Monday, 3 March 2014

The built-in Pi dashcam

Update 12th Oct. 2015: I purchased a UPS PIco which should provide a better automated solution.
Please see here for the install guide.

Or, an alternative to a UPS is this excellent (and cheap) fully automated timer based car ignition
solution made by Ronald M.
                                                                                                                                                                

Initially I made a nice built-in version which had a reset / halt button and an On / Off button to
supply and remove power to the Pi via the 12v - 5v regulator. It worked really well but a little later
I stumbled across a car ignition switch solution which looked ideal, however, it wasn't quite as simple
as I had hoped...
Using a regulated converter
Although the dashcam works well I was a little concerned about the possibility of the power cable
being knocked out and was also getting a little frustrated with having to remove and connect the
cables each time. So I looked to see if I could build it in somewhere. The obvious choice for me was
inside the front interior light housing.

Plenty of space inside!

The parts I used to move the Pi into the light unit were :-
  • A second hand interior light cover
  • An SD card extension cable
  • 30cm CSI flat ribbon cable
  • 1 x on / off push button (with red LED)
  • 1 x momentary button (with blue LED)
  • DC/DC Regulated converter 12V to 5V 3A
  • 1 x Add a circuit piggy back standard blade fuse holder
The interior light unit itself is very basic and has plenty of room so I just transferred the old Pi dashcam
inside the interior light housing. I then fed the white power cable to the fuse box along the roof and
down the left windscreen strut and the cream coloured USB cable for the rear camera up to the roof
via the right strut. The GPS is behind the bottom left black plastic tab in this picture.

I bought this cheap 12v to 5v converter on eBay. It has been very reliable.

I put the Pi inside a case and used insulating tape on any exposed wires before moving the unit into place.

Not too shabby...

The buttons drill holes are 16mm which did not give many options where I could place them but this
is a good enough spot. Later on I removed the USB adapter because it was too visible in my rear view
mirror. At some point I am going to add a flat USB female cable instead. The right (left when in
position) blue momentary button is used for shutdown and rebooting. The left red button is the On /
Off switch and is connected to the converter which goes to the piggy back fuse plugged into my
cigarette lighter fuse slot. In my car this always has power so I use this red push button to remove
power from the converter and hence the Pi. I ordered a car switch from Mausberry Circuits a couple
of weeks ago which hopefully can be used to sense your ignition and shutdown the Pi safely.
If it works as planned the On / Off switch will no longer be required and the Pi dashcam will be
completely autonomous.

The Pi camera is just in front of the sun visor. It is very discrete and difficult to see from outside of the car.

The LEDs on the buttons are powered and controlled by the Pi.

Some issues I have now are that the reflection from the dashboard on the windscreen is picked up by
the camera. The image is also a little more shaky as it's held in place on the roof lining. On the plus
side, the height of the camera gives a much better viewing angle. It is still early days yet and once
things are tweaked a little more I think this will be a really nice setup.

The car ignition switch
Well, I finally received the car switches from Mausberry Circuits (I had to pay €24 customs which
was a bit of a shocker). While I was waiting for them to arrive from the U.S. I had time to prepare
so it really was a case of just swapping out the orginal regulated converter with this new switch.
One power feed needs to be constant, the other power supply needs to be active when the ignition is
switched on. The third connection is the ground. Two more wires from the unit connect to GPIO pins
on the Pi. I modified their supplied script for my setup and updated my pwr_butt program to perform
a shutdown if it receives a SIGUSR1. I also moved the GPS unit further away from the Pi camera to
avoid that pesky interference.

Now when the ignition is switched on the Pi dashcam starts up and when the ignition is switched off
the Pi shuts down gracefully (after a user defined period of time). I have to say I am really happy with
this power switch and the whole Pi dashcam setup is working really well. I'll will update the script list
and try and add some pictures or a demo. video soon.

Update: The morning after installing the car switch I went to start my car, it wouldn't turn over.
The battery had become flat overnight. I am positive I installed the switch correctly but it would
seem the switch was still drawing a large amount of current. Some further testing is needed
but this was somewhat disappointing (not to mention inconvenient).

