This might not look like much, but it was a lot of work to get here. It’s the display from a small Processing sketch, running on a Raspberry Pi, talking to an Arduino controlling the brightness of an LED with the slider, and reading from an LM35 temperature sensor.

I wanted to see if I could get graphical control of an Arduino on the Raspberry Pi. I wrote about the simplest sketch in Processing that combined output (to control a small green LED through a resistor) and input (from an LM35, that simplest of sensors). This is how it looks running on a slightly faster machine than the Raspberry Pi:

LED at half brightness, LM35 showing 25°C

LED off, sensor at 26°C

LED full on, LM35 warmed up

I had the same results on the Raspberry Pi; just much, much slower. The sketch is below the fold.

In the Processing folder, remove or rename modes/java/libraries/serial/library/linux32/librxtxSerial.so; it’s an x86 binary, and will fail

In the Processing folder, also remove modes/java/libraries/serial/library/RXTXcomm.jar, and replace it with a copy of /usr/share/java/RXTXcomm.jar (If you don’t do this, you’ll get a warning: “WARNING: RXTX Version mismatch”, and any serial comms will fail.)

Program your Arduino with Firmata; the version that comes with the Arduino software is fine a bit old.

Connect your Arduino to the Raspberry Pi with a USB cable; it may require external power.

Now fire up Processing. It will used to take a while to start up, and will throw the following warning:

Despite this, it should eventually should start up fine:

Now, this is slow. It takes tens of seconds to start up. It might not be the most practical development tool, but Processing sketches are very portable, so you can develop on one machine, and then run on the Raspberry Pi.

The code at the end of this article expects:

an Arduino running the Firmata DAQ sketch attached to a USB port;

a small LED connected from digital pin 3, through a 1kΩ resistor to ground;

If you run this, after about half a minute, the blank sketch window appears, and about half a minute later, the slider and temperature reading appears. If it doesn’t, there’s a good chance that the serial libraries are wrong. Try this sketch:

This should return a number and a serial port where the Arduino was found; something like ‘[0] /dev/ttyACM0’.

What I really want to do now is get this same hardware running with Python and tkinter. It’s not that Python’s my favourite language; it’s just that the Raspberry Pi Foundation chose Python as the official language for the board. I’d rather work to further the aims of this educational foundation rather than work against it. Processing’s pretty much unworkably slow on the Raspberry Pi — but it does work!

38 thoughts on “Controlling an Arduino from Raspberry Pi using Processing”

any updates on the oracle release of java used with processing? I installed it, and deleted java folder and created a system link to the new java directory but processing only shows a shell script. very new to linux so help greatly appreciated.

I just wanted to give an update that I finally succeeded in getting it to work.
In the end I ended up installed openjdk-7-jdk instead of openjdk-6-jdk and started revisiting every single step.
I actually feel a bit ashamed that I didn’t notice it any earlier, but my error had to do with replacing the RXTXcomm.jar .
As written in the original explanation above, I just quickly copied the RXTXcomm.jar to modes/java/libraries/serial/library/RXTXcomm.jar, without even noticing that it wasn’t a file but actually a shortcut to the real file, which in my case is named : RXTXcomm-2.2pre2.jar . All I had to do was copy both the shortcut and the file, which solved that part.
I ended up downloading a more recent arduino-library as well at https://github.com/pardo-bsso/processing-arduino , because the one I got from the link above was giving access/permissions errors.

Hope this will help some of you, to get it up and running as well. Unfortunately it’s terribly slow, but as long as you don’t need to much interaction (e.g. like sliding bars or so), it’s feasible.
Enjoy

I’m having the same problems as David above, I’ve managed to get Processing up and running but with a similar error: “NoClassDefFoundError: gnu/io/SerialPortEvent Listener” I relatively new to RPi and at the moment I would like it so that when I click my onboard LED on my Uno turns on and off. I have this working with the same code on my PC, but I require it working on the RPi for a wireless robot project. I’m not using Firmata, as I just want the Pi to send a char to the Arduino.

Hello. Hello. Thanks for the tutorial helped me. a question: have you tried the version with JAVA8 2.0.7.by processing. Java8 will do better than this but I get Java6 problems nada.Alguien library and will not have any ideas?

I had processing working fine, however earlier today I tried to execute the processing shell script, and nothings happening. No errors at all. The CPU monitor shows full for about 5 seconds then falls back down. I’ve tried going through the steps again, but nothing’s happening.

Thank you very much. I was more than 12 hours trying to connect firmata with processing in debian wheezy, read thousand blogs and official forums until I found the solution in your post. Also I tried it on my raspberry pi with raspbian, ssh and vnc, it’s amazing. Thank you very much. greetings from Mexico.

Just thought I leave a note that I got the Java 8 JDK running on the pi along with Processing ver 2.08b. I know nothing about Linux, so I was pretty lost trying to folllowing everyone’s instructions and I thought my notes might help somone.

All can be done, but I need to know how slow is it ? Im making a project that includes playing 6 different sounds according to what it reads from serial , it works like a charm on PC will it work on the pi ?