Saturday, 29 June 2013

Installing and Running XBMC on the Raspberry Pi

One of the most exciting applications of the Raspberry Pi is to use it as a media centre connected to your TV so that you can watch videos, play music and view online content from the comfort of your sofa. There are a few different distributions available for this very purpose but in this post I'll look at how to install and run the popular XBMC software on the Raspberry Pi.

Luckily, most of the hard work has already been done - all you have to do is go to www.raspbmc.com and download the appropriate image file and write it to a blank SD(HC) memory card.When you look at the download page on the Raspbmc web site there are various options available, but the recommended option (and I agree) is the one called "Network Image". Click on this option and you will download a file called "installer.img.gz" which is a compressed archive and is only about 16MB.

By now (like me) you've probably realised the many advantages of having a PC or laptop running a Linux distribution, so I'll assume you've downloaded the compressed image file on to your Linux system (I use Lubuntu running on a laptop and it has the advantage of having the same look and feel as the GUI on the Raspberry Pi).

Open File Manager and go to where you saved the downloaded file (mine was saved in folder "/home/tom/Downloads").


Double click on the file and this should open it in Archive Manager. This will show which files are contained in the compressed archive (in this case only one file called "installer.img").


Click on the "Extract" and when the "Extract" window opens, click on the "Extract" button on the bottom right corner of the window.



This will decompress the archive and extract the image file. If all goes well you should get confirmation that the process was sucessfull.


Click on "Quit" to close Archive Manager. You should now have the image file in the folder along with the compressed archive.


As you'll see later it's now a good idea to move (or copy) this image file into your home folder, which in my case is called "/home/tom" (because my username is "tom"). In any case, make a mental note of where the image file is saved on your Linux system. Now, open a terminal window and type "df" at the command line prompt and press Enter:

tom@mylaptop: ~ $ df_

This will display the various partitions on your hard drive. You should get results similar to what is shown in the following screenshot:


Now insert your (formatted) SD(HC) card into the card reader/writer slot on your Linux system (or into a USB card reader/writer like this one available from Cut Price Cables, and then plug the card reader/writer into a spare USB port on your system) and once again type "df" at the command line prompt and press Enter:

tom@mylaptop: ~ $ df_

This time the results should include an entry for your SD(HC) card (in my case it shows up as "/dev/sdb1"):



Now type "umount /dev/sdb1" (replacing "/dev/sdb1" with whatever your SD(HC) card is called) at the command line prompt and press Enter:

tom@mylaptop: ~ $ umount /dev/sdb1_

Now, once again, type "df" at the command line prompt and press Enter:

tom@mylaptop: ~ $ df_

The entry for your SD(HC) card should no longer be listed:


Now, type "ls" at the command line prompt and press Enter:

tom@mylaptop: ~ $ ls_

This will show all the files in your home folder. If you moved (or copied) the image file to your home folder, it should show up in the listing:


Now for the really important part! Type the following command at the command line prompt and press Enter:

tom@mylaptop: ~ $ sudo dd bs=4M if=installer.img of=/dev/sdb_

Please Note  - you must enter the name of your SD(HC) card without any numbers at the end - so in my case I entered "/dev/sdb" because my SD(HC) card name was "/dev/sdb1". You will then have to enter the password for your user account on your linux system.


Assuming you get a confirmation message like the one shown above, the image file should now be written on to your SD(HC) card.

Now, type "sudo sync" at the command line prompt and press Enter:

tom@mylaptop: ~ $ sudo sync_

Again you will be asked to enter your password, but after this command has been executed you can remove the SD(HC) card from your Linux system and insert it into your Raspberry Pi.

Connect keyboard, mouse, display screen and (most importantly) Ethernet cable (all of which are available from Cut Price Cables at a very competitive price) to your Raspberry Pi and then power it up. You'll see a lot of text scrolling up your screen followed by a blue screen and various welcome messages. Time to put the kettle on!

Eventually XBMC will install itself, update itself and launch on your Raspberry Pi......

Thursday, 20 June 2013

Running the Raspberry Pi from another PC using the Pi Console

In my previous post I explained how to connect to the GPIO serial port so that the another computer can be connected to the Raspberry Pi either directly using its serial port or via a USB to serial interface (I've used both methods and the end result is the same). This opens up the possibility of running the Raspberry Pi remotely via the Pi console, but to do this requires some software to be installed on the host computer.

For Windows users...

If you're running Windows XP (or earlier) you should already have a program called "HyperTerminal" which you can use but I'll assume you are running a later version of Windows...

I would suggest you download and install PuTTY (available here), but there are other similar programs you could use. When you install and run PuTTY you should see the following screen:


Change the "Connection type" to "Serial" and then specify the serial port you want to use (in my case COM1) and set the speed to 115200. Note that if you are using a USB to serial interface connected to your host computer you'll probably need to have a look at "Devive Manager" to see what port number has been assigned to it. If you are using a physical serial port then it's probably going to be COM1 or COM2.


OK, once you've specified the com port and speed click on "Open" and you should see a blank console window (remember the Raspberry Pi isn't connected yet!):


With your Raspberry Pi powered down, connect it to the host computer by plugging the female 9 pin D connector (see my previous post...) into a free serial port, or into a USB to serial interface if you're using one. Now power up your Raspberry Pi. You should see the now familiar boot up text scrolling up the console window, and eventually you should be prompted to login:


Notice the line just above the login prompt - the address "ttyAMA0" refers to the serial interface on the GPIO header. Go ahead and login as normal and you'll get to the command line interface, just as you would when working directly on the Raspberry Pi.


For Linux users...

Again, I would suggest you download and install PuTTY from your repository, but there are other similar programs you could use. When you've installed PuTTY, login to your Linux system and type "groups" at the command line prompt and press Enter:

