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

The Pi Zero camera as a dash-cam

Pi dash-cam

*** UNDER CONSTRUCTION ***

What's needed for a dash-cam ?

Your basic DIY Pi Zero Camera and, optionally, a microphone. You might also want to add some control buttons = and that's more or less it !

A microphone is a good idea, but no Pi has direct support for audio input. Instead you will need a USB audio adapter, which will likely mean a USB hub

Powering the Pi

If you want to use it as a 'security camera' you will need to keep it powered-on when the car ignition is off. If you are powering the Pi from a 12v USB adapter (in the car 'cigarette lighter socket'), most vehicles will remove the 12v when the car ignition key is removed (more modern cars have USB sockets, however these are also 'powered off' when the car ignition is off).

As a DIY enthusiast, you can, of course, just run a wire direct from the car battery +12v. However whilst the Pi Zero consumption is small enough not to worry about flattening your battery over-night (or even over-weekend), if you go off on holiday for a couple of weeks it would be all too easy to come back to the airport car park and find you have a flat battery !

Pi Zero PowerBank diode switchover UPSTo avoid a flat battery, use (the guts of) a £1 PowerBank (Poundland) and some Schottky diodes. This will keep your Pi camera running for an hour or so after the ignition is turned off i.e. during the 'high risk' period immediately after you leave your car unattended.

Note. The 12v-5v regulator needs to be rated at 1A or more since it will need to recharge the Powerbank and power the Pi at the same time. It's output also needs to be adjusted to between 5.2 and 5.3v (as it needs to be higher that the Powerbank output (which is typically 5.1v) for the diode 'switch-over' circuit to work)

How it works

The switch-over circuit

When the 12v is present, the output of the regulator (which should be set to about 0.1v above VpowerBank output) charges up the Powerbank (if it needs it) and is passed (via D3 and SW1) to the Pi.
 
When the 12v is removed, R1 ensures the regulator output falls off rapidly. As soon as the Powerbank 'spots' the regulator '5v' has been removed, it turns on it's output and powers the Pi via D4/5 and SW1 (two Schokly diodes, D4 + D5, are used in parallel to minimise the voltage drop). During this switch-over, C1 keeps the Pi running.

The 'power off' circuit.

Note, it's vital that the Pi act on 'power off' and stop writing the video stream to it's SDHC card since a power-loss during an actual SDHC write operations is the major cause of file system corruption. The '/Pwr off' signal (0v) indicates that the 12v supply has been removed and that the Powerbank has discharged to the point that it has turned itself off.

