Thank you for reading this. I’ve spent most of the day trying to discover why the serial write function will not send the correct data the first time. If I send the same block of data twice then the correct data is received by the Arduino. If I send the same block once more, without resetting the Arduino, then all is well. The serial write seem to only fail if I write the block once after an Arduino reset.
If I send the same data from the Arduino serial monitor then there isn’t a problem. So, the fault is something that I’m missing from my Processing code, but What?
After a bit more experimentation I’ve discovered that if I send two line feeds before the data block then all is well. Does this mean that I need some sort of marker at the beginning of the block or do I need the reset something in the serial device before sending the data?
import processing.serial.*;
Serial myPort;
boolean call_once = true;
void setup()
{
myPort = new Serial(this, “/dev/ttyUSB0”, 9600);
delay(1000); // wait for Arduino to reset
}
-b- already send lots of info back, show it at processing console
-c- handshake: arduino sends a line “READY”
and processing only starts sending after got that.
( so it also could help as a kind of see “Arduino REBOOT” logic )
It finally dawned on me that Processing is sending data to the Arduino before it’s ready. I simply increased the delay from 1 second to 1.5 seconds after myPort is created. I suppose a more technically correct method would be to have the Arduino signal when it’s ready. I also discovered that the inter-character delay is not necessary.