Hello,
Consider sending comma delimited data terminated with a ‘\n’:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int data;
void setup()
{
size(200, 200);
// List all the available serial ports
printArray(Serial.list());
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
delay(1000);
}
void draw()
{
if(frameCount%10 == 0) //Sends every 1/6 second
{
String sData = nf(byte(data), 3); // Only the LSB (least significant byte)
//myPort.write(sData); //This will send 0 to 255 and repeat; it is only sending the LSB (least significatn byte of the int)
//myPort.write(',');
String R = nf(int(random(256)), 3);
//myPort.write(R); //R
//myPort.write(',');
String G = nf(int(random(256)), 3);
//myPort.write(G); //R
//myPort.write(',');
String B = nf(int(random(256)), 3);
//myPort.write(B); //R
//myPort.write('\n');
//This replaces commented data above:
myPort.write(sData + ',' + R + ',' + G + ',' + B + '\n');
data++;
}
}
This is an example of the data strings it was sending:
000,183,109,014
001,170,200,221
002,243,029,109
003,200,061,115
004,180,070,156
005,080,132,113
…
The above is one way to do it; I found it easy to get substrings if data had leading 0’s and went with that.
On the Arduino side you will need to:
https://www.arduino.cc/reference/en/language/functions/communication/serial/readstringuntil/
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/trim/
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/substring/
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/
:)