I desired to create a dash cam due to the terrible driving on Irish roads, the few near misses I have had and the creation of the Raspberry Pi and camera module which place hardware creation within my reach. Also I wanted a real world problem to solve where I could use my software skills and put them to the test. Hopefully I would improve my skills and this would give me confidence in my coding abilities.

Image: Configuration of Dash Cam Version 1. Camera installed internally.
Hardware:
- Raspberry Pi version 1 Model B
- Camera module version 1
- USB drive: Integral 360 4 GB
- Black case
I assembled the Raspberry Pi board with the camera module and installed it into it’s case. I flashed the Raspbian image on to a 4 GB SD card and inserted it into the SD slot on the Raspberry Pi. On the software side I going to use the ‘raspivid‘ program to record the video and store it onto the USB drive.
I decided to write my software in Java as I’ve experience with Java and there was an ARM JVM available. Using Java I wrote a program who’s responsibility was to:
- Read a configuration file
- Generate file names
- Run the raspivid program and supply it with the required configuration options and file names
- Check the created file for it’s size and delete it if was empty
- Repeat running the raspivid program until it’s interrupted usually by a power loss event
I mounted the dash cam in my car and tested it. First problem was I had no idea if the Raspberry Pi was on or if the camera was recording. A few times I had come home to find there where no videos on the USB drive. The causes of this issue were file system mounting problems on the USB drive, loose power connections especially the 12 v lighter socket in my car which can become loose in use and few program bugs in software.
The second issue I found was frame dropping in the video recorded. Sections of elapsed driving time would be missing in the video files. This was no good as important events could be missing e.g. dangerous driving, crashes and collisions. I believe the cause of this my choice of using a JVM for my code which has a sizeable memory footprint on device which has small amount of memory and also CPU time usage.
Third issue when the ignition of the car is turned off power is cut to the dash cam. On viewing the resultant video files I found the last couple of minutes of the last video were missing. The cause of this issue is the operating system buffers writes to the file system before it’s flushed. If the power is cut all the information in the buffer is lost. One solution is to informed the OS to write directly to the file system by adding the option ‘sync’ to the ‘/etc/fstab’ file but this causes I/O performance problems and excessive I/O writes to a write sensitive device, the USB drive. Another solution was needed.
117 views