Null Pointer Exception with Arduino Communication

@PapiAli From your code I see that your command protocol to the Arduino is this: One character, e.g. ‘A’ or ‘C’ followed by a number, which might be 2 or 3 chars. As I see it the problem is your Ard code will start reading what’s come in as soon as e.g. ‘C’ arrives, but the value hasn’t arrived yet. So it will see just ‘C’ and the ‘90’ will be in the input buffer for next time. Think you should use a line-feed character on the end and instead of if (available) use ReadBytesUntil . Then your Ard will have the whole message to work on.

I see you are using a LED to indicate code flow. Just thinking about tools to help you. What type of Arduino is it? Do you have any displays LCD, OLED, or TTL-USB adaptor?

You don’t need all the ‘== true’. If (booleanvar) makes sense.

1 Like