Services

Components, kits and expansion

The Raspberry Pi is supplied as a circuit board only – chips can be damaged by static electricity and housing it in an enclosure is a sensible precaution; this will also allow it to be placed on metallic surfaces without fear of short-circuiting the board. There are many cases to choose from, and it's largely a matter of taste, but ease of access to ports is one important consideration.

Two Raspberry Pi cases – one with space for accommodating a breadboard
A breadboard allows circuits to be prototyped without the need for soldering and, when combined with a breakout cable, provides a low cost platform for hardware experimentation. Breadboards can be purchased in varying sizes and breakout kits such as Adafruit's Pi Cobbler provide everything that is required for connecting these up to the Pi. Components are then simply inserted into the solderless contacts of the breadboard in order to construct circuits and connect these up to GPIO.

The Adafruit Pi Cobbler Breakout Kit
Source: Adafruit Industries CC BY-NC-SA 2.0
Shorting or overdriving GPIO could be catastrophic and, as previously mentioned, it's generally advisable to protect this when experimenting. More comprehensive kits such as the Starter Kit-B from SK Pang Electronics include I/O expander chips along with other staples such as buttons, LEDs and resistors. The I/O expander interfaces with the Raspberry Pi via the I2C bus and uses up just 2 pins of GPIO. Typically it provides 8 or 16 channels of I/O where mistakes should limit damage to the expander, which itself would be much cheaper to replace than the Pi.

The PiBorg Raspberry Pi expansion board for robotics control
Source: Freeburn Robotics Ltd
Expansion boards provide a head start for extending the Raspberry Pi and combine additional I/O with commonly used components such as buttons and LEDs. The Gertboard from the designer of the Raspberry Pi alpha hardware, Gert van Loo, was perhaps the most eagerly anticipated of these and includes an Arduino microcontroller and analogue-to-digital and digital-to-analogue converters. Most expansion boards are designed to support a broad range of uses, but one exception is the PiBorg which is intended for use in robotics and can directly control motors and monitor them to work out the torque and their speed.

Writing software

Software to access GPIO can be written in any one of a number of languages and even shell scripts can be used to set and sample the state of pins.

echo "4" > /sys/class/gpio/export

echo "out" > /sys/class/gpio/gpio4/direction

echo "1" > /sys/class/gpio/gpio4/value

Shell commands to enable GPIO in sysfs, configure a pin as an output and set it to logic high

public static void main(String args) {

GpioGateway gpio = new GpioGatewayImpl();

//set up the GPIO channels - one input and one output gpio.setup(Boardpin.PIN11_GPIO17, Direction.IN); gpio.setup(Boardpin.PIN12_GPIO18, Direction.OUT);

The C language is a favourite of embedded developers and the Raspberry Pi community wiki provides two code examples: one that directly manipulates the GPIO register and another that makes use of a C library for the BCM2835 system-on-a-chip (SoC) used by the Raspberry Pi.

The more adventurous could even try their hand at ARM assembly language programming – the University of Cambridge Computer Laboratory has published an entire Raspberry-Pi-based operating systems development course under a Creative Commons licence. This takes the student all the way from writing code to control an LED, to driving a display and using a USB library to take keyboard input.