Detecting 'power off' is made more complex by the Powerbank. When the Powerbank is 'charging' (i.e. 5v appears at it's recharge socket), most Powerbanks will turn off their output. It is only when the charge voltage is removed that the Powerbank output becomes 'live'. When the Powerbank internal battery is almost completely discharged, it's output is again switched off.
 
D1 and D2 thus pass 5v to the comparator '+' input. This is compared to the Pi voltage 'halved' by R3 and R4. So long as either the 12v reg. or the powerbank is supplying 5v, the comparator output will be 'hi' (5v). D6 prevents the 5v Hi reaching the Raspberry Pi i/o pin (which can't cope with 5v input) so the Pi i/o pin will be pulled hi by it's own 'internal pull up' (so make sure to select that option when setting up the Pi i/o). Note - the comparator o/p may 'glitch' Lo when the 12v is removed until the Powerbank 'switches on'. To prevent this, a small (10-100nF) cap. can be used (C2).
 
When both the 12v regulator and Powerbank 5v are lost (or switched off via SW-1), R2 will ground the '+' input whilst the '-' remains at 'half Vpi'. The comparator output will go 'Lo' (0v) and this will pull the Raspberry Pi i/o pin Lo (via D6).
 
Note that the value of C1 needs to be large enough to keep Vpi above 4.85v both during the 'switch over' (when the 12v is removed and the Powerbank takes over) and for long enough to keep the Pi going until it acts on the '/Pwr off' signal and shuts itself down.
 
For more on shutting down the Pi, see below

(+) Auto shut down

Note - whilst the Pi camera has to be mounted so it can see the road, there is no need for the back-up power battery pack to be placed nearby

Do you need a display ?

The main reason for fitting a display is so you can check that your Pi Camera is 'pointed' in the right direction and is actually running. If the Pi Camera is 'fixed' into position (and you are transmitting the video stream via WiFi to your LAN), you may not need an actual display screen in the car at all

If you are using the Pi B+, for about £25 you can get a touch display from eBay ("3.5 Inch TFT LCD Display For Raspberry Pi 2/B+"). However, if want to keep costs down (why else use the Pi Zero ?) you can't use the 'normal' Pi 'touchscreen' display (as the Pi Zero lacks the display ribbon SPI socket)
 
Finding a cheap small display for the Pi Zero is not easy, especially if you want one that's simple and easy to use = ie. one that just plugs straight into the Pi 'TV' composite video (RCA/AVI) or the HDMI output.
 
You can find some small displays aimed specifically at the Pi and driven via the Pi I2C pins (these are usually designed as a 'HAT' or 'shield'), however setting them up is a real pain (unlike the 'composite video display' which only needs you to switch the Pi from HDMI to TV out), plus (of course) they cost 'an arm and a leg' ..
 
A 'composite video input' 4.3" display intended for use with a 'reversing camera' in a car can be had for £10-£12 (eBay, "Video Input 4.3Inch 480x272 Car Rear View Monitor .." or similar)

Video recording

Whilst the video can be saved to the SDHC card, that makes recovering the video clips a bit of a pain.

The problem is, there is no easy way to use your PC to copy the files since, on first boot, the Pi NOOBS re-formats all the available SDHC free space into a series of Linux partitions that your PC can't read (whatever the original FAT32 partition size was, it's shrunk down to the minimum possible size (i.e. just sufficient to contain the original NOOBS files in what now become the 'recovery partition'))
 
To 'preserve' more FAT32 space means preventing NOOBS from shrinking it down so much - and that means 'pre-packing' the FAT32 partition with 'dummy' files using your PC (after copying NOOBS onto the card and before moving it to the Pi)
 
Of course FAT32 is not a very 'robust' file system, and if you use it to store video files there is a very good chance that power will be lost during file write operations thus corrupting directory
 
However using the SDHC card is the cheapest option.

A more 'robust' solution is to use a USB memory stick = this suffers from the same "power off = directory corruption" risk, but swapping a USB stick is a lot faster than generating a relacement system SDHC card

Use as a Security camera

If you add WiFi capability, when parked in your driveway your Dash-cam can be integrated into your home security system (for as long as the battery back-up lasts).

To avoid the need for a USB hub, you can 'swap out' the USB Memory Stick (video store) for a WiFi 'dongle' when you reach home.
 
To avoid pulling out the Memory stick during video file write operation, an 'eject' button can be fitted

Case

Only the 'Official Raspberry Pi Zero Case' comes with a Camera lid - however this will cost you 2 or 3 times the price of the Pi Zero (and has no room for anything else inside) and I just couldn't stomach being ripped off in 'dollars' for a bit of plastic that I know is made for pennies

Searching eBay did not turn up a Pi Zero case/box with camera lid. Lots of Zero cases can be found, but none have any room inside for anything except the Pi Zero.
 
I did find the "Enclosure Shell Hard Case Support Camera for Raspberry Pi B+/Pi 2/Pi 3 Grey" for £1.98 (post free). It's plenty big enough to take both the camera and a Pi Zero, but the USB socket holes are on the 'short edge', so it would be no good for use with a standard USB hubs (which are 'long sticks' not (dual) 'stack sockets') although it looks as if there might be room for a 'micro-USB to standard USB cable' to be 'coiled up' inside.
 
All the 'standard' i cases are simple just too full of holes - and I wanted something that would keep out dust, direct and 'little fingers'. In the end, I decided to go with my 'Really Useful Box' approach, which has the advantage that I can 'custom cut' holes for whatever access I need.

The case needs to provide a slot for access to the SDHC card (so it can be switched out without needing to 'open the box'), a hole for the power lead, mounting point for an RCA socket (for 'TV out' i.e. direct connection to a display) and mount at least one standard sized USB socket (Memory Stick video store or a WiFi 'dongle') and mount at least one push-button (USB 'eject'). As usual, the Camera module would be bolted to the inside of the lid

The Pi Zero's own 'ACT' (Activity status) LED can be used to provide 'feed-back' (such as 'safe to remove USB device') :-


(-) Controlling the Pi Zero ACT LED


The Pi Zero has one LED, led0 (labeled 'ACT' on the board). The LED drive is 'inverted' so, when it defaults to 'brightness 0' this turns the LED 'on' !
The system software issues a 'trggger' that sets 'brightness 1' (for a short time) during 'disk activity' (i..e during SDHC card access) which turns the LED off.

Needles to say, when running from batteries, wasting XmA on an almost permanently 'on' LED is a luxury we can't afford :-)

You can control, the LED from a CLI / script by removing the 'disk activity' trigger and then 'manually' turning it on/off as follows :-

# Set the Pi Zero ACT LED trigger to 'none'.
echo none | sudo tee /sys/class/leds/led0/trigger

# Turn off the Pi Zero ACT LED.
echo 1 | sudo tee /sys/class/leds/led0/brightness

# Turn on the Pi Zero ACT LED.
echo 0 | sudo tee /sys/class/leds/led0/brightness


To permanently disable the LED, add the following lines to your Pi's /boot/config.txt file and reboot:

# Disable the ACT LED on the Pi Zero.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=on

This note last modified: 4th Jun 2017 15:27.

[top]

The pages in this topic are :-


Next subject :- Pi door bell IP camera

[top]