I’m trying to connect an Arduino Nano Every and Processing via serial. I’m getting no errors on either side, and the arduino serial functionality works otherwise on the arduino IDE.
I’m connecting on the right port, and the port is busy while the processing code is running (as you would expect), however, the variable inside the arduino is not updating. In fact, the whole if serial.available statement is not executing.
Arduino:
int var;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
var = Serial.read();
}
Serial.println(var);
delay(100);
}
Processing:
import processing.serial.*;
// The serial port
Serial myPort;
void setup() {
// List all the available serial ports:
printArray(Serial.list());
// open port
myPort = new Serial(this, Serial.list()[2], 9600);
}
void draw() {
try {
myPort.write(1);
}
catch(Exception e) {
// Print detailed error information to the console.
System.err.println(e);
e.printStackTrace();
}
delay(50);
}
Modified Processing code to receive the data to demonstrate that it is working:
import processing.serial.*;
// The serial port
Serial myPort;
byte b;
void setup()
{
// List all the available serial ports:
printArray(Serial.list());
// open port
myPort = new Serial(this, Serial.list()[0], 9600);
delay(1000);
}
void draw()
{
try
{
myPort.write(b++); // Counts from 0 to 255 and repeats since it is a byte
}
catch(Exception e)
{
// Print detailed error information to the console.
System.err.println(e);
e.printStackTrace();
}
//delay(50);
if(myPort.available() > 0)
{
int incoming = myPort.read();
println(incoming);
}
}
I also added a delay(1000) in Processing in the setup() to allow the Arduino to reboot before sending data and flooding the buffers.
Would you be able to suggest a good resource to get to grips with the basics of serial communication? I have basic/intermediate C++ and can only work with the arduino IDE and starting out with processing.
This low level programming may not be useful to a beginner but has given me a much deeper insight into what is going on at a hardware level and I can better understand serial communications.