Processing serial output vs Arduino serial input
in
Integration and Hardware
•
2 years ago
Hi folks!
I have to send via serial port an integer to an Arduino board using a baud rate of 9600.
The problem is that if I send this integer simply as a "int" using this code:
int message = 4000;
Serial.write(a);
delay(5)
arduino will receive one number that is not the one I sent!!!
If I just split the integer into 4 byte and send them one after the other, using this code:
int message =4000;
byte sms = byte((message >> 24) & 0x00FF);
myPort.write(sms);
delay(5);
sms = byte((message >> 16) & 0x0FF);
myPort.write(sms);
delay(5);
sms = byte((message >> 8) & 0x00FF);
myPort.write(sms);
delay(5);
sms = byte(message & 0x00FF);
myPort.write(sms);
delay(5);
at the beginning the numbers arrive correctly, but after a while the input arrives messed up.
Anyone knows if there are problem about sending integers in processing?
Thanks you for your time.
Richard
1