pssturges
Posts: 7
Joined: Tue Jul 21, 2015 12:03 am

Power management for car audio pi

Tue Jul 21, 2015 7:06 am

This is a project that's been on my mind for several years, but I've never been able to work out how to do it to my satisfaction. I think with a raspberry pi and a couple of accessories I may finally be able to manage it.

I would like to build a headless hires music player for the car with enough hard drive space for all my music. Let's say 1tb. At this stage, I’m not particularly concerned about other aspects often associated with a car pc such as satnav, bluetooth etc, but that may come later. I would like the player to function as much as possible like an 'appliance' and not like a PC. The main road block has been having to shutdown the pc before the engine is switched off then booting up next time i get in the car and select my music/playlist each time. Very cumbersome. I want a simple automated play/pause when stopping/starting the car without the PC draining the car battery in between uses.

So here are my thoughts/plans. Please feel free to poke holes in them. I’d rather iron out as many issues in the planning stage as possible.

Software:
Not particularly important at this time, but I’m considering options such as Volumio, Openelec/Kodi and JRiver Media Center. I can try various options once I have the hardware set up.

PC:
Raspberry Pi 2 Model B

Audio:
Hifiberry or similar DAC connected to the line in/AUX on my existing head unit. Still looking at various DAC options.

Music storage:
1tb laptop hdd (already have a spare) connected via usb to Pi. May need to go through a powered hub.

Music Selection/Control:
Existing iPod touch with appropriate app for chosen software. Will connect to Pi via usb wifi dongle set up as access point on the Pi.

Power Supply and Management:
Here’s where things get complicated. Ideally, what I would like is some sort of power management module that would send a sleep signal to the pi when ‘Acc’ power is turned off. The pi would still be powered by the car battery, but in sleep mode would (hopefully)use a sufficiently small amount of power that car battery would not drain in between drives. Up to about 48hrs should be sufficient for my purposes. When ‘Acc’ power is restored, the module would send a wake signal. A very happy side effect of this set up is that this would produce the pause/play behaviour that I’m looking for.

I have done some searching and found the following 2 modules that may be able to achieve this:
http://spellfoundry.com/products/sleepy-pi/
https://pi.gate.ac.uk/pages/mopi.html

I would love to here from anyone who has experience with them or can recommend any possible alternatives.

Other concerns:
Obviously the power of the wifi dongle and the hdd need to be managed also. I assume they would sleep along with the pi if connected directly via usb. I’m a little concerned about lag time for them to wake and be available when the pi wakes and resumes playing. The hdd may be able to be managed by increasing the music buffer size in software. It may take some time for wifi dongle to come back on-line and the iPod touch to reconnect and then the app to connect to the player. This may not be fatal, but perhaps an annoyance.

So, please let me know if you think this will all work as I hope or if I should go about it another way. I have considered using a rechargeable battery pack. That may still be an option.

Thanks in advance.

pssturges
Posts: 7
Joined: Tue Jul 21, 2015 12:03 am

Re: Power management for car audio pi

Wed Jul 22, 2015 4:38 am

After a little more research, it seems my assumption that the pi even has a sleep/suspend function was incorrect. Certainly makes things more difficult, although it's not quite dead yet.

The Pi 2 B apparently uses about 230mA at idle. Obviously they vary quite widely, but an standard car battery has a capacity in the order of 60Ah. So by my calculations, the car battery could power a pi at idle for 260hours before going flat. Of course, I don't want it to go close to flat, but my target of 48hrs seems to be within reach.

So I think with this in mind, I would need to be able to isolate the hdd and wifi dongle via a powered hub which would be powered off when the ignition is switched off. Does anybody know if a powered hub with devices connected draws any power from the pc when then hub is powered off?

