Tuesday, 3 March 2015

Raspbian setup guide

Initial configuration
For instructions on installing an OS image to your SD card please see here or here.

After Raspbian has been installed login to the Pi from your computer using ssh...
(If you do not have ssh installed then for Windows check here, PuTTY is a popular choice,
else see the main openssh website.)

ssh -l pi {your Pi's IP address}
The default password for the user 'pi' is: raspberry

Run raspi-config
pi@raspberrypi ~ $ sudo raspi-config
(Use arrow keys to navigate. ESC to return. TAB key to move to the bottom line)

- Change User Password (for the 'pi' account) to one of your choosing

- Internationalisation Options -> Change Timezone (set the timezone to your location)
- Enable Camera -> choose <Enable>
- Overclock -> select Medium
- Advanced Options -> select Hostname (choose the desired name for your Pi)
- Advanced Options -> select Update
- Select Expand filesystem (if all of your SD cards space has not been allocated)
Choose <Finish> and reboot (or from the command line: sudo reboot)

Log back in as 'pi' and change the root password

pi@dash ~ $ sudo su -
root@dash:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Update the system
root@dash:~# apt-get update
root@dash:~# apt-get dist-upgrade

Add the camera user
root@dash:~# useradd -m -G video camera
root@dash:~# passwd camera
root@dash:~# su - camera
camera@dash ~ $ mkdir -p front rear sound usb logs/tmp
Change the file permissions so the camera directories are available to all (only needed for SAMBA).
camera@dash ~ $ chmod -R 777 /home/camera
camera@dash ~ $ exit

--- Optional ---
The Pi camera using picam
If you would like to use picamera for recording (which has a nice text overlay facility) we need to
install Python3 and picamera.
root@dash:~# apt-get install python3 python-pip
root@dash:~# pip install picamera
The picamera site has some great examples on programs you can write to use it's different
--- End 

Install and configure motion (primarily for the USB camera)
root@dash:~# apt-get install motion
root@dash:~# vi /etc/motion/motion.conf (an alternative text editor to vi is nano)
The bold variables are required, the others settings are recommended or my defaults.
daemon on
process_id_file /etc/motion/run/motion.pid
width 512         < change to suit your camera
height 288        < change to suit your camera
framerate 12     < change to suit your camera
max_mpeg_time 600
output_all on
output_normal off
ffmpeg_video_codec mpeg4
target_dir /home/camera/rear
movie_filename %Y%m%d%H%M-%v
webcam_port 8080      (required for the GPS text annotation)
control_port 9080        (required for the GPS text annotation)
thread /usr/local/etc/thread1.conf (only needed if you are going to use the included scripts)
root@dash:~# mkdir /etc/motion/run;chown camera /etc/motion/run

GPIO (if you use LEDs or buttons)
root@dash:~# cd
root@dash:~# git clone git://git.drogon.net/wiringPi
root@dash:~# cd wiringPi
root@dash:~/wiringPi# ./build

If you are using a serial GPS remove the ttyAMA0 information from /boot/cmdline.txt
root@dash:~# vi /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
to something like this:-
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Comment out the ttyAMA0 line in /etc/inittab (at the very end of the file).
root@dash:~# vi /etc/inittab
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Install the GPS software
root@dash:~# apt-get install gpsd libgps-dev

SAMBA (if you wish to access the files over a network)
Please see here

Get the scripts like so... (as the root user)
root@dash:~# cd;wget http://dropcanvas.com/u60yw/1 -O scripts.tar
root@dash:~# tar -xf scripts.tar;chown -R 0:0 scripts;rm scripts.tar
A directory called "scripts" in /root should now contain all the required files. The global.rc file
has many values used by these scripts which you can change to best suit your needs.

audio.sh                        - Uses arecord to save audio recordings to the audio directory
dashcam.sh                  - The main startup script. Mounts USB device, rotates logs, disk cleanup etc.
flash                              - C program to flash LEDs as required (GPIO #, count, delay, finish on/off)
global.rc                        - Resource file for all the global variables
gps_logger                    - C program to manage the GPS (via gpsd)
motion_camera.sh        - Runs motion to record video when a USB camera is connected

picam.py                       - Pi camera recording using the picamera package (requires python3)
pivid.sh                         - Pi camera recording using the raspivid command
pwr_butt                        - Monitors (GPIO 2 by default) for a button press

Although the scripts can be used separately the idea is to start them from the dashcam.sh program
and stop them with the pwr_butt program (usually via a button press). You can start one or more
programs using the dashcam.sh script with arguments:
/root/scripts/dashcam.sh pwr_butt pivid
This will start only the pwr_butt and pivid.sh camera recording programs.
N.B. If arguments are used then any global.rc *_enabled settings are ignored.

If no arguments are passed to the dashcam.sh then the defaults of GPS, motion, pivid & pwr_butt are
enabled. These defaults will be overridden by values found in /root/scripts/global.rc followed by the
'usb_directory' root mount point global.rc (if it exists) respectively.

Killing pwr_butt with a SIGUSR1 will stop all running programs and shutdown the Pi.
Using SIGUSR2 will do the same but issue a reboot instead.
E.G. pkill -USR2 pwr_butt (or pkill -SIGUSR2 pwr_butt) will reboot the Pi.
The other scripts will try and exit cleanly if killed with an INT, TERM or USR1

A global.rc file can exist at the root of mounted USB storage. Any variables in this file will take
precedent over the progam defaults and also matching variables found in /root/scripts/global.rc

An easy way to have the dashcam script start automatically from boot up is to add it into the
/etc/rc.local file. 
root@dash:~#  vi /etc/rc.local
/root/scripts/dashcam.sh &

So it looks something like this:-
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"

/root/scripts/dashcam.sh &

exit 0
You can test it works with this command:-
root@dash:~# /etc/init.d/rc.local start

Reboot and (all being well) everything should start when your Pi has booted up.

Other stuff
If you want to disable the Pi camera's LED then add the following to the /boot/config.txt file and reboot.


  1. Hi all. First, Tricky - great work!

    I downloaded the last scripts from the Arch setup guide and the gps_logger stopepd working. For all that have problem on raspbian w/error libgps.so.22 not found:
    1. login as root
    2. cp /usr/lib/arm-linux-gnueabihf/libgps.so.20 /usr/lib/arm-linux-gnueabihf/libgps.so.22
    Then the gps_logger works again - and thanks Tricky w/the GPS data in video.

    Hope this helps,

    1. Thanks for the heads up Pego, I'm glad you found the guide useful.
      A small note I would add is maybe symbolically link the library file instead of making a new copy…
      ln -s /usr/lib/arm-linux-gnueabihf/libgps.so.20.0.0 /usr/lib/arm-linux-gnueabihf/libgps.so.22

      Thanks again and all the best,

    2. Alan,

      I have gotten to the spot in the project where I am trying to add on a USB GPS device and use the included gps_logger script you wrote. I am having the same problem when running the gps_logger script by itself I get the error that it cannot find libgps.so.22. When I browse out to the /usr/lib/arm-linux-gnueabihf directory, I find libgps.so.21.0.0 so I make a symlink from the so.21.0.0 to so.22. After that all I get is a Segmentation fault. I am using a Raspi 3 with Raspian and a gt-730fl-s USB GPS dongle. I have verified that I the PI can read and receive gps data. Any suggestions?


    3. Hi Hoins,

      I have to admit I have been away from this project for a while and I'm not quite sure why gps_logger fails. I did a quick test and also had the same error. I recompiled it and it seems to work now. Can you try this updated version: https://drive.google.com/file/d/0B3C9fv6-yJclU1JyQU5jQlg2a2s


  2. Alan, thanks for the great project. I have put some time and effort in this project and I want to get my camera up and functioning properly. I am a little confused about your instructions, if I want to use the Raspbian system do I only need to follow the instructions on this page (Raspbian setup guide)? Is there any reason to refer back to other instructions from the beginning or in other sections?

    1. Hi Danny, the Raspbian setup page on its own should be enough to get things up and running. It was written after the Arch instal guide and might be slightly abbreviated but hopefully has everything you need. If you are going to use a button or LEDs etc. then please take a look at the 'How to wire up the button….' guide for further info. Let me know how you get on. All the best,

    2. Thanks for the info. When the script dashcam.sh runs will that automatically start all the both of the cameras or do I need to run additional scripts?

    3. The dashcam.sh script by default will start gps_logger, motion_camera (USB camera), pivid (Pi camera using raspivid) & pwr_butt (for the button and LEDs). If for example you only want the Pi and USB cameras and the button to start then you could change the start up in /etc/rc.local to:-
      /root/scripts/dashcam.sh motion pivid pwr_butt &
      or alternatively you can edit the global.rc file and change the settings that have *_enabled to yes or no as desired (using this method pwr_butt will still start too). You can check the changes and see the defaults by running:
      /root/scripts/dashcam.sh -h

  3. Hello again Alan, I thought I had seen some documentation regarding GPS annotation on the videos. Is that something I am missing. I view both the front and rear video and only have a date showing. Also I can only start the rear camera by adding the dashcam.sh script to the /etc/rc.local file. I must start the pivid.sh script separately. Any thing I need to look for? Also on the LED's for some reason the red led does not come on at all. The green one is activated when the script is on and the yellow one blinks when there is activity on the camera.
    Thanks in advance for your help.

    1. Hi Danny,

      GPS annotation will work for the Pi camera if you use the picam script instead of the pivid one. The picam script requires Python3 to be installed. Sorry, it looks like the Raspbian install guide is sadly lacking information here. It should be a case of:-

      apt-get install python3 python-pip
      pip install picamera

      And check that 'camera_method' in /root/scripts/global.rc is set to 'picam'
      You can only use picam or pivid. I wrote picam recently so it's not as robust as pivid but does have better annotation functionality.

      The gps_logger program needs to be running for it's data to be overlaid onto the USB camera video.

      The red LED should come on as soon as power is connected to the Pi as it takes its power directly from the GPIO pin. The green LED should come on when the OS is running (via pwr_butt starting or when gps_logger has a fix). The yellow LED will blink while it is waiting for a GPS fix and will remain on once recording via the Pi camera has begun.

      If you could run dashcam.sh on it's own and in another window check the log file 'status.txt' which is probably under '/home/camera/usb/logs' to see what's starting. If you still have problems maybe you could send me a snippet to hmm.tricky@gmail.com

      Good luck,

  4. hello I am trying to make this work but i haven't been successful. I right now have only two usb cameras and no gps antenna . I went into the global.rc and turned off the pi cameras off and the gps_logger. I run the scrip but nothing happens i checked the log and this is what i got. can you please help me.

    14:27:19 [dashcam] (v2-1.2) Starting up...
    14:27:19 [dashcam]: USB mount disabled in /root/scripts/global.rc
    14:27:19 [dashcam]: Rotating status log files
    14:27:19 [dashcam]: motion:yes - GPS:no - Pi camera:off - power:yes - audio:no - pico:no
    14:27:19 [dashcam]: pwr_butt is already running
    14:27:19 [dashcam]: Starting motion_camera
    14:27:19 [dashcam]: Disk space threshold is set to 95%
    14:27:27 [dashcam]: up 1:07, 3 users, load average: 0,72, 0,61, 0,34, 900Mhz, 50.8'C (50843)
    14:27:28 [dashcam]: Capacity of /home/camera is 86%
    14:27:28 [motion_camera]: Started recording /home/camera/rear/16-01_201604271427
    14:28:28 [dashcam]: up 1:08, 3 users, load average: 1,15, 0,72, 0,39, 900Mhz, 51.4'C (50843)
    14:28:28 [dashcam]: Capacity of /home/camera is 86%
    14:28:43 [dashcam]: Stopped.
    14:28:52 [motion_camera]: motion stopped

    is there a way to check if the cameras are working? and it only says rear camera even thought i doesn record whay doesnt metion front camera. I have two usb cameras pluged in.. another thing i bout this antena would it work? GlobalSat BU-353-S4 USB GPS Receiver

    1. Hi There,

      It looks like it is recording a USB camera and saving the recording into the /home/camera/rear directory correctly. I did a small test using two USB cameras a while ago but I think due to the limitations of the USB transfer on the Pi it did not perform that well. However, I have updated the motion scripts to make it possible to use two USB cameras. Drop me an e-mail (hmm.tricky@gmail.com) and I'll send it to you.

      One way you can check the cameras are working is by running motion directly with daemon mode off. Edit /etc/motion/motion.conf and change daemon from 'on' to 'off'. Then, at the end of the file remove the ';' for each camera, so for two cameras uncomment thread1.conf and thread2.conf. Create those two files and in each one add the information for each camera. For example in thread1.conf add "videodevice /dev/video0" and in thread2.conf add "videodevice /dev/video1". You can also watch the cameras live by adding the information from the "Live Webcam" section into each file (make sure they have different port numbers). When ready run /usr/bin/motion. You should see thread 0 and thread 1 start running. See: http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome for information.
      If you still have troubles let me know and I'll send you examples.

      Regarding the GPS, if it is recognised by the Pi it should work. The device path just needs adding into the global.rc file. Check for it using the lsusb command etc.


  5. thanks Alan I will email you right now so you canhelp me with those updates you mentioned above ,first I want to thank you for your help. I checked the cameras one by one and they both work but not together and only by changing the values in the motion.conf. when i set the parameters in the independent thread1 and 2 it woudnt work it was like it did not exist or did not not read them. In the log [motion camera] only shows the rear camera and only when both thread lines have the semicolon if i take them off the whole thing wont work i wonder what could it be. I will check the link. thank you ,

  6. Hello!

    My name is Cory and I have been fallowing your tutorial. I really appreciate you taking the time to make this. It's an awesome project and idea. I am currently fallowing the steps and everything is going perfectly until I reach the section for 'Install and configure motion'. When I enter the command "root@dash:~# vi /etc/motion/motion.conf " I come to a long text document that I am unsure of how to edit. I am using a Contour Roam2 as my USB camera, so I would like to take advantage of it's 720p or 1080p resolution but I can't seem to be able to change the values in the file. Any help would be awesome!

    1. Hi Cory,

      Glad you like the tutorial. Regarding motion.conf, it contains all the variables and settings which modify the behaviour of the motion daemon. We need to change it slightly for our needs. Edit it using your favourite file editor, for example (as JD mentions below): nano /etc/motion/motion.conf
      Search for the values listed in the blog, for example "daemon" is right at the very top of the file and modify them accordingly. Once done save the file.

      Not sure how well the Pi will cope with a USB camera at 720p or above but let me know how you get on.


    2. Will do! I'm curious because the Contour Roam2 is like the GoPro so it does the video processing onboard (as far as I know).

  7. sudo nano /etc/motion/motion.conf change de values then control x , then yes , then enter

    1. Awesome! Thank you so much. This is my first time using the terminal and I'm not too versed with Linux based OSs. I've learned a lot so far and I see the appeal of it.

  8. I've been getting things going and I've been having a ton of fun doing it! I do have a few problems that I can't quite resolve.

    1) I would like to have the videos saved to my USB instead of the SD card. I have mounted the USB into the Directory.

    2) All of the videos that I have recorded are sped up. Currently, ten seconds of recording leaves me with a four to five second video that is played back really fast.

    3) In the file where my recordings are saved there are 11 videos in avi. and 1663 photos in .jpeg. I am assuming that these photos are stills that are made to make these videos. Am I wrong in this? Is there any way not to save these in order to save disk space?

    and help would be awesome!

  9. Hey Alan,

    I have solved issues number 1 and 3, but for some reason I can not figure out how to slow down my recording. I have been going through the frequently asked questions at:


    It mentions setting 'low_cpu' to on and off but there is no setting like this in the motion file. I've tried playing with frame rates but for some reason the camera is recording at half the frames that Motion is using, so I am getting one second of recording for every two seconds in real time. Have you had any problems like this?

    1. Hi Cory,

      Glad you've managed to resolve some of the issues, but just in case…

      1) The mount point / save directory location can be set in the global.rc file by changing the "usb_directory" variable.

      2) I haven't heard of the low_cpu option before but it is in the FAQ you mention. I tried it in my motion.conf but it was an 'unknown' option. To try and fix the speed issue I would make sure the "ffmpeg_video_codec" is mpeg4, set the frame rate very low, maybe 4 and put the resolution down as low as possible that your camera will support and increase things gradually from there. You could also try different codecs for ffmpeg_video_codec, for example mov although mpeg4 should work fine.

      3) Control the saving of still images by modifying "output_normal" in the motion.conf file. output_normal off
      Disables saving any still images.

      Hope this helps.

  10. Thanks Alan! I will try your suggestions for #2 and let you know how everything turns out. These problems have been great because I have found so much useful information in the search for answers.

  11. Awesome write up. So, do I need to have the buttons wired up before, I can record? So far, I only have one camera hooked up. waiting for the rest to come in the mail. Wondering, logs look good, however, I don't see a video file. I thought everything stared automatically, from what the logs indicate. any help would be greate..

    1. Hi there and thanks!

      Regarding the buttons, you do not need to have them wired up, they are only used for an additional way to power off/on and do shutdown/reboots.
      The dashcam.sh script should start recording straight away but it depends on your start up options and the settings in the global.rc file. At the top of logfile it should give one line showing which programs are being started or you can just run dashcam.sh -h to get a list of the current settings. If you do not have a GPS make sure the "GPS_enabled" variable is set to "no" otherwise it will wait around two minutes before timing out and starting the recording.

      Let me know how you go but if you still have problems please send me some information on your setup.

      All the best,

  12. Good Afternoon,

    Sorry to reply to an old thread but this is an awesome project and I ave just happened to hit a speed bump. I have installed everything ok and cannot see any immeidate issues, until I run ./dashcam.sh

    Nothing happens until I CTRL+C then it says stopping. I have been through the dashcam file and the global.rc and can't see anything that may be precenting the script from running.

    Have you seen this at all?

    1. Some additional info.

      - Raspbian Jessie Pixel latest build and updated.
      - Running on a Pi Zero W
      - U-Blox USB GPS receiver
      - 4gb (for now) USB storage.

      Latest from status.try

      GNU nano 2.2.6 File: status.txt
      21:30:10 [dashcam]: (v2-1.2) Starting up...
      21:30:11 [dashcam]: Mounted /dev/sda1 on /home/camera/usb
      21:30:12 [dashcam]: Rotating status log files
      21:30:12 [dashcam]: motion:off - GPS:yes - Pi camera:picam - power:no - au$21:30:12 [dashcam]: Starting gps_logger 21:30:12 [gps_logger]: Started (v3-0.09)
      21:30:12 [gps_logger]: Rotating GPS log files 21:30:12 [dashcam]: Starting picam
      21:30:14 [gps_logger]: Waiting for GPS fix (mode: 0 , status: 0)
      21:30:16 [dashcam]: Disk space threshold is set to 95% for /home/camera an$21:30:25 [dashcam]: up 3 min, 1 user, load average: 0.30, 0.30, 0.13, 70$21:30:25 [dashcam]: Capacity of /home/camera is 58%, /home/camera/usb is 1%21:31:25 [dashcam]: up 4 min, 1 user, load average: 0.11, 0.24, 0.12, 70$21:31:25 [dashcam]: Capacity of /home/camera is 58%, /home/camera/usb is 1%21:32:25 [dashcam]: up 5 min, 1 user, load average: 0.04, 0.20, 0.11, 70$21:32:25 [dashcam]: Capacity of /home/camera is 58%, /home/camera/usb is 1%21:33:21 [picam]: Timed out waiting for GPS
      21:33:25 [dashcam]: up 6 min, 1 user, load average: 0.01, 0.16, 0.10, 70$21:33:26 [dashcam]: Capacity of /home/camera is 58%, /home/camera/usb is 1%21:34:25 [gps_logger]: GPS logger received signal 2. Closing connection to$21:34:25 [gps_logger]: Finished, exiting. 21:34:27 [dashcam]: Stopped.

      Latest from gps_status.text

      Traveling time: 24815374 minutes. Recording time: 24815374 minutes. Est. d$Average speed: nan mp/h. Highest speed 0.0 mp/h. GPS samples used: 0 / 0. ^--- Ended Tue Mar 7 21:34:25 UTC 2017 ---^

      No other files or logs.

    2. Hi Jonathan,

      Did you update the global.rc file variable "GPS_device" with the device path to you GPS device? If you did and it still does not work then can you try creating (or editing) a file called "/etc/gpsd" and add an entry pointing to your USB GPS device. So it has an entry something like this:-


      It seems that gpsd does not necessarily honour the command line device option when it is started.

      Also, if you want to test the camera recording but do not want to wait for the GPS to start up or timeout then change "GPS_wait" to "no" in the /root/scripts/global.rc file.

      Hope this helps.

    3. Hi Alan,

      Thank you for your reply. I can see the video is now recording but i am still having issue with my GPS device. I think it is because its running on ttyACM0 although with some of the changes I have made the device no longer gets a fix. Not sure why this will be but will require further digging.

      Many Thanks for your help.

      I can now see the GPS data using cat /dev/ttyACM0 however there is no GPS annotation.

    4. Great, if you run gpsmon or cgps does it show the GPS data?

  13. An amazing project been looking at this to tinker and build something nice and waterproof/discreate for my bike.

    To get around the low BUS rate on the USB I'm thinking of using IP camera connections, how easy is it to get motion to use the net_url rather than /dev/video0 path

    1. Thanks Tim. Using an IP camera with motion only requires adding the cameras IP address and path to the video / image feed to the 'netcam_url' variable in motion.conf. For example;


      If you want to use two (or more) cameras you can define individual settings for each camera in separate configuration files (see the end of motion.conf). Motion will then start one thread per camera.

      All the best.