1

Im trying to send data from an arduino with integrated ble (bluno nano from DFRobot) to a raspberry pi 2 which has an hm10 ble module connected to its serial0 gpio14 and 15 pins. I link the devices by sending AT+CONNmac through a python script.

On the pi with hm10 module Im using this python to read it:

#! /usr/bin/env python
import serial
from time import sleep
ser = serial.Serial(port='/dev/serial0',parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,timeout=1)
while 1:
    try:
            sleep(2)
            ser.write("S")
            myData = ser.readline()
            print myData
    except KeyboardInterrupt:
            exit()

So far what works is sending data from the bluno nano to the pi and I can see the values coming into the pi terminal from the bluno nano after linking both devices via bluetooth.

float flow = 111.22;
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      Serial.print(flow);
      Serial.print("\n");
    }

What doesnt work is when I try to test what comes into the bluno from the raspberry pi:

float flow = 111.22;
void setup() {
  Serial.begin(9600);
}
void loop() {
  if (Serial.available()>0) {
    if (Serial.read() == 'S') {
       Serial.print(flow);
       Serial.print("\n");
    }
  }
}

and when I simply use a script to send data from the pi to the bluno and have the bluno write it back to the pi, I get a bunch of ????????? on the pi terminal:

void setup() {
  Serial.begin(9600);  //initial the Serial
}

void loop() {
  if (Serial.available())  {
    Serial.write(Serial.read());//send what has been received
  }
}

I dont understand why I can send data from bluno to pi but not from pi to bluno? Or maybe data is being sent but not recognized properly by the bluno.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.