NOTE: January 2016, some changes have happened since RaspBMC became OSMC. I am updating these notes mainly for my benefit as I go along, changes or additions are in
REDI'm posting this to give an example of an implementation using Felix's ATXRaspi power controller.
The Brief:An XBMC media player for my caravan, including on board storage and wireless access, plus access to the onboard library via iPad app. Must run on 12V power and be able to support a variety of media formats and outputs. It must also be housed in a neat and reasonable sized case.
Background:
Tests had been carried out using a WDTV Live Hub, but that runs part of my home theatre setup and I did not want to buy a new one. I have previously built a Raspberry Pi based media centre for my outdoor entertainment area, but that was network based only (no onboard storage), was hard wired ethernet and was housed in a large Tupperware container.
I had also used a second Raspberry Pi as a VOIP PBX using Asterisk, so I am quite familiar with them plus I also had one spare left over from my experiment pile.
Parts List:
My nominal budget for this was the price of a WDTV Live Hub, about $220. Using bits I already had and settling for a smaller hard drive I came in a bit below. All prices are Australian dollars and include delivery.
Part | Price |
Non Vented Instrument Case | $20 |
Raspberry Pi | n/a |
300GB USB Drive | n/a |
RJ45 Bulkhead Cable | $4 |
USB Bulkhead Cable | $3 |
HDMI Bulkhead Cable | $7 |
Powered USB Hub | $29 |
Adjustable switch power supply | $6 |
ATXRaspi | $24 |
Nano USB WiFi Adapter | $7 |
SPST Rocker Switch | $2 |
SPST Momentary Push Switch | $5 |
PCB Crimp Sockets | $1 |
Various 2, 3 and 4 pin Header Connectors | $5 |
Small Red LED | n/a |
IR Receiver | $5 |
2.5mm Bulkhead Power Socket | $3 |
12V Power Lead - Fused | $3 |
Media centre IR Remote Control | n/a |
Various Cables | n/a |
Heat Shrink | n/a |
Total so far is $119.
If we then add in the cost of the Pi ($35), the drive (say $50? had it forever and replaced twice over) and the remote ($10) it comes to $214. I did say it came in a "bit" under...
Schematic:
The following schematic concentrates on the power feed and control as we are mainly interested here in how the ATXRaspi is implemented.
An adjustable DC-DC power supply accepts a switched and fused 12V feed and is adjusted using the onboard trimpot for 5V output. This PSU is rated up to 3A output which is more than sufficient to power the ATXRaspi and the powered USB hub. Search eBay for LM2596S to find a range of boards with similar functionality.
The powered USB hub (not shown above) powers up on application of 12V power, this allows the USB disk to power up before turning on the Raspberry Pi. It also powers the nano wifi adapter, I have had problems previously powering these directly from the Raspberry Pi USB ports.
The ATXRaspi is connected as shown in Felix's instruction page, the only other thing to note is the addition of an IR receiver powered by the Raspberry Pi 3.3V supply and connected to the ATXRaspi common ground.
Build Log:
All connections were made using crimped and soldered 0.1" pitch header connectors, or with single crimped and soldered header connectors. A good quality temperature controlled soldering iron makes this easier, too high a heat from cheaper soldering irons can sometimes bend the connecters making them hard to insert into the connector housing.
A cheap $19 crimp tool is another worthwhile investment if you are going to be doing this sort of project work.
All connections were made to the ATXRaspi as per Felix's instructions.
Software was already installed on the Raspberry Pi following again the instruction page. Note that I had to install "make" and "gcc" before executing the "./build" command as shown below, modified from Felix's instructions. This is because RaspBMC is a slim distribution of the Debian OS and did not already have these installed.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git-core
sudo apt-get install make
sudo apt-get install gcc
sudo apt-get install build-essential
git clone git://git.drogon.net/wiringPi
cd wiringPi
./buildPower was applied and the big red button pressed, the Raspberry Pi dutifully powered on.
Testing proved however that pressing the button for 4 seconds did not turn the Pi off. The status led for the ATXRaspi pulsed slowly for a while, then came back on solid. Obviously something was not quite right.
I powered down the Pi manually, then powered up again using the ATXRaspi. I then SSHed into the machine to do a bit of troubleshooting. First to make sure the shutdowncheck script was running I ran the "top" command. shutdowncheck was running but consuming 2.6% of CPU rather than the 0.7% Felix expects. Starting the shutdown sequence using the ATXRaspi caused the shutdowncheck script to crash.
To cut a long story short, the issue was with the cut down Debian distro that RaspBMC uses. The sleep and halt commands were not in the path specified by the script. The lack of the sleep command caused the high CPU usage, as the script was continually looping rather than pausing for .5 seconds each loop. The script was crashing on shutdown because the halt command was not found.
Making some modifications as shown below to the PATH variable brought success. The Pi powered up and down as advertised.
Unfortunately the story doesn't end there. I stupidly decided to enable USB audio in the RaspBMC software which resulted in me finding about a known fault and having to install my software from scratch, using the latest RaspBMC download.
After setting up the script using the modified path statement, the Pi would now shutdown but not power off. My configuration was identical to one that worked earlier that day so I was initially stumped. A quick test with a multimeter showed that even though the Pi had shutdown down under control of shutdowncheck, pin 8 was still high. Huh??
Google came to the rescue and suggested that using halt can leave some processes running even though the system appears shutdown. They suggested using the command "shutdown -h now" instead for a clean shutdown. Knowing the minimum I need about Debian I gave it a try and lo all was working again... Maybe Felix can shed some light.
The final shutdowncheck script is below.
As the link for the Rev 1 ATXRaspi download appears to be broken, create the file by typing the following:
cd ~
nano shutdowncheck
Then paste the following into the file:#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/home/osmc/wiringPi/gpio
echo "ATXRaspi shutdown script starting..."
echo "Asserting pins (7=in,low; 8=out,high)"
gpio -g mode 7 in
gpio -g write 7 0
gpio -g mode 8 out
gpio -g write 8 1
COUNTER=0
#while [ $COUNTER -lt 10 ]; do
while [ 1 ]; do
#echo Looping - counter is $COUNTER
#let COUNTER=COUNTER+1
#sleep 1
if [ "$(/home/osmc/wiringPi/gpio/gpio -g read 7)" = "1" ]; then
echo "PIN7 requested a SYSTEM HALT !"
shutdown -h now
break
fi
sleep 0.5
done
exit 0
Note that this is for RaspBMC based Pis only, stick with Felix's original script unless you have similar problems.
Layout:
Note that there is a fair amount of excess cable for the Hong Kong brand bulkhead connectors, these coil neatly up in the compartment housing the Raspberry Pi, they have been moved for the photos. Also moved out of the way is the hard drive which is attached to the top cover and resides in the space above the power supplies.
"Rear" Panel:
"Front" Panel:
Finished and assembled:
Conclusion:The ATXRaspi turns what was an awkward to use media centre into something my wife is happy using in the caravan. My previous media centre build is permanently connected to a 5V USB power pack locked away in a cupboard. Turning on the 240V supply turns on the Pi, and shutting it off required the use of an Android shutdown app or SSH connecting to the Pi and initiating a shutdown. What normally happened was that I turned it off at the wall, twice so far resulting in a corrupt SD image.
Highly recommended product.