I decided to have a second attempt at producing a reliable dash cam. The Raspberry Pi Zero 1.3v was just out and it now had a camera connector. I also picked up the second version of the camera module which was now 8 MP instead of 5 MP. Better video quality and performance I hoped. I dropped Java for my project and decided to try a non-JVM language. I knew some C but my code always ending with those annoying segfaults and I would have to spend fruitless hours trying to find the offending code. I chose the Go language because it seemed easy to learn, had supporting libraries I required, had memory management, small memory footprint and good performance albeit garbage collection which was not going to be an issue as the ‘raspivid’ program did all the heavy lifting and it was written in C.


The ‘raspivid’ program now had the ability to split recording over multiple files with a numbering scheme. I decided not to use this feature and implement my own solution as I wanted flexibility in the video file naming convention and behaviour.
The responsibilities of my Go program would be:
- Fail fast and provide feedback of the failure to the user.
- Read a configuration file.
- Check the file system of the destination for my video files was writable.
- Read the directory containing my previous video files to determine the correct index for file name creation
- Run the raspivid program with the supplied options and file names
- Check the completed video file for size and delete if necessary
- Delete least recently files according to options set in the configuration file
- Repeatedly run the raspivid program unless an error is detected or user/system event interrupts the program
Using the LEDs and resistors I had got in a Camjam Edukit. I soldered on the components using pin 24 for the green LED and pin 18 for the red LED and pin 6 for common ground. I used a go library ‘go-rpio’ to control the GPIO pins on the Raspberry Pi. Diagram for the circuit can be found here. Now I would know if the dash cam was working or not.

I tested my new version of the dash cam in my car. The issue of frame dropping in the dash cam’s recorded video files seemed resolved. Though I found a new issue with file name creation. I was using Linux’s Ext4 directory ordering to order files which I wrongly presumed would be in correct order. I forgot that a file named ‘VID10’ would come before ‘VID2’ in file directory ordering. I fixed this issue by padding the video index number with zeros to the right so ‘VID000010’ would come after ‘VID000009’.
The next feature I want to add is the ability for the dash cam to communicate with my phone to push notifications to and retrieve from the phone the correct time. The raspberry pi zero has no real time clock and in the environment I’m using it the raspberry pi has no access to the internet to retrieve the time via NTP. I want to embed the date and in the video recordings.
95 views