Null Pointer Exception with Arduino Communication

@PapiAli Try this program in your Ard.

#define buffsize 50
char buffer[buffsize];

void setup(){
  Serial.begin(9600);
  Serial.setTimeout(2000);}
  
void loop(){
  int res;
  int val;
  if (Serial.available() > 0){
    res = Serial.readBytesUntil('Z', buffer, buffsize);
    Serial.print(res); Serial.print(" ");
    buffer[res] = 0;  // terminate the 'string' after the number.
    Serial.print(buffer); Serial.print(" ");
    sscanf(&buffer[1], "%d", &val);
    Serial.print(val); Serial.print(" ");}}

Leave processing aside for the moment. Open Ard’s serial monitor, and enter C180Z (return). It should print "4 C180 180 ". 4 is the no. of chars, C180 is the chars received, 180 is the value converted to integer. It works with different length numbers.

(I don’t normally put the { on the same line, prefer the old way on next line. But the new way is shorter for copy+paste. Then I thought, why not put the trailing } on the line above? Now it looks like Python :slight_smile: )