The car ignition switch workaround (please read the update)
After fairly extensive testing and trying vanilla installs of different Pi OS's on the three switches
I'd bought from mausberry circuits (two micro USB and one USB) all seem to have the same problem.
They correctly shut down the Pi after the ignition is switched off but the regulator / converter
continues to draw full current instead of going into a 'low power' mode which fairly quickly leads
to a flat car battery. Although very unlikely, it is possible I was just unlucky with getting three duff switches.

Anyway, as they partly worked my father though of a possible solution. His idea was to use capacitors
to keep supplying enough power to the mausberry switch (after the ignition has been turned off) so the
Pi can shut down properly and then a transistor to remove power to the mausberry switch completely.

Here is the circuit diagram :-

(The capacitors in the circuit diagram are 3900µF but I have since swapped them for 4700µF)


With the Pi camera, a USB camera, GPS and a USB memory stick all connected I seem to get around
8 - 10 seconds of power to the Pi after the ignition is turned off. This is enough time for the Pi to
gracefully shut down.

Disclaimer
This is still very much a test unit, I accept no responsibility for any damage this may cause to your
Pi, car or physical and/or mental well-being. Once I am happier that it is working (or not) I will add
a better description.

Update:
This solution worked well for a few weeks but when I went to add a new USB cable during testing
by switching the ignition off and on the Pi died. I am not quite sure why but possibly a power spike
frazed something on it. So I would not recommend trying the above capacitor solution. I am now
going back to using my original trusty converter with the reboot and on off switches.

