2
votes

I have the following sketch uploaded to my Arduino Uno Rev3:

void setup() {
    Serial.begin(9600);
}

void loop() {
    Serial.println("Hello, World!");
    delay(10);
}

When I run it, Hello, World! is continually printed to the Serial Monitor as expected.

I have the following Processing sketch:

import processing.serial.*;

Serial port;

void setup() {
    port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
}

void draw() {
}

When I run the Processing sketch, the Serial Monitor output gets corrupted. The clean lines of Hello, World! end up looking like this:

Hello, Wold!
Hell, Wrld!
He
Hello, o, Worlorld!
H
Hello,World!
ello World!
Hell, World!
Helo, orld
Hello,Worl!
Hello World!
d!
HellHello, W, World!

I would like to communicate between Processing and Arduino via the Serial, but I can't if the output is corrupt. What could be causing this?

1

1 Answers

1
votes

Are you saying that you have the Arduino Serial Monitor open at the same time as running the Processing sketch? If so, you can't do that: you can't have two apps trying to communicate with the Arduino over the same port at the same time.

Also, increase the delay (try 100) - you are flooding the buffer. You don't show the Processing code that reads from the serial port; where is that?