SEPTEMBER 2012: The Raspberry Pi (Fig. 1) is powered by a BCM2835 system-on-chip from Broadcom that contains an ARM processor (running at 700 MHz) and a powerful graphics processing unit capable of 3D operations. The peripherals include two USB master ports, 10/100 Ethernet, HDMI and composite video outputs, and an SD card slot (more details available at www.raspberrypi.org/faqs). System memory is 256 MB of RAM. A few general-purpose input/output (GPIO) pins are available for low-level interfacing with the external electronic circuitry.

There are two models of the device. Model A has 256MB RAM, one USB port and no Ethernet (network connection). Model B has 256MB RAM, two USB ports and an Ethernet port. Only Model B is currently in production.

Things you need to get started
The Raspberry Pi is a complete system—connect a USB keyboard/mouse and a DVI/HDMI monitor to it and you are ready to go! The Linux operating system kernel and the root file system have to be present on the SD card.

Explore Circuits and Projects Explore Videos and Tutorials

Note that the device does not support VGA monitors—you have to use a monitor with DVI/HDMI inputs. In case you have a monitor that accepts DVI inputs, you need an HDMI-to-DVI converter cable. An old TV set can also be used as a display by connecting it to the composite video output of the Raspberry Pi.

A standard micro USB mobile charger (capable of handling at least 700 mA of current) can be used to supply power to the board.

Fig. 1: Raspberry Pi
Fig. 1: Raspberry Pi

Preparing the SD card using a GNU/Linux system
The easiest way to get started with the Raspberry Pi is to use an SD card to store the file system image. The Raspberry Pi website (www.raspberrypi.org/downloads) provides pre-built images for both Debian GNU/Linux and Arch Linux. I prefer Arch because of its simplicity and the ease with which you can keep packages updated.

Download the Arch Linux image and unzip it using the following command:
unzip archlinuxarm-13-06-2012.zip

The Arch Linux image files are continuously updated. So the name of the file that you have downloaded might be different from what you see above.

You will now see a directory called ‘archlinuxarm-13-06-2012.’ Change into this directory, verify the checksum of the file with ‘img’ extension resent in the directory and write it to your SD card using ‘dd’ command:
cd archlinuxarm-13-06-2012
sha1sum -c archlinuxarm-13-06-2012.
img.sha1
dd if=archlinuxarm-13-06-2012.img
of=/dev/sdb bs=1M

I am assuming that your SD card is detected as a device ‘/dev/sdb’ on the GNU/Linux system you are using to write the image file.

READ
PULSE GENERATOR

You can now connect the keyboard, mouse and monitor (and optionally the network cable) to the Raspberry Pi, insert the SD card into its slot and power on the board. You should see boot messages scrolling by on the screen (Fig. 2). You will be finally presented with a login prompt. Login with user name ‘root’ and password ‘root’.

Detailed instructions for SD card setup are available on the following Raspberry Pi wiki page: http://elinux.org/RPi_Easy_SD_Card_Setup

Setting up networking on the Raspberry Pi
If the Ethernet cable is plugged in, and if you have a DHCP server active on your network, your Raspberry Pi’s network interface will automatically configure at boot up. You can verify this by pinging a well-known host:
ping google.com

Because of some reason, the network interface on my Raspberry was not being configured automatically. I had to execute the following commands to get things ready:
mii-tool -A 10baseT-FD eth0
dhcpcd eth0

Fig. 2: Boot messages scrolling by on the screen
Fig. 2: Boot messages scrolling by on the screen

Performing an Arch Linux system update
The packages in an Arch Linux distribution get updated continuously—you can always bring the system up-to-date by executing the following command:
pacman -Syu

‘pacman’ is the Arch Linux package installer (similar to ‘apt’ on Debian/Ubuntu). It is recommended that you perform this step and reboot the Raspberry Pi.

Setting up X Windows
Setting up a basic graphical user interface (with X Windows) is simple. Just use pacman to install some packages:
pacman -S xorg-server xorg-apps xorg-xinit xorg-twm xterm xf86-video-fbdev

You can run X by typing ‘startx’ at the command prompt.

Installing Python
We will use Python to write our demo app; let’s install it using ‘pacman’:
pacman -S python2

You may additionally install package ‘python2-pyserial’ if you plan to do some serial communication.

Let’s write a ‘blinking LED’ program!
WARNING: Interfacing electronic circuits to the Raspberry Pi might damage the board if not done correctly.

The GPIO pins of a processor are useful for controlling external electronic circuitry. One of the simplest things you can do with these pins is write code, which will output a logic high (3.3V) or low (0V) on them. The Raspberry Pi has a set of 26 pins (arranged as a 2×13 strip), which bring out a few of the GPIO pins of the processor on board; you can identify these pins by looking for label ‘P1’ on the board. The pins on this connector are numbered P1-01, P1-02, P1-03 and so on. Check out http://elinux.org/RPi_Low-level_peripherals for a diagram of this connector and details of the I/O pins. (You will note that certain pins are labelled as ‘do not connect.’ These pins should not be used for interfacing.)