17 comments:

  1. Hi and thank you for this cool website.

    Are there any news to the Mouseberry unit or same problem with the battery drain?

    Another idea would be using the Raspberry UPIS Advanced.

    http://www.pimodules.com/_pdf/UPiS%20Module.pdf

    ReplyDelete
    Replies
    1. Hi Julian, I'm glad you like the website.

      Sadly no real update regarding the Mausberry power switch. Initially they
      responded quickly but they have not been able to resolve the problem.
      I bought three switches and testing the other two in different ways gave the
      same constant battery power drain (this drain is actually higher than if I had
      just left the Pi powered on and recording).

      A friend has offered to see if they can modify the switch or make an alternative
      solution but for now I am sticking with my old regulated converter and the shutdown
      and power-off buttons.

      Thank you for the info. on the UPiS. I had not heard of it before and I really like the
      functionality it provides. I will definitely be taking a further look at this.

      Cheers,
      Alan.

      Delete
  2. How about using a good old mechanical relay in front of regulator? Controlled by ignition power.

    ReplyDelete
  3. How about configuring a GPIO pin to constantly output logic 1 while the Pi is active, wire an OR circuit so if IGN or Pi is ON the circuit stays energized, put a capacitor delay and transistor in the power feed to the regulator. (Note, you don't want an XOR circuit) plus a feed from the IGN to the Pi. When the ignition shuts off, Pi goes to hibernate or power off, just in case there is something slowing the shutdown the circuit waits 10 seconds after the Pi signals to the converter that it's off (GPIO pin assumes logic 0) You switch the ignition on, the OR circuit switches the output on. Use CMOS and you're looking at <10mA standby current.

    ReplyDelete
    Replies
    1. Hi, the last thing I tried was something similar to this. It worked really well for a few weeks but when I went to change some cables and did some testing the Pi died on me. It is possible I may have shorted it somewhere but my electrical knowledge isn't great and I didn't trust my capacitor unit enough. The other thing I missed was being able to leave the camera running while I was away from the car. I am thinking about adding a UPS device which hopefully will give me the best of both.

      Delete
  4. Why not wire it up to the car's switched power? Still have the capacitors in line to provide enough power for the Pi to shutdown gracefully, but even if it doesn't -- that power will stop eventually -- at least you save your battery. Just add enough capacitance to ensure it can consistently shut down.

    ReplyDelete
    Replies
    1. Hi Stephen, that is what I tried and it worked pretty well but some time later (and probably my own fault) I managed to kill my Pi. I went back to the manual push button as it was really no biggy and quite handy if I wanted to leave the cameras running when not in the car.

      Delete
  5. This idea is probably really crazy, but what if you added an arduino into the mix that has an accelerometer and should be able to be on constantly tied to the car battery.

    The arduino could then send power on signal to the Pi if it detects the car has started up, (reads power to your radio?)

    This accelerometer could detect the car is moving and then send signal to pi to start recording. It would then stop recording after 10 minutes that the car has come to a stop as it has stopped receiving a signal from the arduino to keep recording. And then after another X minutes it would tell it to shut down the pi completely.

    You could also code in an onverride button that tells it to record for 10 minutes or a switch that tells it to keep recording until the switch is flipped back off.

    I'm working on a PiLapse project myself where an arduino is controlling a Pi and my my Arduino Pro Mini can run for 7 days on 3000 mAh so you should be able to go a long time with a car battery without making it flat.

    ReplyDelete
    Replies
    1. Sounds interesting but a little too complex a solution for me. I'm going to see if I can use some kind of Pi UPS solution as it may also work well in a portable version. Good with the PiLapse project. All the best.

      Delete
  6. May I suggest an ATXRaspi as power switch and shutdown/reboot controller or MightyBoost if you also need a power backup that can run for a long time (depending on attached LiPo battery that gets charged while power is ON) when power is cut off... this could allow recording after you are parked perhaps, for added security.

    ReplyDelete
    Replies
    1. Thanks Felix, this looks interesting and could be a nice solution. I will look into further. Cheers.

      Delete
  7. Is there a live display with this? how difficult would it be to connect this to an external display and see the video as it is streaming in, i.e. a livened of the car, if I wanted to set these up as blind spot cameras

    ReplyDelete
    Replies
    1. You can easily view live video from the Pi camera by connecting a screen to the Pi's HDMI port. It's also possible to make it opaque to see things behind the video.
      A video feed from the USB camera is harder. It could be done using motion and connecting to the Pi from a web browser. Or by using a streaming application or program like VLC.

      Delete
  8. I do a lot of work with raspberry pi's including opencv, robotics, pi-timolo timelapse, motion tracking etc. I also have dash cam's in my vehicles that I purchased at Amazon.com for $50 USD http://www.amazon.com/Black-Box-Original-Dashboard-Dash/dp/B00FONBG1A/ref=sr_1_12?s=car&ie=UTF8&qid=1459803141&sr=1-12&keywords=dash+cam
    If I tried to duplicate the features using a RPI it would take a lot of effort (not counting the programming) I am very happy with these and would not entertain using a RPI unless I needed to do something more challenging like computer vision or license plate reading etc. In my case I have basic dash cam needs and using a RPI for the job would not be worth my time or effort unless I wanted a hobby project/challenge. But I have better things to tinker with. Here is my Dash Cam YouTube playlist if you are interested
    https://www.youtube.com/playlist?list=PLLXJw_uJtQLagdtWpul9iONw0AbCYpvTP

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. I did not mention these have a good sound recording, built in display screen, gforce sensor, night vision, motion detection, auto start and delayed stop when ignition is turned on/off, good suction cup mounting with little or no windshield reflection. Sorry to sound like I am marketing but I am only a retired guy who likes to tinker on things that are interesting to me. Duplicating the functionality of an inexpensive dash cam is not one of the things I choose to tinker with. BTW I also use these as portable camera's using a small USB power pack that runs unattended for many hours/days. The suction cup mounts on a window and set to motion detect monitor for wildlife like birds, squirrels etc.
      Let me know your comments. I am open minded about these things.

      Delete
    3. I did not mention these have a good sound recording, built in display screen, gforce sensor, night vision, motion detection, auto start and delayed stop when ignition is turned on/off, good suction cup mounting with little or no windshield reflection. Sorry to sound like I am marketing but I am only a retired guy who likes to tinker on things that are interesting to me. Duplicating the functionality of an inexpensive dash cam is not one of the things I choose to tinker with. BTW I also use these as portable camera's using a small USB power pack that runs unattended for many hours/days. The suction cup mounts on a window and set to motion detect monitor for wildlife like birds, squirrels etc.
      Let me know your comments. I am open minded about these things.

      Delete