logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Setting up the Raspberry Pi camera

Pi Camera setup

*** UNDER CONSTRUCTION ***

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
Video:
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)


As with everything *nix, it seems command and component names change with every new System release. Most of the guides you will find are based on the Raspbian Wheezy and NOT the 'latest' Raspbian Jessie - and the fact is, what 'works' with Wheezy does NOT work with Jessie. Since you must have Jessie for the Pi Zero I focus on Jessie ONLY.

NB. to check which Pi OS version you have, type "uname -a" at the command prompt. If you get something like 'Linux raspberrypi 4.4.11+ ..." that's Jessie (yeah, well, just like everything else in the *nix world you didn't think the OS would identify itself with anything as obvious as 'Jessie' did you ?)

Sharing a folder using samba

To 'push' data from the PC to the Pi across your LAN, you need to set up a 'share' on the Pi that can be 'mapped' from your Windows PC. This can be a real pain as it involves installing samba on the Pi

First ensure your Pi has the most recent list of the available 'update' packages :-

sudo apt-get update
Next, get and install the samba package :-

sudo apt-get install samba samba-common
Even if you have a 'direct' connection to the Internet (i.e. the Pi is plugged into your Router LAN directly, and not via ICS) it's still possible that one or more of the 'packages' will fail to download (or for the install itself to fail), so pay attention to the status reports that appear on the Terminal command line.

If the packages partially download, just type 'sudo apt-get install samba samba-common' again
If you get continuous "Could not resolve 'mirrordirector.raspbian.org'" errors, see at end of this note

Setting the samba user

Samba has it's own list of valid user accounts. To add 'pi' to the list of permitted samba users :-
sudo smbpasswd -a pi
If you get 'command not found' then samba has not installed correctly, so revisit 'Installing samba' above (retype 'sudo apt-get install samba samba-common')

Setting up a folder to share

Typically, you will be setting up a new folder on the Pi to 'share' with the PC  (or you can just share (all) the existing ones - see later). To set up a new folder eg 'photos' :-
sudo mkdir -m 777 /photos
The -m 777 means 'allow executable files' (scripts) to use this folder

Note - when you 'share' a folder, all 'sub folders' within it are also part of the share. This means, for example, if you 'mount' a USB memory stick as a 'sub-folder' to /photos/ - say /photos/usbroot - the contents of the USB stick plugged into the Pi now become visible to the PC user

Sharing the folder

Folders to be shared must be given a 'share name' - for example 'pi-share' - that the PC user will use to 'map network drive'. To do this, edit the /etc/samba/smb.conf file. For example, to share the folder created above (sudo mkdir /my-folder-for-PC) as 'pi-share':-

sudo nano /etc/samba/smb.conf
then add at the bottom :-
[pi-share]
comment = My share folder
path = /photos
browseable = yes
read only = no

To share the entire Pi system, set the share-name to something obvious (like [pi-root]) and set the path=/ 

To check what you entered into smb.conf :-
/usr/bin/testparm
NOTE: 'testparm' just lists the 'shares' = if you change the name of a 'target' folder (eg from /my-folder-for-PC to /photos) using 'mv' ("move"), the old folder is NOT 'moved' to the new name in smb.conf (it will continue to 'point' at the old folder).

This means the 'share-name' will become 'unlinked' from Pi source folder, although 'testparm' won't complain (although your PC will throw an error when it can't find the Pi mapped drive contents, perhaps even claiming 'network unavailable')

Activating samba

To ensure a 'clean' start-up, reboot the Pi :-
sudo reboot now
After samba has started OK for the first time, if you add (or change) the 'shares' in /etc/samba/smb.conf, all you need to do is restart samba (rather than reboot the Pi). To restart samba :-
sudo samba restart

Accessing the Pi samba share from your PC

If you know the Pi's IP address, then from 'My Computer', Tools, Map Network Drive. Enter the path to the Pi share-name folder (eg //192.168.0.103/pi-share) when asked for user, enter 'pi', password 'raspberry'.

If using Bonjour to find the Pi, you 'map' using 'raspberrypi.local' instead of the IP address (eg //raspberrypi.local/pi-share)


Pi Zero and "mirrordirector.raspbian.org" errors

Using a Pi Zero in RNDIS Gadget mode, when I attempted the 'apt-get' it successfully obtained the 'package lists' but then ended up with a series of "Could not resolve 'mirrordirector.raspbian.org'" errors.

'mirrordirector.raspbian.org' is a 'clever trick' by raspbian.org designed (I assume) to reduce loading on their servers by redirecting download requests to other sources, but (of course) I have no doubt this trips up all sorts of Firewalls, anti-virus and anti-'man-in-the-middle attack' prevention software on your PC.

The way out of this quagmire is (apparently) to bypass the 'redirect' by going direct to the raspbian.org servers :-
sudo nano /etc/apt/sources.list
replace 'mirrordirector' in :-
deb http://mirrordirector.raspbian.org/raspbian  ...
with 'archive'  as follows :-
deb http://archive.raspbian.org/raspbian ...

Needless to say, this didn't actually work for me, even after I manually downloaded raspbian.org's public key and installed it onto the Pi :-
wget http://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -

Update - the 'mirrordirector' problem is not due to the RNDIS Gadget driver.

A Raspberry Pi B+ that would 'apt-get' just fine when wired direct to my LAN, exhibited the exact same 'mirrordirector.raspbian.org' errors as did the USB Gadget connected Pi Zero when wired to my Laptop (and thence via ICS and the laptop's WiFi link to the Internet) .

So (as usual) it's down to Microsoft and the way ICS works (or, in this case, doesn't work). You may have better luck using 'Bridging' (on the other hand, setting up on the B+ and moving the SDHC card to the Zero is faster)


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

[top]


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


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

[top]