Run Processing programs on your touchscreen RPi2

Lead Image © Studiostocks,

In Touch

We show how to get started with the Processing language on a Raspberry Pi 2 with a touchscreen.

I do a lot of hardware prototyping projects on Arduinos, the Raspberry Pi, and Linux notebooks, so you can imagine my excitement when a 3.5-inch PiTFT touchscreen [1] arrived in the mail from Adafruit. How great would it be, I thought, to use a compact portable touchscreen for interaction with the Raspberry Pi 2 (RPi2) instead of being hooked up to a big-screen monitor and its bulky HDMI cable? I'm not talking about just a framebuffer display, but rather a regular X Window desktop complete with a touchscreen and small, special-purpose applications.

The Processing language [2] works well on my Linux notebook, so I thought that sticking with a similar framework made sense for the Raspberry Pi, as well. Processing offers a rich set of easy-to-use functions and tons of additional libraries for generating graphical user interfaces. The language was created to make it less daunting for artists, creative types, and non-programmers to build their own software.

If you've used the Arduino IDE (Figure 1), you'll be right at home with Processing. The look and feel are identical. Not only that, the IDE works the same on the RPi2, a Linux notebook, and even Windows and Macs. The syntax is the same, too. Some of the functions, of course, aren't always applicable across platforms. For example, turning an output pin "on" makes sense for the RPi2, but not so much for a Linux notebook.

Figure 1: The Arduino IDE.

In this article, I'll go through the steps to build a simple Processing interface on the RPi2 that uses the PiTFT touchscreen screen.

Install PiTFT Version of Raspbian on RPi2

Adafruit has done a great job packaging their 3.5-inch PiTFT display with a custom Raspbian Linux image [3], so take advantage of their hard work, download the tweaked image, and burn it to the RPi2's microSD card. I used the "Jessie" version.

Once the PiTFT is operational, use a stylus for accurate touches to the screen. It's also convenient to use a wireless keyboard/mousepad. Mine's a Logitech K400r [4] with a tiny receiver that plugs in to a USB port (Figure 2).

Figure 2: Raspberry Pi 2 with the Logitech keyboard.

Install Processing 3

I like to develop the majority of a Processing app on the notebook and then transfer it over to the RPi2 for final tweaking, even with the PiTFT screen. The good thing is that Processing version 3 is pretty well synced up for the Pi and regular notebook Linux. Bear in mind, however, that there are a few slight differences that you'll have to work around. For example, the library isn't included in the Linux notebook version as it is for the Pi. A notebook doesn't give you access to the general-purpose I/O (GPIO) pins. The Raspberry Pi has more than a dozen digital GPIO pins you can use.

Regardless of the platform, installing Processing is the same for a Linux notebook or the RPi2. Go to the website and download the one that is appropriate for your platform [5]. I used the Linux 64-bit version for my ancient ASUS duo-core, Intel-based notebook. The RPi2 required the Linux ARMv6hf ZIP file.

Once the file is downloaded, unzip the file, and it will create a directory named something like processing3.0.1. Navigate to the directory and start Processing with the following line:

rob%  ./processing

The Processing IDE will start, and you can check out the examples by selecting File | Examples.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content