Friday, March 8, 2013

USB Hub Modified to Back Feed Power

Most powered USB hubs will not feed power back into the host system.  This is normally a good thing.  However, it is possible to power the Raspberry Pi by back feeding power from a powered USB hub.
Note:  Doing this bypasses the fuse on the Pi, so it is possible to damage it if too much power is drawn into it.  Since all my peripherals will be connected to the hub and GPIO will not be used, then there is little risk of this occurring.  Another note:  The rev 1 Raspberry Pi boards have fuses on the USB ports.  These will provide some protection but will also reduce the power.  I expect that a typical powered USB hub will have adequate power such that this will not be a problem.

Below is a simple modification to make a USB hub backfeed.  The power connector on the hub I used has +5V on the outside of the barrel, and ground on the inside.  There are three connectors on the power socket - one ground and two power connectors.  When the power plug is inserted then power is drawn from the power supply instead of from the host.  This can be overcome by simply connecting the two power connections on the socket.

Now the 2A power supply for the USB hub will power all of the periperals as well as the Raspberry Pi itself.

I need this much power in order to connect an external hard drive.  The purpose for this system will be described in my next blog post.

Thursday, March 7, 2013

Low Memory Automatic Reboot

Below is my solution to the memory leak problem that I discovered in the frame buffer interface used by my digital picture frame.  My first thought was to simply schedule a reboot at midnight, but the Raspberry Pi has no internal clock.  My picture frame is not connected to the network, so it never really knows what time it is. Also, the low memory system hang may occur in less than 24 hours.

The better solution is to monitor the amount of free system memory and reboot when it gets too low.  I use the /proc file system to access the system memory status, the awk command to pull out the value that I need, and a bash script to tie it all together.

declare -i fmem
while [ true ]
        fmem=` awk '/MemFree/ { print $2 }' /proc/meminfo`
        if [ "$fmem" -lt "10000" ]
                echo FREE MEMORY IS LOW----FORCING REBOOT
        sleep 60

Note that the command that awk runs is surrounded with single quotes.  The entire command is surrounded with back quotes.  This causes the output of the command to be saved in the fmem variable.

This script is run from /etc/rc.local the same way that is run.  When the free system memory drops below 10K, the system will reboot and all is well again for a while.  Now I can just let the picture frame run forever and not worry about it.

I would like to see someone write a real slideshow program that does multiple transition types and supports controls such as pause and reverse.  I have too many more interesting projects on my mind, but maybe someone will find the time to do this.