Hello, I need help connecting Processing to my Arduino.
I am new to Processing and Arduino.
I am running on a Mac and using an Arduino Uno.
I don’t know what I am doing…
I have used the following code and methods that I found online:
I am trying to read the Arduino serial out with Processing.
If I get this to work I will then work on writing to the Arduino.
Arduino code:
<void setup()
{
//initialize serial communications at a 9600 baud rate
Serial.begin(9600);
}
void loop()
{
//send ‘Hello, world!’ over the serial port
Serial.println(“Hello, world!”);
//wait 100 milliseconds so we don’t drive ourselves crazy
delay(100);
}>
Processing code:
<import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.readStringUntil(’\n’); // read it and store it in val
}
println(val); //print it out in the console
}>
When I run the Arduino code I get a series of "Hello Worlrt"s on it’s I/O
window, as expected.
For the Processing Code I was not sure which serial port to specify.
I tried 3 different methods to find out.
Method 1:
I looked at the Arduino IDE, Tools, Port dropdown.
It listed:
/dev/cu.BLTH
/dev/cu.Bluetooth-Incoming_Port
/dev/cu.UART
/dev/cu.usbmodem1412401
The forth one down is selected.
The forth one down looks correct, so it’s port3 ?
Method 2:
I started a new, separate Processing sketch with the following code:
Processing code:
< import processing.serial.*;
void setup() {
println(Serial.list());
}>
Running this resulted in a list of the same ports, in the same order, as
the Arduino IDE Tools Port list.
… although it printed the list out twice for some reason.
Method 3:
I tried all the port numbers in order.
The results are as follows:
Ports 1, 2, 5, 6:
Produced a vertical string of "null"s in the Processing console screen.
Ports 0, 3, 4, 7 produced the following error:
RuntimeException: Error opening serial port /dev/cu,BLTH: Port busy
Each error had the different name for each of the different devices.
I also got a small empty Processing I/O widow when I ran the
Processing sketch.
The end result is that nothing seems to be connecting.
Well, this was a lot of stuff.
I am obviously interested in getting this working.
I am trying to make a sort of Gui interface for a Arduino bench setup.
Does anyone have any ideas?
Thanks much for any help.