Hello,
I’m trying to send data from Arduino to processing via serial.
I’m getting no errors on either side, and all seems to work.
Just one problem : the data doesn’t arrive in processing…
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
//change the 0 to a 1 or 2 etc. to match your port
String arduinoPort = Serial.list()[0];
myPort = new Serial(this, arduinoPort, 115200);
}
void serialEvent(Serial myPort)
{
val = myPort.readStringUntil('\n'); // read it and store it in val
println(val); //print it out in the console
}
I’ve just found the problem.
I was using an esp8266 which seems not to work with Processing unfortunately .
I’ve changed it with an arduino board and all is working properly.
Hi @Mathis, I have two NodeMCU boards. I think these are simply ESP8266 mounted on a larger PCB. There are a few differences from Arduino, but for me nothing to stop it working with Processing. I’ve found the most significant difference is that the ESP program does not reset when Processing (or anything on the PC) opens the port. So I never see any prints from the setup() function. This code prints everything the ESP sends. I’m not using serialEvent.
import processing.serial.*;
Serial myPort;
int val;
void setup() {
frameRate(40);
String portName = "COM4";
myPort = new Serial(this, portName, 9600);
}
void draw() {
int val;
while (myPort.available() > 0) {
val = myPort.read();
print((char) val);
}
}
I think I’ve seen somewhere that you can’t repeatedly do serial.available() at infinite speed. In any case not good do something like that too fast. Have to give the serial hardware and software time to do its own thing. 40 gives 25 mS/cycle. That’s probably faster than most users/applications care about and gives time for 25 chars to arrive at 9600 baud.
When I added the loop(), it started working, frameRate(40) was better. After I added the .bufferUntil I didn’t go back and try without the first two fixes.