Dash Camera with Raspberry Pi Zero W
With Windshield Mount
The small form factor of Raspberry Pi Zero W along with its official cases makes it ideal for many camera based applications, so I thought why not make a dash camera with it for fun.
Raspberry Pi Zero W lacks some key features required to qualify as a true dash camera:
- RTC with battery or GPS for time stamping records: Alternative approach is to do network time sync with WiFi access point in vehicle or in smartphone.
- Accelerometer sensor to automatically trigger/save recording on jerk detection: This can probably be addressed with some complex image processing.
- Wide angle lens with more than 120° field of view: Off the shelf wide angle lens caps are available for picamera module but this needs custom case design.
- Some kind of visual indication: LED or display to indicate dash cam is operating correctly.
All of the above can be implemented on a custom addon board but for now my priority is on evaluating how reliable and practical is a dash cam with Pi.
- Videos are recorded in mp4 container format, on the fly conversion from raw h264 to mp4 is done with ffmpeg.
- Loop recording, for trying out please use high endurance micro SD card, speed class atleast 10, for Full HD recording and playback. How much size? Typical size of a one minute video in 1920x1080p@30fps format is around 120MB (picamera quality parameter=23). Larger the sd card size, longer hours can be stored before overwriting old recordings. I have tested with Sandisk SDSQQND 32GB and LD Car DVR Class 10 32GB micro sd cards and both work fine.
- Video annotation with current date time, temperature, resolution. If Bluetooth GATT server is running then Location (Latitude, Longitude, Heading) and Speed details can be sent from mobile app.
- Web Interface over WiFi.
- Bluetooth GATT Custom Service (Experimental).
Get Source Code
Source code and instructions on how to install this application on your
Raspberry Pi Zero W is available on GitHub public repository:
User interaction with Pi is through web interface allowing easy control from any web browser. Below are the screen shots of Home page and View/Download of existing recordings. More control on how much disk space to use, video format, recording duration, etc. can be configured from the source code.
View/Download Records page
Sample video from dash camera (Pi camera module used here is v1.3, 5MP)
Bluetooth GATT Custom Service
As an alternative to web interface, Generic Attribute Profile (GATT) custom service can be used to synchronize time, get real time notifications on recording status and also stream location and speed information to dash camera. For now there is no mobile app, instead any app that can explore GATT services can be used to connect and test status/control features of dash camera. Below are some screenshots taken on Android phone with nRF Connect Mobile app.
The Dash Camera will appear as RPi DashCam while scanning for bluetooth devices. After connecting to device, from top Overflow Menu (vertical ellipsis) tap Refresh services. Custom service and custom characteristics will appear as Unknowns, most of the characteristics are from bluetooth GATT characteristic specifications, this allows the app to correctly display their values along with units, if applicable. Each characteristic has a Characteristic User Description (CUD) descriptor, reading these descriptors will assist in understanding their purpose.
To read all characteristics in one go and to enable notifications, tap on the client's Overflow Menu and tap Read Characteristics and Enable CCCDs. To control dash camera operations, send a command byte as described in its CUD on Control characteristic, the one with UUID beginning with 19120100-...
To test Location and speed, send byte array 0x150064002aa52407ca736737a00f on Location and Speed Characteristic. This will cause Latitude, Longitude, Speed and Heading details to appear on video annotation text.
Note: Bluetooth/BLE features will get automatically enabled when all software requirements are met on RPi Zero W. Please refer to the README file in git repo.
DashCam Custom Service
Read All Characteristics
Custom Control Characteristic
Write Location and Speed
After a week of field trial:
- Heat: Because of small enclosure there is not much gap between camera module and SoC and it's not feasible to install a heat sink, within some 20 minutes temperature can exceed 82°C at which point CPU frequency throttling begins and app eventually crashes. Current fix: as temperature exceeds a configurable threshold, video resolution is dropped to 1280x720@30fps this causes temperature to drop around 62°C and when temperature falls below another threshold, Full HD resolution is restored.
- Vibrations from road: There is no image stabilization, this causes jerky video on not so nice roads, in long run it may also affect sd card mechanical connector points.
- Stuck on boot: Sometimes Pi doesn't boot and gets stuck at coloured screen, since there is no visual indication you can miss a lot of recording. So better check in between whether web interface is accessible.
- .local address resolution doesn't work on Android phones as there is no support for mDNS/bonjour on Android yet, one way to fix this is to configure WiFi router to allocate fixed IP address to Pi.
- What is Raspberry Pi Zero W↗
- Pi camera documentation↗
- Sometimes Pi doesn't boot↗
- Booting stuck at coloured screen↗
- Since I use nRF51/52 series products from Nordic semiconductors, I prefer nRF Connect for Mobile app↗
- Bluetooth SIG defined GATT Characteristics↗
- Location and Speed GATT Characteristic Format↗