OpenSource For You

Getting Started with Raspberry Pi

Raspberry Pi is an inexpensiv­e ARM processor-based single-board computer that runs the GNU/Linux operating system. For only $35, you get a system that can play games, stream video, function as a network server, control devices through input/output (I/O) p

-

Raspberry Pi is powered by a BCM28PR system-onchip from Broadcom that contains an ARM processor (running at T00 MHz) and a powerful graphics processing unit capable of PD operations. The peripheral­s include two rpB master ports, 10/100 Ethernet, HDMI and composite video outputs, and an pD card slot (more details available at www.raspberryp­i.org/faqs).pystem memory is 2RS MB of RAM. A few general-purpose input/output (dPIO) pins are available for low-level interfacin­g with the external electronic circuitry.

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

Things you need, to get started

Raspberry Pi is a complete system—connect a rpB keyboard/ mouse and a DsI/HDMI monitor to it and you are ready WR JR! 7hH /LnXx RSHUDWLnJ VyVWHP NHUnHO DnG WhH URRW fiOH system have to be present on the pD card.

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

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

Preparing the SD card using a GNU/Linux system

The easiest way to get started with Raspberry Pi is to use Dn 6D FDUG WR VWRUH WhH fiOH VyVWHP LPDJH. 7hH 5DVSEHUUy Pi website ( www.raspberryp­i.org/downloads) provides prebuilt images for both Debian dNr/iinux and Arch iinux. I prefer Arch because of its simplicity and the ease with which you can keep packages updated.

Download the Arch iinux image and unzip it using the following command:

unzip archlinuxa­rm-13-06-2012.zip

7hH AUFh /LnXx LPDJH fiOHV DUH FRnWLnXRXV­Oy XSGDWHG. 6R WhH nDPH RI WhH fiOH WhDW yRX hDYH GRwnORDGHG PLJhW EH different from what you see above.

You will now see a directory called ‘ archlinuxa­rm-13-06-2012.’ Change into this directory, YHULIy WhH FhHFNVXP RI WhH fiOH wLWh WhH ‘img’ extension resent in the directory and write it to your pD card using the ‘dd’ command as follows:

cd archlinuxa­rm-13-06-2012 sha1sum -c archlinuxa­rm-13-06-2012. img.sha1 dd if=archlinuxa­rm-13-06-2012.img of=/dev/sdb bs=1M

I am assuming that your pD card is detected as a device ‘/ dev/sdb’ on the dNr/iinux system you are using to write the LPDJH fiOH.

You can now connect the keyboard, mouse and monitor (and optionally the network cable) to Raspberry Pi, insert the pD card into its slot and power on the board. You should see ERRW PHVVDJHV VFUROOLnJ Ey Rn WhH VFUHHn. YRX wLOO EH finDOOy presented with a login prompt. iog in with user name ‘root’ and password ‘root’.

Detailed instructio­ns for setting up the pD card are available on the following Raspberry Pi wiki page: http://elinux.org/RPi_Easy_SD_Card_Setup

Setting up networking on Raspberry Pi

If the Ethernet cable is plugged in, and if you have a DHCP server active on your network, Raspberry Pi’s network LnWHUIDFH wLOO DXWRPDWLFD­OOy FRnfiJXUH DW ERRW XS. YRX FDn verify this by pinging a well-known host, as follows:

ping google.com

For some reason, the network interface on my Raspberry wDV nRW JHWWLnJ FRnfiJXUHG DXWRPDWLFD­OOy. , hDG WR HxHFXWH WhH following commands to get things ready:

mii-tool -A 10baseT-FD eth0 dhcpcd eth0

Performing an Arch Linux system update

The packages in an Arch iinux distributi­on get updated continuous­ly—you can always bring the system up-to-date by executing the following command:

pacman -Syu

‘pacman’ is the Arch iinux package installer (similar to ‘apt’ on Debian/rbuntu). It is recommende­d that you perform this step and reboot Raspberry Pi.

Setting up X Windows

petting up a basic graphical user interface (with u Windows) is simple. gust use ‘pacman’ to install some packages, as follows:

pacman -S xorg-server xorg-apps xorgxinit xorg-twm xterm xf86-video-fbdev You can run X by typing ‘startx’ at the command prompt.

Installing Python

iet’s use Python to write our demo app and install it using ‘pacman’, as shown below:

pacman -S python2

You may additional­ly install package ‘python2-pyserial’ if you plan to do some serial communicat­ion.

How to write a ‘blinking LED’ program

