2

I just wrote some code that just sends a string from Arduino to Processing.

Processing prints the string and displays the number of characters in the buffer... After uploading the sketch to the Arduino and starting Processing for the first time, the serial buffer is initially filled with a few things (it turns out that these are nulls; 0 in ASCII). Why is this happening?

And this mostly happens after uploading and starting Processing for the first time. When I start Processing for the second time, the buffer is initially free as it should be. I am using a genuine Arduino Uno. I also tested on another Arduino and another laptop, but there is still the same problem. So it should not be a hardware problem.

Arduino Code

void setup() {
  Serial.begin(9600);
  //delay(1000)
  Serial.println("the quick brown fox jumps over the lazy dog");
  delay(1000);
}

void loop() {
}

Processing Code

import processing.serial.*;
Serial myPort;

void setup() {
  myPort = new Serial(this, "COM3", 9600);
}

void draw() {
  if (myPort.available()>0) {
    println("Buffer:"+myPort.available());
    String string = myPort.readStringUntil('\n');
    if (string!=null) {
      println("String:"+string);
    }
  }
}

In the image is other code just to show that the buffer contains nulls.

Enter image description here

33
  • 2
    Is is an Arduino or an ESP? (Because the latter prints some data on boot, using a different baud rate, IIRC: 76800. This MAY result in nulls if you try to read them using a different baud rate than they're sent in, but usually results in garbage.)
    – orithena
    Sep 8, 2022 at 11:00
  • 2
    The Arduino that I got is genuine not a clone.
    – Robot12
    Sep 9, 2022 at 16:42
  • 1
    Provide versions numbers of everything involved like I did in explaining my attempt to replicate your problem.
    – timemage
    Sep 13, 2022 at 17:03
  • 1
    versions are the same as yours. Arduino 1.8.19, Processing 4.0.1
    – Robot12
    Sep 13, 2022 at 17:22
  • 1
    What happens if you connect a 10 kOhm resistor from D1 to 5V?
    – timemage
    Sep 13, 2022 at 17:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.