Monday, April 16, 2018

Carpc project - power supplies

I recently uploaded a new video to show my custom-made carpc based on a Raspberry Pi. In the video, I had to leave a lot of information out for the sake of runtime, so, I decided to write a little series of posts to explore thoughts and ideas about this project.

This episode is about power supplies.

Disclaimer (sort of):
Be aware that this post is not self-contained. If you haven't seen the video, you probably won't get much out of this reading. Also, this is not a tutorial on how to build a carpc like the one I made. For that, I'd need much more time and space. I just want to document the thought process behind a few hardware and software choices, share some techno-ramblings, and provide you with some links to get you started using the components I used.

Have you ever modified your car with custom electronics? Are you planning to hack a Raspberry Pi into a device that was not intended to be modified? Have you ever started a simple project (such as adding music to your car), and somehow turned it into a huge, titanic undertaking?

Power supplies

 

Here's another potential deal breaker of the entire project. The carpc needs power, and the only source of power in the car is the battery. If power were the only issue here, I could do like everyone else and connect the carpc to the cigarette lighter. The issue is that the carpc would turn off abruptly when the engine stops, and that can damage my file system in the long run. I also doubt that the cigarette lighter is regulated, so I expect the voltage to fluctuate wildly around 12V, and spike up to 30V when the engine stops.

Not good.

In the end, I want to achieve four things:
  1. I want the carpc to power on automatically when the engine starts.
  2. I want the carpc to power off gracefully when the engine stops. This means closing all files and resources, and issue a shutdown from the OS, rather than pulling the plug.
  3. I want the carpc to be protected from the wild swings and spikes of the car battery voltage. The Pi should see a clean, regulated 5V at all times.
  4. I want to prevent the carpc from deep-discharging my battery, if I forget it on, or by means of electrical leakage across a long period of inactivity.
Mausberry Circuits' 2A car switch.
I was lucky enough to stumble on the perfect component for my needs: a 2A car switch from Mausberry Circuits. Unfortunately, the part is no longer available on their website, and it has been replaced by more capable units sustaining 3A of current.

The unit is essentially a DC-DC regulator stepping down the 12V DC of the car battery to a 5V DC usable by the Raspberry Pi. The device also contains a pre-programmed microcontroller that monitors the engine ignition line. When the engine starts, the microcontroller activates the regulator and powers on the Pi. The microcontroller communicates to the Pi using two GPIOs. One of them is asserted by the microcontroller when the engine stops. A shell script running on the Pi (provided by Mausberry Circuits) monitors this GPIO, and responds to the signal activation by closing all open files and shutting down the computer in a clean fashion. At that point, the microcontroller starts polling the other GPIO to determine when the Pi has finally shut off, and then disconnect the power entirely. This little board is well designed, and helps in protecting the Raspberry Pi against power surges, and the battery against deep discharges.

The example script provided by Mausberry Circuits simply shuts the Pi off. I modified the script to perform few additional operations. In particular, the script stalls the shutdown and attempts to connect to my own network via WiFi. If successful, it will attempt to synchronize the media USB key with the designated folder in my media server.

This means that I will be able to change the music and videos in my car simply by copying files to a folder in my home media server, and my car will automatically update itself every night when I hit home.

I hope I won't regret rushing to buy the 2A version. By my calculations, the system should burn approximately 1.8A at full steam, including the screen at full brightness. I'll let you know if it works.

UPDATE: It works!

Have fun,
Kradion.

6 comments:

  1. Can you use the 3a switch. Will that work

    ReplyDelete
    Replies
    1. Yes. In my project, the 2A switch is used close to its limit. It would be better to use the 3A switch in this case.

      Delete
  2. Would you be willing to share your code for connecting to home network and updating files on local usb drive with home media server? This is exactly the type of functionality I am looking for but I am not a coder. Thanks for all the info on your blog and video, it was very helpful.

    ReplyDelete
    Replies
    1. Glad you liked the project. Few people asked your question. I moved on to new projects, but if I will revisit this one, I may show this part of the code in a dedicated blog post, an instructable, or similar.

      Delete
  3. Hi Kradion,

    Thanks for your videos. I’m sorry but i don’t understand how to connect car battery to the switch... can you explain it to me ? I’m a rooky in elec :s

    ReplyDelete
  4. Hi I'm following you for a while, but I would like you to make screenshots of the raspberry diet in a please vehicle

    ReplyDelete

Featured posts

Raspberry Pi Bluetooth speakers