tom@mylaptop: ~ $ groups_

Please note that my username is "tom", and my Linux system is called "mylaptop" - you will obviously see your own user and system names here. The "groups" will display a list of groups which you (as a user of the system) belong to. Look for one called "dialout". If it isn't listed type the following at the command line prompt and press Enter (remembering to replace "tom" with your username):

tom@mylaptop: ~ $ sudo usermod -a -G dialout tom_

This will add you to the "dialout" group which is a necessary requirement for you to use PuTTY. Now launch the PuTTY application. Change the "Connection type" to "Serial" and then specify the name of the serial port you want to use. If you are using a physical serial port the port name should be "/dev/ttyS0" (or "/dev/ttyS1" if you have more than one physical serial port). If (like me) you are using a USB to serial interface the port name should be "/dev/ttyUSB0". Finally set the speed to 115200:


Now click "Open" to connect to the serial port, and you should see a blank console window. Proceed as described above for Windows users (i.e. connect your Rasperry Pi and power it up), and you should be able to login to your Raspberry Pi from your Linux system.

So now what?

Well you can use the command line interface on your Raspberry Pi as you normally would, although the interface will be text only (no graphics). You won't be able to use the GUI by entering the "startx" command, but who needs a graphical user interface anyway....

It does make your Raspberry Pi a lot more portable when you don't have a keyboard, screen and mouse connected to it. The only connections you need are a power source and the serial connection, which consists of only three wires.

I took advantage of this portability and took my Raspberry Pi outside and placed it in front of my cat's bowl and waited until he came to feed. I was then able to remotely take photos of him eating out of his bowl using the Raspberry Pi camera module.


In my next post I'll take the portability one stage further by using a wireless serial link.

Tuesday, 18 June 2013

Serial Communications using the GPIO header on the Raspberry Pi

As I mentioned in a previous post the Raspberry Pi has a serial port as part of the GPIO interface. However this serial port uses 3.3V TTL logic which is not compatible with the RS232 standard which uses +/- 12V. In order to use the Raspberry Pi's GPIO serial port with RS232 devices a level shifter is required. It would be quite straight forward to make your own level shifter based on the MAX3232 chip, but I managed to get hold of some of these tiny ready made modules from China:


As you can see they are based on an SMD version of the MAX3232 IC and each end is labelled with data in, data out, and +/- power connections.


The PCBs are double sided and as I understand it there are two separate comms channels - one on each side of the board. The modules are so small that I decided to solder one directly on to the back of a female  9 pin D connector so that once assembled it would be hidden inside the connector shell.


The output from the level shifter board (as indicated by the arrow) was connected to pin number 2, the input to the level shifter board (as indicated by the arrow) was connected to pin number 3, and the system ground (-ve) connection on the level shifter board was connected to pin number 5. Note that pin number 4 on the female 9 pin D connector was cut off so that it didn't inadvertently make contact with the +ve terminal on the level shifter board. As previously mentioned these boards are double sided so a small strip of insulating material (I used clear acetate sheet) was placed between the pins on the D connector and the terminals on the other side of the level shifter board to prevent inadvertent connections being made. Finally wires were carefully soldered to the pads on the opposite end of the level shifter board and the complete assembly inserted into the connector shell.


Not forgetting to fit the cable grip before fitting the other half of the shell.


The finished item, assembled and ready to go. I have a limited number of these ready built and tested units available for purchase from www.cutpricecables.co.uk for only £9.99 each inc VAT and UK delivery - please email me for details if you are interested.


The other ends of the wires are fitted with connectors that will attach directly to the GPIO pins on the Raspberry Pi.


These wires were connected to the GPIO header on the Raspberry Pi as follows. The data wires (white and blue) were connected to GPIO 14 (TXD - pin number 8) and GPIO 15 (RXD - pin number 10) respectively. The ground connection (black wire) was connected to the ground pin (pin number 6 on the GPIO header), and the power connection (red wire) was connected to the 3.3V power pin (pin number 1 on the GPIO header).


By default the serial port on the Raspberry Pi's GPIO header is configured to be used for console input/output. Therefore to operate the Raspberry Pi in "headless mode" (i.e. via a console interface on another computer) all that is required is to connect the female 9 pin connector to the serial port on another computer (or to a USB to serial interface connected to another computer) and then run a terminal emulation program on the other computer. Details of how to do this will be the subject of my next post.

Tuesday, 11 June 2013

A simple enclosure for the Raspberry Pi Camera

After installing the camera module I wasn't happy leaving it exposed outside the Rasperry Pi's case and started to think about how to protect it, and hold it steady while taking photos.

I found a small black plastic enclosure in my junk box and decided to mount the camera board inside it. I drilled a hole for the lens and two smaller holes for mounting LED's to provide supplementary illumination in low light conditions if required (these will be added later...).


The Raspberry Pi camera board does have mounting holes, but some of the components on the board are very close to the holes, so rather than risk damage to the board I decided to mount it using four small double sided sticky foam pads.


Here's a photo of the camera board mounted in the enclosure...


...and here's what it looks like from behind.


I cut away and filed the edge of the enclosure's wall, and the edge of the lid, to allow the ribbon cable to pass through without being pinched. The following photo shows the enclosure with the lid fitted and the ribbon cable passing out through the slot.


I mounted the camera enclosure on top of the Raspberry Pi's case using some larger double sided sticky foam pads...


... and routed the ribbon cable in through the back of the Raspberry Pi's case. I had to trim the case slightly in order to allow the ribbon cable to enter without being pinched.


So there you have it! A very simple and dare I say rough and ready enclosure for the Raspberry Pi camera board using a small plastic enclosure I had to hand. All I have to do now is find something to photograph...