Strange issue with Processing to Arduino serial communication

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

Sign In or Register to comment.