READ
Pulse Counter Using AT89C4051

There are many ways in which you can output voltages on these pins. One of the easiest ways is to use a Python library. The Raspberry Pi Python GPIO access library can be downloaded from http://pypi.python.org/pypi/RPi.GPIO. It is available as a tar file, RPi.GPIO-0.2.0.tar.gz. (Don’t worry if the version number you are seeing on the website is different from this; you might be getting a newer version). Installing the module is simple: untar it and run the set-up script (as super user):
tar xvf RPi.GPIO-0.2.0.tar.gz
cd Rpi.GPIO-0.2.0
python2 setup.py install

Connect a red LED in series with a 1-kilo-ohm resistor between pins P1-08 (GPIO pin) and P1-06 (GND) and run the following program:
import RPi.GPIO as GPIO
import time

GPIO.setup(8, GPIO.OUT)
while True:
GPIO.output(8, True) # LED ON
time.sleep(1)
GPIO.output(8, False) # LED OFF
time.sleep(1)

We configure pin P1-08 as an output pin using GPIO.setup and write high/low values to it using the function GPIO.output.

Internally, the Python GPIO library uses special files under ‘/sys’ directory to access the I/O pins. The disadvantage with this method is that you really can’t do timing sensitive operations this way.

Streaming video from a webcam
What role can Raspberry Pi play in the design of your embedded system?

If your application needs fast media processing and networking, you can replace your PC with a Raspberry Pi, which consumes considerably less power (and comes in a much smaller form factor—the size of a credit card). If you need to do timing sensitive operations (like measurement of the time delay between low to high transitions of an I/O pin to microsecond-level precision), you can use something like an Arduino and interface it with the Raspberry Pi.

Here is an example. Say, you wish to capture the video stream from your webcam and make it available over the network. The first step is to connect the webcam and see whether the Raspberry Pi recognises it—if you see a file called ‘video0’ under ‘/dev’, everything should work well!

Next, you can install the popular ‘ffmpeg’ package, which does a whole lot of video manipulations including streaming:
pacman -S ffmpeg

READ
10 Microcontroller Based Projects You Must Not Miss!

Let’s now create a small configuration file called ‘ffserv.conf.’ This file supplies information like the network port at which the stream is available, the name of the stream, etc:
Port 8010
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 1000

File /tmp/webcam.ffm
FileMaxSize 5M

Feed feed1.ffm
Format mpjpeg
VideoSize 160×128
VideoFrameRate 3
VideoIntraOnly
Noaudio
Strict –1

Check out http://ffmpeg.org/sample.html for more information on the parameters in this configuration file. Streaming of the video is done by a program called ‘ffserver.’ Invoke it like this:
ffserver -f ./ffserv.conf
‘ffserver’ automatically goes into the background. Now you have to run ‘ffmpeg’ to capture data from the webcam and supply it to ‘ffserver’:
ffmpeg -v 2 -r 5 -s 160×128 -f video4linux2 -i /dev/video0 http://localhost:8010/feed1.ffm

You can open the browser on a remote machine and enter the following URL to watch a streaming video: http://192.168.1.5:8010/feed1.mjpeg. (You have to replace the address 192.168.1.5 with the IP address assigned to your Raspberry Pi’s Ethernet interface.)

Move your webcam with a servo motor!
You can mount your webcam on the shaft of a hobby servo motor and control it using the Raspberry Pi! The easiest way to do this is to run the servo control code on an Arduino and send commands to the Arduino from the Raspberry Pi. When the Arduino is connected to the USB port of the Raspberry Pi, the serial port on the Arduino is accessible as a special file (usually ‘/dev/ttyACM0’) on the Raspberry. The Python module ‘pyserial’ can be used to write the code, which sends and receives commands over this serial channel. (In our case, the ‘command’ may be simply a number that indicates the angle at which the servo shaft should be positioned.)

The servo control code as well as the Python code running on the Raspberry are available for download at: https://github.com/rlabs/rpi-article.

The start of a revolution!
The Raspberry Pi revolution has just begun. This tiny credit-card sized GNU/Linux system has generated tremendous enthusiasm among hobbyists and ‘do it yourself’ fans all over the world. You can already see people coming up with amazing ideas like the ‘fishpi’ (http://fishpi.org/)—an autonomous Raspberry Pi controlled marine vehicle that is planned to make a journey across the Atlantic unaided!


The author is founder of recursive-labs.com, an online learning start-up focussed on free software-based technologies

LEAVE A REPLY