I am working on sending serial values from processing to arduino.
I have an arduino sketch that works with serial values sent from the arduino software's serial console. all it does is read the values and echo them back.
However when i use processing to send the same values issues start to happen.
in the arduino console when i send the string
'DRGBRGBRGBRGBRGBD'
it echos
"RGBRGBRGBRGBRGB"
however when i have processing send the same string it echos
"RGBRGBRGBRGBRGB
RGBRGBRGBRGRBRRBRG
RBRGBRGB
RGGRGRGRG
RG
RGBRGBRGBRGBRG"
the program attempted to send the string approximately 10 times during that echo
Im new to serial communication so hopefully someone can help me figure this out.
ARDUINO CODE
byte test[15];
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(Serial.available() >= 17)
{
if(Serial.read() != 'D')
{
delay(10);
Serial.flush();
}
for(int i=0; i<15;i++)
{
test[i] = Serial.read();
}
if(Serial.read() == 'D')
{
for(int p=0 ; p<15 ; p++)
{
Serial.print(test[p]);
}
Serial.println();
Serial.println();
}
}
PROCESSING CODE
import processing.serial.*;
Serial port;
long last =0;
void setup()
{
size(200,200);
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
if( millis() - last > 2000)
{
last = millis();
port.write('D');
port.write('R');
port.write('G');
port.write('B');
port.write('R');
port.write('G');
port.write('B');
port.write('R');
port.write('G');
port.write('B');
port.write('R');
port.write('G');
port.write('B');
port.write('R');
port.write('G');
port.write('B');
port.write('D');
}
}