We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm passing some byte from Processing to an Arduino Due, then having the Due echo the information back to the Arduino.
My Processing code looks like:
void draw()
{
if(port.available() > 0)
{
int incoming_value = (int) port.read();
println(incoming_value);
}
}
// When a button is clicked, send some values down to the Arduino
public void buttonA(int theValue)
{
byte command = 22;
port.write(command);
byte value = 1;
port.write(value);
}
And my arduino code looks like:
void loop()
{
if (Serial.available() > 0)
{
// read the incoming byte:
command_byte = Serial.read();
if(command_byte == 22)
{
Serial.write((byte)Serial.read());
}
}
}
In the Arduino's Setup function, Serial.begin(9600) is called and the serial port is flushed. Everything looks like it should work, however, the value I'm getting back from the Arduino is always 255. No matter what value I send from Processing, the response is always 255. Any suggestions?
Cheers, Bret
Answers
Ah, nevermind. I figured it out. In short, the line
was true before there were two bytes in the serial buffer. I had to change it to:
I found the answer here: http://stackoverflow.com/questions/17547246/arduino-code-weird-return-with-serial-read
Cheers, Bret