Null Pointer Exception with Arduino Communication

I have to stop soon (22:15 UK) but have some pieces working. In your Processing code, in each section you need to set the boolean false to prevent it sending multiple times:


  if(clawgrab){
    print("Claw Closing ");
    port.write("C90");
    clawgrab = false;
  }

In the Arduino before setup

#define dW digitalWrite
#define buffsize 50
char buffer[buffsize];

in loop

    int res;
    if (Serial.available() > 0)
    {
      res = Serial.readBytesUntil('x', buffer, buffsize);
      Serial.print(res); Serial.print(" ");
      if (res > 0) {dW(led2, 1);}
      else         {dW(led2, 0);}
    }

This is correctly flashing the led each time it receives some chars terminating with x. I’ve included the .available() despite what I said before. Your application only sends occasionally, but I’m more used to things being sent regularly. We don’t want the readBytesUntil to timeout, and we don’t want to use a big timeout as that would prevent the Ard code doing other things.

I’m using Serial.print to see what the Ard is doing, and testing using Putty, just typing in chars. The Ard serial monitor is similar but I prefer the interaction with Putty. (Don’t leave Putty running and try to reload.)