I’m waiting on a TFT Touchscreen to come in for my kaliPi project, so I’m tinkering with my Raspberry Pi Zero W today. I have been wanting a dashcam for a while now, primarily due to the snowbird season incoming. I have seen other dashcams on Amazon but they all come with some less than stellar interfaces, so I figured I’d make my own.
This will be a headless and automated dashcam, meaning it will be powered on and record until shutdown. My first iteration of it will be a video only recording, until I can figure out a way to easily toggle the microphone for when I’m on the phone with clients.
The Parts List:
- Raspberry Pi Zero W (CanaKit Basics)
- Raspberry Pi Camera V2
- 8GB+ Micro SD card (Raspbian Stretch)
- Optional:
Note: I chose to go with the CanaKit Basics due to it including the standard Pi to Zero Camera cable. The basic kit also has a lid that perfectly fits the camera module for a compact solution.
The goal:
The primary focus is for the Pi to act as a dashcam, recording from the time it’s powered on until it’s turned off. My secondary goal is to incorporate GPS and acceleration logging as well. I enjoy visualizing data and it’d be cool to have those metrics. If there is enough processing room after those two goals, I may tack on a wardriving component. It would be one less device I need to carry around with me if I can fit that onto my dashcam.
Dashcam:
We’ll start with preparing our Raspbian image for low power consumption. On your first boot, you’ll need to change Pi’s password, configure SSH to launch on boot, disable HDMI output, disable GUI startup on boot, and tell the on-board wifi to connect to friendly AP’s when in range.
raspi-config
- Change User Password
- Boot Options
- Desktop / CLI -> Console
- Splashscreen -> No
- Interfacing Options
- Camera -> Yes
- SSH -> Yes
- Advanced Options
- Memory Split -> 128
- Finish & Reboot
Disabling HDMI Output
# rc.local is ran on each boot
$ sudo nano /etc/rc.local
# On the line prior to exit 0
/usr/bin/tvservice -o
Adding Wifi Networks
# /etc/wpa_supplicant/wpa_supplicant.conf contains all of our stored networks
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# A standard template looks like
# network={
# ssid="Network name"
# psk="Password"
# key_mgmt=Wifi Type (WPA-PSK, WPA2-PSK,..)
# }
Now that we’ve handled the basics, time to setup a way to control the Pi when we’re on the road. I don’t personally have the ability to hotspot from my cellphone. I’ll link my guide on creating a hotspot from a Pi when it’s uploaded.
The magic of Bluetooth
We’re going to use bluetooth to control our dashcam, it’s a secure way of communicating when no network or console is available.
You’ll need the following app:
Android: Play Store | iOS: App Store
Now we’ll need to enable the bluetooth on the Pi, pair our device with our Pi, and start the daemon for bluetooth terminal.
# Install bluetooth components $ sudo apt-get install bluez python-bluez # Start bluetooth service and connect to the controller $ sudo service bluetooth start $ sudo bluetoothctl [bluetooth]# power on [bluetooth]# discoverable on [bluetooth]# agent on [bluetooth]# scan on # At this point, ensure your device is discoverable and wait for it to show you the device ID in terminal [bluetooth]# pair device_id # Confirm the pins and answer y to the question [bluetooth]# exit # We need to create a new service which relies on bluetooth sudo nano /etc/systemd/system/rfcomm.service
/etc/systemd/system/rfcomm.service
[Unit] Description=RFCOMM service After=bluetooth.service Requires=bluetooth.service [Service] ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a pi [Install] WantedBy=multi-user.target
Now that we have that service, we need to start it to test and then enable it at boot
$ sudo systemctl start rfcomm # Now, in BlueTerm select the Pi to connect to it. If it's working, it should display a bash terminal. We'll enable it at boot now $ sudo systemctl enable rfcomm $ sudo reboot now
At this point, we have a Raspberry Pi that is configured to startup, open a bluetooth terminal, start SSH and disable video output. We need to setup the actual thing we’re trying to accomplish now.. having a video recording that we can later review.
I’m almost done writing that python script and I will post another guide finishing this project.