Arduino filling serial buffer with nulls

Viewed 47

I just wrote some code that just sends a String from Arduino to Processing. Processing prints the string in ASCII. After uploading the sketch to the Arduino and starting Processing for the first time, The serial Buffer is initially filled with nulls. 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 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) {
    int c =myPort.read();
    print(c,",");
  }
}

Output on Processing

0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,116 ,104 ,101 ,32 ,113 ,117 ,105 ,99 ,107 ,32 ,98 ,114 ,111 ,119 ,110 ,32 ,102 ,111 ,120 ,32 ,106 ,117 ,109 ,112 ,115 ,32 ,111 ,118 ,101 ,114 ,32 ,116 ,104 ,101 ,32 ,108 ,97 ,122 ,121 ,32 ,100 ,111 ,103 
0 Answers
Related