Arduino filling the serial Buffer with nulls

Hello @maro,

Arduino Code
void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("0123456789ABCDEF");
  }

void loop() 
  {
  }
Processing Code
// Example by Tom Igoe

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[4], 9600);
  myPort.clear();
  // Throw out the first reading, in case we started reading 
  // in the middle of a string from the sender.
  //myString = myPort.readStringUntil(lf); // glv - I commented this
  myString = null;
}

void draw() {
  while (myPort.available() > 0) {
    myString = myPort.readStringUntil(lf);
    if (myString != null) {
      //println(myString);  // glv - I commented this
      
      //******************************************
      // glv - I added this:
      int sl = myString.length();
      println(sl); 
      for(int i = 0; i < sl; i++)
        print(hex(myString.charAt(i), 2));
      println(); 
    //******************************************  
    
    }
  }
}

Console output directly after:

  • Uploading Arduino code to Arduino Uno R3
  • Running Processing 4.0.1 sketch the first time

The zeroes are not there after an upload followed by a USB disconnect\connect (power off\on) of the board and then running the Processing sketch.

The zeroes are not there on subsequent runs of of the Processing sketch which resets the Arduino.

Related:

Related but not exactly ? the same issue…
Consider opening an issue that is specific to your observations.

:)

1 Like