Repository navigation
Raspberry Pi
The original Raspberry Pi contained an ARMv6 CPU, 256 or 512 MB RAM, and Broadcom VideoCore IV graphics. The Raspberry Pi 2 contains a quad-core ARMv7 CPU, 1 GB of RAM, and the same graphics as the original Pi.
Both primarily run a modified version of the Debian Linux distribution named Raspbian that was made to run on the ARMv6 CPU (and higher).
On the Pi 2 it is also possible to run other unmodified Linux distributions, such as Debian or Fedora, since those settled on the ARMv7 architecture as their "baseline" for modern ARM support. Yet on those distributions you might not have the necessary kernel modules and graphics library to make full use of the Pi's peripherals. This page thus specifically talks about running Processing on Raspbian, on either the Pi or the Pi 2! (see also: General notes about running Processing on ARM)
You can download a full Raspbian image with Processing pre-installed here. This image is based on Processing 3.1 and Raspbian release March 2016, and works on all versions of the Pi.
Important: Since the image contained in the ZIP file is larger than 4 GB it is necessary to use extraction utilities that can handle large files, such as The Unarchiver on OS X. (Try this if extracting yields a file with CPGZ extension.)
See the Writing an image to the SD card section on this page for how to transfer the contents of the extracted IMG file onto a microSD card. Those are different depending on the operating system you are using.
Alternatively, if you already have an existing installation of Raspbian you want to keep, you can install Processing by running the following in a terminal:
curl https://processing.org/download/install-arm.sh | sudo sh
Important: Due to an issue with recent Raspbian releases, it is necessary to uninstall the packages libgles1-mesa and libgles2-mesa before using Processing, to prevent startup errors related to the P2D and P3D renderers. The Raspbian image linked above already has them pre-removed - but on all other Raspbian installations you might need to run the following command once:
sudo aptitude remove libgles1-mesa libgles2-mesa
(see issue for details)
The Pi's graphics core exposes OpenGL ES 2.0, which is supported by Processing P2D and P3D renderer, thanks to specific enablement in the underlying library, JOGL. The graphics driver are built around a closed-source driver (found in /opt/vc), which limits our ability to troubleshoot bugs for the moment.
Due to a limitation of this driver, P3D is currently limited to using 2 lights.
Certain sketches might run out of video memory and throw an exception mentioning GL_OUT_OF_MEMORY. You might be able to work around this by changing the memory split - the amount of memory allocated for the GPU from all system memory. To do so, open the Raspberry Pi Configuration (under Menu, Preferences), navigate to the Performance tab, change the amount of "GPU memory" and then restart your Pi.
Starting with the February 2016 version, Raspbian also includes an experimental, open source OpenGL driver for the Pi 2. This driver is still in development, but might be worth trying out when experiencing issues with the default one. To enable or disable the driver, run sudo raspi-config and select the GL Driver option under Advanced Options. For the time being, it is necessary to also temporarily move the files of the old driver, since JOGL is using their presence to select a specific behavior. Run sudo mv /opt/vc /opt/vc.bak to do so, and later sudo mv /opt/vc.bak /opt/vc to revert this action. Note that the new driver currently lacks many features of the existing one, such as the ability to drive screens attached to the DSI interface, support for camera modules or hardware-enabled video decoding.
Processing has a new Hardware I/O library that was extensively tested with the Pi.
There is no special configuration necessary to use the digital pins with digitalRead(), digitalWrite() etc.
Keep in mind that the Pi uses 3.3V level, rather then the 5V of the Arduino Uno. The pins are said not to be 5V tolerant, so make sure to keep your voltages to 3.3V.
Each pin is rated up to 16 mA per pin, with 50 mA total, across all pins. (The Arduino UNO is 20 mA @ 5V per pin.) Make sure not to draw more.
The Hardware I/O library's GPIO class uses GPIO numbers with its methods. Those are not the same as the physical pin numbers of the pin header. (see pinout) You can use the special RPI class to use physical pin number in your sketch: e.g. pin 7 on the header can be addressed by RPI.PIN7 instead of (GPIO) 4.
The Pi has one (publicly exposed) hardware I2C interface. To use it in Processing (with the I2C class in processing.io), open the Raspberry Pi Configuration (under Menu, Preferences), navigate to the Interfaces tab, enable I2C and then restart your Pi.
After restarting, I2C.list() should return one interface: e.g. i2c-1 on the Pi 2. The interface is located on pins 3 (SDA) and 5 (SCL) on the Pi's header. (see pinout) Ground is conveniently located right next to it, on pin 6. Use it together with the 3.3V supply on pin 1, since that is the level that the Pi expects.
The Pi has two on-board LEDs, led0 and led1, which can be controlled through the LED class in Processing.
Since the regular user (named pi) is by default not permitted to write to the LED device, you must enable this once by running
sudo sed -i 's|exit 0|chmod -R a+rw /sys/class/leds/*\nexit 0|' /etc/rc.local
After a restart, the devices should be read- and writable by any user. (This can be confirmed by running ls -l /sys/class/leds/led0/brightness. The resulting line should start with -rw-rw-rw-.)
On the Pi, led0 is the green (I/O activity) light, while led1 is the red (power) light. They only can be turned on and off, so brightness() values besides 0.0 and 1.0 have no effect.
The Pi two hardware SPI interfaces, but which share all but the SS (Slave Select) pins. To use it in Processing (with the SPI class in processing.io), open the Raspberry Pi Configuration (under Menu, Preferences), navigate to the Interfaces tab, enable SPI and then restart your Pi.
After restarting, SPI.list() should return two interfaces spidev0.0 and spidev0.1.
The interfaces' pins are located on the Pi's header on pins 19 (MOSI), 21 (MISO), 23 (SCLK), 24 (SS, aka CE0) and 26 (SS, aka CE1). (see pinout) When using spidev0.0, pin 24 (CE0) is being pulled low during a transaction, while pin26 (CE1) remains unchanged. When using spidev0.1, pin 26 (CE1) is being pulled low, while pin24 (CE0) remains unchanged. (This is to be able to address two devices on the same data & clock lines.)
The Pi has only one PWM channel exposed on the pin header, which is furthermore disabled by default, as it is shared with the on-board audio output functionality. To enable it, add the line dtoverlay=pwm-overlay to the bottom of the /boot/config.txt file and restart.
It is currently necessary to use the audio output, however brief, before the PWM channel can be used, since this sets up the required internal clocks. Run e.g. omxplayer example.mp3 from the terminal. (But make sure no sound is being played back while you actually use the PWM channel. Again, those functions share the same underlying hardware.)
After this, PWM.list() should return pwmchip0/pwm0 and pwmchip0/pwm1. pwmchip0/pwm0 is located on the Pi's header on pin 12, as well as on the right channel of the audio jack. (see pinout) pwmchip0/pwm1 seems to be only accessible on the left channel of the audio jack.
Unfortunately, the Linux kernel doesn't send out notifications to user-space after a new channel has been requested, which would allow the udev program to change its permissions. Because of this, it is currently necessary to run Processing as the root user to use PWM output.
The Pi has one serial port, exposed on pins 8 (TXD) and 10 (RXD). (see pinout) Like all other pins, these operate on 3.3V TTL levels, instead of the RS-232 voltage levels normally expected from a computer's "serial port". By default, the serial port is used to be able to command the Pi remotely, by offering a "shell", through which one can type in commands and receive screen output as on a local terminal.
To use it instead with Processing's Serial library, open the Raspberry Pi Configuration (under Menu, Preferences), navigate to the Interfaces tab, disable Serial and then restart your Pi. The serial port will be called /dev/ttyACM0.
Using USB-connected Arduino boards, etc., is possible without any configuration. They will show up as /dev/ttyUSB0, etc.
The simpletouch library allows you to track up to 10 simultaneous fingers on top of the official Raspberry Pi display, or any other multi-touch-enabled display or touchpad (provided it comes with the necessary kernel drivers).
The two example sketches the library comes with explain how to use it. Please file issues here.
The current version of Processing's video library makes use of the 0.10 version of GStreamer, which is only partially supported by the latest version of Raspbian.
There is also an alternative library for use with the Raspberry Pi that enables hardware-accelerated decoding and playback of H.264 video files: GL Video. (This is currently work in progress.)
If you're receiving the error IllegalArgumentException: No such Gstreamer factory: v4l2src, install the necessary package by executing sudo aptitude install gstreamer0.10-plugins-good in a terminal.
To use the Raspberry Pi camera, add the following line to your /etc/modules file and reboot:
bcm2835_v4l2
After the reboot your camera should show up as /dev/video0. However, it seems that the camera isn't working with the Video library at this time (gst_value_list_get_size: assertion 'GST_VALUE_HOLDS_LIST (value)), this is being investigated.