Additionally, there seems to be some tweaks I can perform to reduce power consumption when idle such as disabling graphics (which I don't plan using anyway) and the built in usb hub amongst others.

The question still remains, how to trigger 'pause' and run the power tweak scripts when 'acc' power is lost and also a 'play' and reset the tweaks when 'acc' power is restored.

fruitoftheloom
Posts: 21957
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Power management for car audio pi

Wed Jul 22, 2015 5:12 am

There are several safe shutdown ideas found by googling, also many users have undertaken similar projects:

http://electronics.stackexchange.com/qu ... i-in-a-car


A RPi B+/2B with a 5V2A PSU should be able to power a WiFi Dongle and a 2.5" USB HDD if the USB BUS is increased from 600ma to 1200ma

Code: Select all

max_usb_current=1
https://projects.drogon.net/testing-set ... berry-pi-b


To give a more comlete response the majority of Automotive Projects using a RPi work on the premise of the Ignition Switch being the on/off switch, obviously with a suitable 30-60s shutdown delay.

If you are concerned about SD Card Data corruption then boot the RPi from SD Card but boot the Operating System from the USB Hard Drive.
Retired disgracefully.....
......to an uncomplicated life !

Rather than negativity think outside the box !

pssturges
Posts: 7
Joined: Tue Jul 21, 2015 12:03 am

Re: Power management for car audio pi

Wed Jul 22, 2015 10:59 am

fruitoftheloom wrote:There are several safe shutdown ideas found by googling, also many users have undertaken similar projects:

http://electronics.stackexchange.com/qu ... i-in-a-car


A RPi B+/2B with a 5V2A PSU should be able to power a WiFi Dongle and a 2.5" USB HDD if the USB BUS is increased from 600ma to 1200ma

Code: Select all

max_usb_current=1
https://projects.drogon.net/testing-set ... berry-pi-b


To give a more comlete response the majority of Automotive Projects using a RPi work on the premise of the Ignition Switch being the on/off switch, obviously with a suitable 30-60s shutdown delay.

If you are concerned about SD Card Data corruption then boot the RPi from SD Card but boot the Operating System from the USB Hard Drive.
Thanks for the reply. Most (all) projects that I have been able to find involve shutting down the car pc or pi when the ignition is switched off. This is what I am trying to avoid and instead have the pi run with as little power as possible from the car battery while not in use. That way it is instantly available when returning to the car, i.e. not waiting for boot.

Having said that, some of the clean shutdown solutions may well be able to be adapted for my purposes. Making my own circuits from circuit diagrams is also a little beyond my capability at this stage. I was hoping for a cheap addon module that could just plug in and require a small amount of programming or configuration.

My reasoning for using a powered hub for the wifi and hdd is so that they would be powered off and isolated from the pi when the car is not running, thereby not consuming any battery power.

Good idea about the os being on the hdd. I'll definitely look into that.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Power management for car audio pi

Wed Jul 22, 2015 12:36 pm

pssturges wrote:Most (all) projects that I have been able to find involve shutting down the car pc or pi when the ignition is switched off. This is what I am trying to avoid and instead have the pi run with as little power as possible from the car battery while not in use.
The PI consumes around 0,2A in HALT-state; see no way to avoid this without cutting power? OK, that is not much current for a car-battery, but it is far away from "sleeping mode".
pssturges wrote:That way it is instantly available when returning to the car, i.e. not waiting for boot.
Boot-up-time for an "audio-only-system" should be 10 seconds from "giving power" until "listen music", if well configured ...
pssturges wrote:Making my own circuits from circuit diagrams is also a little beyond my capability at this stage.
Should not be very difficult, 2 or 3 diodes, 2 transistors, a relay, some capacitors, resistors and of course a step-down-circuit (no one should use 7805-regulator-style in 21th century :)) ...
EDIT: Added picture & code
pwr-car.JPG
pwr-car.JPG (19.28 KiB) Viewed 7108 times

Code: Select all

/*
* lpoweroff.c:
* Poweroff if GPIO08 goes to HIGH-level
*/

#include <wiringPi.h>
#include <stdio.h>

int main (void)
{
  int pin_level = 10; // GPIO08 - in original layout and in REV 2
  int del = 500;

  if (wiringPiSetup() == -1) return 1;

  pinMode(pin_level, INPUT);

  for (;;){
    if (digitalRead (pin_level) == 1) {
		delay (del);
		if (digitalRead (pin_level) == 1) system("poweroff");
	}
    delay(del);
  }

  return 0 ;
}
X means any GPIO with LOW in halt-state, will be set HIGH during startup.
GPIO08 detects the power-loss.

Greetings, FM_81
Last edited by FM81 on Thu Jul 23, 2015 10:47 am, edited 1 time in total.
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

pssturges
Posts: 7
Joined: Tue Jul 21, 2015 12:03 am

Re: Power management for car audio pi

Thu Jul 23, 2015 12:12 am

Thanks FM81,
FM81 wrote:The PI consumes around 0,2A in HALT-state; see no way to avoid this without cutting power? OK, that is not much current for a car-battery, but it is far away from "sleeping mode".
Very true, but if it turns out that is sufficiently little to not drain the battery and then be able to start the car after a couple of days this may be acceptable. This HALT state that you speak of, is that something the pi manages itself or is it something that can be configured?
FM81 wrote:]Boot-up-time for an "audio-only-system" should be 10 seconds from "giving power" until "listen music", if well configured ...
Ok, 10 seconds may be acceptable IF the player can be configured to resume playback where it left off prior to shutdown. i.e. mid-song. Not sure I've seen any that can. Obviously power management becomes much easier with this arrangement.
FM81 wrote:Should not be very difficult, 2 or 3 diodes, a relay, a transistor, a relay, some capacitors, resistors and of course a step-down-circuit (no one should use 7805-regulator-style in 21th century :)) ...
Probably still a bit beyond me at this stage, but perhaps with a bit of assistance at build time it may be feasible
FM81 wrote: * lpoweroff.c:
* Poweroff if GPIO08 goes to HIGH-level
*/

