In association with heise online

21 September 2012, 12:21

Breaking out the Raspberry Pi

By Andrew Back

With flexible I/O options and Linux capability, the Raspberry Pi offers enormous potential for hardware development. Andrew Back takes us through the possibilities with his hardware-hacking getting-started guide for the credit-card-sized Linux computer.

Although the Raspberry Pi can be used as a general purpose computer, media centre or compact web server, the real fun to be had is in extending it with custom hardware. And in fact, small computers of this class – that typically have low power consumption, more modest resources and no moving parts – are known as "embedded systems" and are used to provide the smarts in everything from heating controls and DSL routers, to ECG machines and aircraft instrumentation.

Embedded Linux development systems have been around for many years but none have succeeded in capturing the imagination of so many, or of such a diverse community, as the Raspberry Pi. This is great news for would-be hardware hackers as there exists a rapidly growing selection of starter kits and accessories and help should never be far away.

A portal to experimentation

A laptop or a desktop computer could be equipped with hacker-friendly hardware interfaces, but one of the benefits of the Raspberry Pi, aside from its low cost and small size, is that its P1 connector packs plenty of general purpose input/output (GPIO). This can be used to connect switches, dials, and sensors for things such as temperature and light, to control motors and displays, or to interface with hardware such as a real-time clock (RTC).

Certain hardware can be connected directly to the P1 header, although even where this is possible it's often advisable to use additional circuitry to protect or "buffer" the port when experimenting. Various hardware options and kits are available to make life easier for those that are just starting out, but we'll cover those later and first take a closer look at what P1 provides.

Don't panic, it's only plumbing!


The P1 connector
Source: eLinux.org CC BY-SA 3.0
The great thing about digital electronics is that the actual hardware part of wiring up chips, sensors and displays, etc, is incredibly simple and akin to stringing together UNIX commands with the pipe operator. There are a few basic rules to follow, such as ensuring that devices use the same voltage levels to indicate a one or a zero and, where required, using "pull-up" resistors on input pins, but it doesn't really get complicated until you start working with high-performance digital systems.

There are 17 GPIOs brought out to the P1 header and each can be configured as an input or output, and read or set to be logic high or low using a wide selection of programming languages. Wiring up a switch to one of these to provide a boolean input is trivial, as is driving a small LED when a pin is configured to be an output. Things such as motors, lamps and larger LEDs can also be controlled with the addition of a simple circuit that is able to switch higher currents or voltages.

GPIO is used for far more than just ascertaining the state of basic inputs and switching things on and off, and one or more pins can be driven to implement a particular hardware interface. For example, a Linux kernel module is available that uses GPIO to provide support for the 1-Wire bus that is used by devices such as digital temperature sensors. Where software is used to implement serial communications by directly setting and sampling the state of GPIO this is known as "bit banging".

Since bit banging uses software to drive GPIO it takes up more processor resources than a dedicated hardware interface and may not always be as reliable. Fortunately the Raspberry Pi includes hardware support for the popular I2C and SPI buses, both of which can be configured for access via the P1 header. I2C is used by devices such as RTCs, LCD displays and low-speed analogue-to-digital converters, and SPI by high-speed devices such as SD cards and USB and Ethernet controllers.


Zoom A Raspberry Pi with a USB to serial adapter connected to the UART presented at P1
The default is for two GPIO pins to be configured as a UART (serial port) and if an HDMI monitor is not connected this will be used as the console. However, since the Raspberry Pi uses 3.3V logic, a level converter is required when connecting to a standard RS-232 port, but more typically a PC would be connected via a USB-serial adapter which is configured for 3.3V logic.

The upcoming revision 2 of the Raspberry Pi Model B will add a header with an additional 4 GPIOs, along with support for debugging the ARM processor via a JTAG port.

Next: Components, kits and expansion

Print Version | Permalink: http://h-online.com/-1704735
  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit
 


  • July's Community Calendar





The H Open

The H Security

The H Developer

The H Internet Toolkit