Home and Links
 Your PC and Security
 Server NAS
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Setting up the Raspberry Pi camera

Pi Camera setup


Buying a Pi Camera

You should ALWAYS shop around for Pi 'parts' ! Even the basic Raspberry Pi's (A,A+,B,B+,B2,B3) can differ in price between different vendors (especially after adding compulsory delivery costs) and the various Pi Camera prices even more so = for example :-

Pi Camera prices as of 8 Jan 2016 (including VAT and delivery) :-
http://cpc.farnell.com - £20.15 (you have to search for the Pi Camera on it's own, if not they will try to see you a 'Pi Camera kit' for £50+)
http://www.amazon.co.uk - £18.95
http://www.modmypi.com - £15.99 (which includes postage of £2.99)
http://uk.rs-online.com/web/p/video-modules/7757731/ - £9.59 (post free) = yes, less than half the CPC price !

Note that the 'standard' Camera lens is a fixed-focus 'f/2.9', specified to work from '1 m to infinity'. This means that anything closer than 1m away will be 'out of focus', BUT the lens is held in a screw-thread fixture that allows the focus to be manually adjusted (for those who want close-ups only)

Some useful specs for the 5 Mpixel Camera of note are :-
Sensor is the OmniVision OV5647 (2592 x 1944 pixels @ 1.4 m sq., 10bit RAW)
Mode switching (preview to photo to video) approx 40mS per switch.
(Note, the first frame after a switch is always corrupted)
Time to read the full sensor array, 200mS (so theoretical max. photo rate is 5fps)
Actual max full resolution 2592 x 1944 photos per second = 3fps to class 10 SDHC, 4fps to ram-disk
Max frame rate at full resolution 2592 x 1944 = 15fps
Max frame rate at full HD (1080p) = 30fps
Max frame rate at half HD (720p) = 60fps
Max frame rate at VGA (640x480) = 90fps
Max possible Frame rate = 120fps (at 320x240 pixels)
Pixel sensitivity 680mV/(lux-sec)
Pi supported image formats - JPEG (accelerated), JPEG + RAW , GIF , BMP , PNG , YUV420 , RGB888
Pi supported video format - raw, h.264 (accelerated)

Pi camera vendor sites do contain some useful information (such as the 'getting started' pages at Element14), however the 'vendors' always try to 'sell you up' by promoting their own massively over-priced 'add-ons'.

For example, most vendors will suggest you 'need a hub', however that's only true for the A/A+, and even if you do, why would you pay anything up to £10 for their 'Pi hub' when a perfectly good one can be had from a well know high street store for £1 ?
Even if you need a hub to drive some high power USB add-on, there is still no reason to pay for two power-blocks (you only need one and the ability to solder a wire or two so the hub 'back-drives' the Pi)
The £4 Pi Zero plainly makes very little money for the vendors (even after they add the £2.50 delivery charge), so you will find multiple 'Pi Zero kits', each with various 'adapters' at ever increasing tip-off prices.

Install the Camera

1) The camera comes with a small piece of translucent plastic film covering the lens (usually blue or pink). This is to 'protect the lens during shipping', however it's more vital to keep the dust off ! I recommend you leave it in place until you actually start to take photos.
2) The Pi motherboard CSI socket is the one situated between the HDMI and Ethernet socket position. Pull the 'end tabs' of the 'clamp bar' on the top of the socket upward and then toward the Ethernet socket to release the clamp.
3) Insert the Camera flex cable with the silver side connections facing the HDMI socket.
4) Clamp the cable by pushing the socket tabs toward the HDMI connector and down, whilst holding the flex cable in place.

Enable the Camera

By default, neither Wheezy nor Jessie (2016) loads the GPU camera drivers. To 'enable' the Camera drivers, launch the 'raspi-config' tool from any terminal window :-
sudo raspi-config
Use the 'down' cursor (arrow) key to highlight "Enable camera".
Then use the 'right' cursor to highlight 'change' and hit 'Enter'.
Confirm the change, then 'right' cursor to highlight 'Finish' and press Enter again.
You'll be prompted to reboot - now would be a good time :-)