WARNINd: Interfacin­g electronic circuits to Raspberry Pi might damage the board if not done correctly.

The dPIO pins of a processor are useful for controllin­g external electronic circuitry. One of the simplest things you can do with these pins is write code, which will output a logic high (P.Ps) or low (0s) on them. Raspberry Pi has a set of 2S pins (arranged as a 2x1P strip), which bring out a few of the dPIO 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, P10P and so on. Check out http://elinux.org/RPi_Low-level_ peripheral­s 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 interfacin­g.)

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 dPIO access library can be downloaded from http://pypi.python.org/pypi/RPi.GPIO. It is available as D WDU fiOH, 53L.G3,2-0.2.0.WDU.Jz. (DRn’W wRUUy LI WhH YHUVLRn number you see 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 the super user), as follows:

tar xvf RPi.GPIO-0.2.0.tar.gz cd Rpi.GPIO-0.2.0 python2 setup.py install

Connect a red iED in series with a 1-kilo-ohm resistor between pins P1-08 (dPIO pin) and P1-0S (dND) 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)

CRnfiJXUH SLn 31-08 DV Dn RXWSXW SLn XVLnJ G3,2.VHWXS DnG write high/low values to it using the function dPIO.output.

,nWHUnDOOy, WhH 3yWhRn G3,2 OLEUDUy XVHV VSHFLDO fiOHV under ‘/sys’ directory to access the I/O pins. The disadvanta­ge with this method is that you really can’t perform timingsens­itive operations this way.

Streaming video from a webcam

po what role can Raspberry Pi play in the design of your embedded system?

If your applicatio­n needs fast media processing and networking, you can replace your PC with Raspberry Pi, which consumes considerab­ly 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 measuring the time delay between low to high transition­s of an I/O pin to microsecon­d-level precision), you can use something like an Arduino and interface it with Raspberry Pi.

iet us, for example, assume that you wish to capture the video stream from your webcam and make it available over

WhH nHWwRUN. 7hH fiUVW VWHS LV WR FRnnHFW WhH wHEFDP DnG VHH whHWhHU 5DVSEHUUy 3L UHFRJnLVHV LW—LI yRX VHH D fiOH FDOOHG ‘video0’ under ‘/dev’, everything should work well!

Next, you can install the popular ‘ffmpeg’ package, which does a whole lot of video manipulati­ons, including streaming, using the following command:

pacman -S ffmpeg

/HW’V nRw FUHDWH D VPDOO FRnfiJXUDW­LRn fiOH FDOOHG ‘ffserv.conf’. 7hLV fiOH VXSSOLHV LnIRUPDWLR­n OLNH WhH nHWwRUN SRUW DW whLFh the stream is available, the name of the stream, etc. Issue the following commands:

Port 8010 BindAddres­s 0.0.0.0 MaxClients 10 MaxBandwid­th 1000 <Feed feed1.ffm> File /tmp/webcam.ffm FileMaxSiz­e 5M </Feed> <Stream feed1.mjpeg> Feed feed1.ffm Format mpjpeg VideoSize 160x128 VideoFrame­Rate 3 VideoIntra­Only Noaudio Strict -1 </Stream>

Check out http://ffmpeg.org/sample.html for more LnIRUPDWLR­n Rn WhH SDUDPHWHUV Ln WhLV FRnfiJXUDW­LRn fiOH. ptreaming of the video is done by a program called ‘ffserver’. Invoke it with the following command:

ffserver -f ./ffserv.conf

‘ffserver’ automatica­lly goes into the background. Now you have to run ‘ffmpeg’ to capture data from the webcam and supply it to ‘ffserver’, as follows:

ffmpeg-v2 -r5 -s160x128 -f vide o4linux2 -i /dev/video0 http://local host:8010/feed1.ffm

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

How to move your webcam with a servo motor

You can mount your webcam on the shaft of a hobby servo motor and control it using Raspberry Pi! The easiest way to do this is to run the servo control code on Arduino and send commands to Arduino from Raspberry Pi. When Arduino is connected to the rpB port of Raspberry Pi, the serial port on Arduino is accessible as a special file ( usually ‘/ dev/ ttyACM0’) on Raspberry Pi. 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 Raspberry Pi, 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 dNr/iinux 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 its designers plan to launch on a journey across the Atlantic, unaided!

 ??  ?? Figure1: Raspberry Pi
Figure1: Raspberry Pi
 ??  ?? Figure 2: Boot messages scrolling by on the screen
Figure 2: Boot messages scrolling by on the screen

Newspapers in English

Newspapers from India