#include <wiringPi.h>
#include <stdio.h>

int main (void)
{
int pin_level = 10; // GPIO08 - in original layout and in REV 2
int del = 500;

if (wiringPiSetup() == -1) return 1;

pinMode(pin_level, INPUT);

for (;;){
if (digitalRead (pin_level) == 1) {
delay (del);
if (digitalRead (pin_level) == 1) system("poweroff");
}
delay(del);
}

return 0 ;
}[/code]
X means any GPIO with LOW in halt-state, will be set HIGH during startup.
GPIO08 detects the power-loss.

Greetings, FM_81
I new to the pi and particularly programming for it. In fact some basic shell scripting is about the extent of my programming experience. Where does something like this go? I assume it is started somewhere in the boot routine and runs like a daemon?

Thanks again for you input.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Power management for car audio pi

Thu Jul 23, 2015 9:26 am

pssturges wrote:This HALT state that you speak of, is that something the pi manages itself or is it something that can be configured?
It's the state, the PI reaches after shutdown, when green LED has stopped blinking.
pssturges wrote:Ok, 10 seconds may be acceptable IF the player can be configured to resume playback where it left off prior to shutdown. i.e. mid-song. Not sure I've seen any that can. Obviously power management becomes much easier with this arrangement.
Some weeks ago one member posted a thing called "Juplic", based on MPD (music player deamon). I'm not sure, if it can be configured in this way? Support for "Hifiberry DAC +" seems included; but I didn't know, if for the orignal PCM5102a-based "Hifiberry" too?

My minimzed solution uses also MPD, but without WLAN, I use it at home only, so I need LAN - nothing more. And I need only PCM5102a-support for good analog out. So my approach is different to "Juplic". Think, it will not fit to your needs at the moment, but I plan to adapt it for a car too in future. May be with WLAN ...

What I'd like to say: Any solution with MPD can do this! In MPD-config is defined a state-file, in which the current status is saved at STOP an restored during START.
pssturges wrote:I new to the pi and particularly programming for it. In fact some basic shell scripting is about the extent of my programming experience. Where does something like this go? I assume it is started somewhere in the boot routine and runs like a daemon?
It's C-code. WiringPi is needed for compling. You you have to compile it by:

Code: Select all

gcc lpoweroff.c -lwiringPi
and as root move it to the right place (or with 'sudo', which I didn't like):

Code: Select all

mv a.out /usr/local/sbin/lpoweroff-gpio08-M2
chmod 755 /usr/local/sbin/lpoweroff-gpio08-M2
chown root:root /usr/local/sbin/lpoweroff-gpio08-M2
Code of my INIT-Script '/etc/init.d/gpio':

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          gpio
# Required-Start:
# Required-Stop:
# Should-Start:      glibc
# Default-Start:     S
# Default-Stop:
# Short-Description: Special usage of some GPIO-pins
# Description:       Define some outputs
#                    and set the levels as early as possible
#                    Watch level-changing from LOW to HIGH on GPIO08
#                    for shutdown (binary '/usr/sbin/lpoweroff-gpio08-M2')
### END INIT INFO

PATH=/usr/sbin:/usr/bin:/sbin:/bin

. /lib/lsb/init-functions

GPIO () {
	echo "$1" > /sys/class/gpio/export
	echo "out" > /sys/class/gpio/gpio$1/direction
	echo "$2" > /sys/class/gpio/gpio$1/value
}

case "$1" in
  start|"")
	GPIO 18 1
	log_daemon_msg "From now watching level on GPIO08:" "lpoweroff"
	start-stop-daemon --start --background --exec /usr/local/sbin/lpoweroff-gpio08-M2
	log_end_msg $?
	;;
  *)
	echo "Error: argument '$1' not supported" >&2
	exit 3
	;;
esac

:
For first tests please start the binary manually in a terminal, if it works correct you can activate the INIT-Script by

Code: Select all

update-rc.d gpio start S
Please be aware that with 'system.d' many things will change (For me not to a better thing!), so that all/some described here will not work anymore!

Greetings, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

pssturges
Posts: 7
Joined: Tue Jul 21, 2015 12:03 am

Re: Power management for car audio pi

Thu Jul 23, 2015 10:03 am

Thanks FM81,

Lots of good info here. I had actually just been playing around with MPD on my macbook to try and get a feel for it. One of the great things I discovered was the resume functionality. Puts it right to the top of my list. So I guess my next step is to get hold of a pi and start playing with the likes of volumio and runeaudio.

Thanks again!

tomlubas
Posts: 1
Joined: Sat Aug 15, 2015 6:59 am

Re: Power management for car audio pi

Sat Aug 15, 2015 8:00 am

Hallo this is helpful maybe for you...

https://youtu.be/q0U-tvky5vw

I find it RGB interface..But is very expencive for me.

Return to “Media centres”