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.
Im currently using this sketch:
float flow = 500.06;
void setup() {
Serial.begin( 9600 );}
void loop() {
if (Serial.available()>0) {
if (Serial.read() == 'R') {
Serial.print(flow)
Serial.write("\n");
}
}
}
and 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)
# Wait to read from Arduino
while 1:
try:
time.sleep(10)
ser.write("R")
myData = ser.readline()
print myData
except KeyboardInterrupt:
exit()
This should make the raspberry send R to the arduino after 10 seconds of running the script. But I get blank lines in the raspberry terminal every ten seconds. I guess that is the print myData line, which is coming in blank.
I just tried connecting the bluno nano and the raspberry pi 2 over usb serial and ran this code and the rpi received 82, which is the ascii equivalent of R. Ive modified the code and added an image to display these findings. I still dont understand why I dont get the response when its over bluetooth serial?