Hey! This article is really old! The code might still work, but I’ve updated the installation instructions for Processing 2.1 and
Sun Oracle Java here: Processing 2.1 + Oracle Java + Raspberry Pi + Serial + Arduino = â˜º.
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.
Running Processing on Raspberry Pi
Processing is both written in and generates Java, so there’s some hope that it can run on most platforms. Up-to-date installation instructions.
These instructions are modified fromÂ Processing sur Raspberry Pi, for which thanks are given to the original author:
Install the JDK and Java serial library:
sudo apt-get install librxtx-java openjdk-6-jdk
Download the Linux version of Processing, and unpack it to somewhere permanent in your home directory
Delete the java folder in the Processing directory; for me, that was
Replace that java folder with a link to your system’s installation:
ln -s /usr/lib/jvm/java-6-openjdk-armhf java
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
(If you don’t do this, you’ll get a warning: “WARNING:Â RXTX Version mismatch”, and any serial comms will fail.)
- Download and install the controlP5 library for Processing
- Download and install the Arduino library for Processing
- 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;
- an LM35 with the following connections: +Vs â†’ +5V, Vout â†’ analogue pin 0, and GND â†’ GND.
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 ‘ /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!