Check the camera is working

IF you have a display plugged in, then you can simply activate the camera and it will display images in 'preview' mode. For a single image :-

raspistill -f

To preview video :-

raspivid -f

If you don't have a display, you will need to 'write' the image to a file and access that file from your PC. A full resolution jpeg photo will be about 2.2Mb, so exposing at 4fps requires bandwidth of approx. 71 mbps

The Pi can write images to it's SDHC card faster than writing to the Ethernet - a class 4 SDHC is 4x8 = 32mbps (and Class 10 at least 80 mbps), whilst you will be very lucky to get 20mbps out of the Pi Ethernet socket.
Note that many Class 10 SDHC cards achieve write speeds in excess of 100mbs, some 5x faster than the Pi's Ethernet.
A ram-disk is even faster (but limited in size), however can easily be used as a 'buffer' when operating the camera in burst mode (see my next page)

1) This means the 'best' way to 'see' images on the PC is to 'share' a Pi SDHC card folder with the PC - this lets you take photos at high speed (up to 5 a second) and then 'browse' them at leisure on the PC. However that means installing 'samba' on the Pi (and the size of the movie / number of photos will be limited by the size of the SDHC card)

(+) Installing samba - (the Pi as a Network Share on your PC)

To take a photo and write it to '/my-folder-for-PC/my-photo.jpg' :-   sudo raspistill -o /my-folder-for-PC/my-photo.jpg

2) The alternative approach is to set up a 'shared folder' on the PC and have the Pi 'save' across your LAN to that folder. The Pi SHOULD be able to stream HD movies (approx 18mbps, 2.25Mbytes/s) and manage 1 full sized jpeg photo (2.5 Mbytes) per second.

(-) Accessing PC shares from the Pi

Mounting a network 'share' on the Pi

It is, apparently, quite possible to access a Windows PC 'share' from the Pi by simply 'mounting' it = and this is a LOT simpler than trying to install 'samba' and dealing with all the "Could not resolve 'mirrordirector.raspbian.org'"  errors (which is required before you can see Pi shares on a PC)

You should, in fact, be able to 'mount' any existing 'share' on your LAN, including your NAS / Server 'back-up' folders etc.

You start by creating the 'share' on your LAN (eg 'share' a folder on your PC / NAS / Server). You will need to note the share name and the details of a user account (on the PC/NAS etc) that has access to the share.

At the Pi command line, start by creating a 'directory' to act as the mount point:-
sudo mkdir mount-point-dir

Now connect to the Windows share using the mount command:-
sudo mount -t cifs -o username=username,password=password //server-name/share-name mount-point-dir

NB. the PC's IP address can be used in place of 'server-name'

You can now treat the directory (mount-point-dir) just like any other folder on the Pi (ls to list the contents, cd to move to a different folder, cp to copy files etc.)

To unmount the Windows share, use the umount command:
sudo umount mount-point

.. or just reboot the Pi

If you want the 'share' to be mounted automatically after a re-boot (i.e. when you log on), you'll need to add the mount details to fstab :-

You need to create a mount point in /mnt for the PC share point.
sudo mkdir /mnt/share-mount

Now edit your fstab:
sudo nano /etc/fstab

Add a new entry in the following format:
//pc-server/pc-share /mnt/share-mount cifs defaults,rw,username=pc-username,password=pc-user-password,domain=pc-workgroup-name 0 0

Where :
pc-server is the IP address (or NetBIOS name) of your PC,
pc-share is the name of the share that you created on your PC
share-mount is the name of the mount point you have just created.
pc-username and pc-user-password are a valid account on the PC (that has access to the Windows share).
The 'domain' is used the Windows domain or workgroup (i.e. not specifically a domain) = note this is required in fstab (a manual mount at the command line will work without the domain keyword)

To avoid rebooting, you can 'refresh' the shares from the command line :-

sudo mount -av

This note last modified: 17th Sep 2016 08:10.


To take a photo and write it to '/my-PC-folder-for-Pi/my-photo.jpg' :-   sudo raspistill -o /my-PC-folder-for-Pi/my-photo.jpg

Next page :- Using the Pi Camera