I am trying to establish a connection between the BeagleBone version with Ubuntu 10.04 and Arduino. So far, I can send the string in order, but I am having trouble recognizing a newline character.
From the BB side, in Python3 and using PySerial, I (edited only for the corresponding bits):
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.write(chr(13).encode('ascii'))
delay(3000)
mesg = 'Beagle\n'
ser.write(mesg.encode('ascii'))
On the Arduino side, I have:
boolean newMsg = false;
String incomingMsg = "";
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(newMsg) {
lcd.print(incomingMsg);
newMsg = false;
}
}
void serialEvent()
{
incomingMsg = "";
while (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == '\n') {
newMsg = true;
} else {
incomingMsg = incomingMsg + inByte;
}
}
}
The problem is that newMsg never gets true because it is if (inByte == '\n')never checked as true. I tried using '\ r' on both sides and even the characteristic type ('#'), but this test never works. The string "Beagle" does everything well, so it incomingMsgis created normally.
, Arduino Processing (Arduino , Bluetooth). , . ?
. , , , , .
if (inByte == '\n') . - true var newMsg . serialEvent(), (). var (, , Arduino). () :
if (messageReceived != "")
. , .