Thursday, 23 May 2013

Installing the Raspberry Pi Camera Module - Part 2

Now it's time to connect the camera module to your Raspberry Pi. Shut down your Raspberry Pi and unplug all cables. If like me you use a case to protect your Raspberry Pi then you'll have to open up the case. The camera connector is located just next to the Ethernet network socket. The socket clamps the ribbon cable but before you insert the ribbon cable into the socket you must first "open" the clamp by gently pulling on the small tabs on either end of the socket. The tabs are indicated by the arrows in the following photo.


The next photo shows the camera connector opened and ready to receive the ribbon cable.


Now insert the end of the ribbon cable in to the socket with the metal contacts facing you and close the socket by pushing the clamp back down.


Now you can route the ribbon cable however you want to. The case I use (available from Cut Price Cables) has an opening in the side which is designed to allow access to the GPIO pins. The opening is in the form of a long narrow slot and is ideal for routing the ribbon cable through. I carefully folded the ribbon cable over on itself so that it passed out through the opening as shown in the following photo.


The next photo shows the Raspberry Pi with its case reassembled and the camera module resting on top of the case.


As a temporary measure to keep the camera module from flapping around I attached the camera module to the outside of the case using a couple of double sided sticky foam pads. I also removed the small protective plastic tab on the front of the camera lens.


Now you can boot up your Raspberry Pi as normal. Once you get to the command line prompt you can now take photos using the "raspistill" command or capture video using the "raspivid" command. To see what commmand line options are available for the "raspistill" command type "/opt/vc/bin/raspistill" at the command line prompt and press Enter:


pi@raspberrypi ~ $ /opt/vc/bin/raspistill_

You can take a photo by typing "/opt/vc/bin/raspistill -o test.jpg" at the command line prompt and pressing Enter:



pi@raspberrypi ~ $ /opt/vc/bin/raspistill -o test.jpg_


This will display a 5 second preview of that the camera sees, and then take a photo and save it to the file "test.jpg" in the /home/pi folder on your SD(HC) card. Here is a photo of the view outside my window which was taken using the camera module attached to my Rasperry Pi.


Here is another photo of the map on my office wall. The photo has been cropped using image editing software, but can you spot the slight problem?....


The photo has been mirrored, but this is how the camera took the photo! This problem can be easily corrected using any photo editing software, and there is even a "horizontal flip" command line option that can be used when taking a photo to save the image the right way around in the first place.

In this post I have only scratched the surface of what you can do with the camera module, but I hope that what I have written has been helpful at least in terms of explaining how to connect, setup and use this interesting add-on to the Raspberry Pi.

Sunday, 19 May 2013

Installing the Raspberry Pi Camera Module - Part 1

The Raspberry Pi Camera module recently went on sale and I managed to get hold of one to play, I mean experiment, with. The module itself came with no documentation, but I did manage to find a document on the Element14 web site called "Unofficial guide to getting up and running with the Raspberry Pi Camera" which was very helpful. You can find this document here if you are interested.

Ok, so lets have a look at what you get for your hard earned cash. The ruler is included in the photos to give an idea of scale. The actual camera is tiny and is mounted on a board which is only about 25mm x 25mm:



The camera board comes with a pre-fitted ribbon cable which is about 15 cm long. The following photos show front and back views of the complete assembly as supplied.



Unfortunately the camera module isn't quite "plug and play" and there are a few preparatory tasks to perform before before it can be used with the Raspberry Pi.

First of all you need to download the latest release of the Raspbian "Wheezy" operating system from www.raspberrypi.org and install it on a freshly formatted SD(HC) memory card (4GB or larger). At the time of writing the most recent release is dated 2013-02-09. I've covered in detail how to make a bootable SD(HC) card in a previous post so I won't repeat it here.

The first time you boot from this new SD(HC) card "Raspi-config" will run automatically. Use the "expand_rootfs" option to expand the root partition on the SD(HC) card to use all the available space (how to do this is covered in detail in a previous post).

 Now choose the "memory_split" option and press Enter:


This option allows you to specify how much memory to allocate to the graphics processor. Type in "128" and press Enter:


Now select "Finish" and allow your Raspberry Pi to reboot. Then log in and run the "sudo apt-get update" and "sudo apt-get upgrade" commands. Details of how to do this can be found here if you need them.

Let your Raspberry Pi reboot and then run the "Raspi-config" commmand again by typing "sudo raspi-config" at the command line prompt and pressing Enter:

pi@raspberrypi ~ $ sudo raspi-config_

There should now be an option to enable camera support. Use the arrow keys to move down to the "camera" command and press Enter:


Select "Enable" and press Enter:



When you return to the Raspi-config main screen select the "Finish" option and then reboot your Raspberry Pi.

Your Raspberry Pi should now be ready for the camera module, but just to be sure, go into the GUI, launch "Leafpad" and open the file "/boot/config.txt". Scroll down to the bottom of the file - the last few lines in the file should contain the entries "gpu_mem=128", "start_file=start_x.elf" and "fixup_file=fixup_x.dat" as shown in the following screenshot.


In my next post I'll explain how to connect the camera module to the Raspberry Pi and get it up and running.

Friday, 3 May 2013

Displaying System Information and Overclocking

The "vcgencmd" command is very useful and allows you to display all manner of system information like for example the clock speed of the CPU, the voltage the CPU is running at and the temperature of the system core.

To find out the clock speed of the ARM processor type "vcgencmd measure_clock arm" at the command line prompt and press Enter:

pi@raspberrypi ~ $ vcgencmd measure_clock arm_

This should return a result similar to the following, which in my case shows that the ARM processor is running at 700 MHz (700,000,000 Hz):

frequency(45)=700000000

You can also measure your system's core frequency by typing "vcgencmd measure_clock core" at the command line prompt and press Enter:

pi@raspberrypi ~ $ vcgencmd measure_clock core_

This should return a result similar to the following, which in my case shows that the system core is running at 250 MHz (250,000,000 Hz):

frequency(1)=250000000

To measure the voltage your system is running at type "vcgencmd measure_volts" at the command line prompt and press Enter:

pi@raspberrypi ~ $ vcgencmd measure_volts_

This should return a result similar to the following, which in my case shows that the system is running at 1.20 volts:

volt=1.20V

Finally you can measure your system's core temperature by typing "vcgencmd measure_temp" at the command line prompt and press Enter:

pi@raspberrypi ~ $ vcgencmd measure_temp_

This should return a result similar to the following, which in my case shows that the system is running at at temperature of 48.2 deg C:

temp=48.2'C

All the above commands are very useful for monitoring your system, especially if you wish to overclock your Raspberry Pi. Overclocking simply means running your system at a higher frequency and/or voltage than it was designed for in order to increase performance, but an overclocked system will inevitably run hotter and possibly be less reliable than a non-overclocked system.

To start experimenting with overclocking run the Raspberry Pi configuration utility by typing "sudo raspi-config" at the command line prompt and pressing Enter:

pi@raspberrypi ~ $ sudo raspi-config_

Use the arrow keys to move down to the "overclock" command and press Enter:



You will then see the following warning message:



Press Enter to dismiss this warning and you will be presented with a number of overclocking options to choose from:



Select your desired option and press Enter. Your will receive conformation of your selection (in my case I selected "Medium"):



Then you will be returned to the Raspi-config main screen. When you select "Finish" and press Enter you will be asked if you want to reboot now:



Select "Yes" and let your Raspberry Pi reboot. Once your Raspberry Pi has rebooted and you have signed back in you can use the "vcgencmd" commands to check the frequency, voltage and temperature of your system.

Please note however that your system will only use the overclocking settings if required. In other words when the system is "idle" CPU frequency and voltage will be normal, but under load the overclocking settings will be used. You can see this if you run the "vcgencmd" commands when the system is "idle" and then run them again while you have a resource hungry application running in the background.

Also note that even if overclocking settings are enabled, holding down the "Shift" key while the system is rebooting will cause overclocking to be disabled temporarily until the system is rebooted again

A final word of warning - overclocking can cause your SD memory card to become corrupted, so if you want to experiment with overclocking make sure to back up your memory card first...