I am working on a project that utilizes a Raspberry Pi. Everything is going good but I need to make the Pi shutdown when the power cuts out. Our building power cuts out on a timer but it varies from day to day. I have figured out how to use the Arduino to control a pin fro th pi's GPIO header and shutdown the pi. Thats the easy part.
The challenge, is to find away to keep both the Arduino and the Pi on long eough for a proper shut down. I know there is a commercially available PiUPS but it uses six AA batteries and doenst even charge them for the 40 bucks it think I can do it my self.
My theory... both a battery supply and a wall adapter will plug into a power distribution board. A realy of somesort will be held open by the precence of power coming from the wall adapter. When the power cuts out the relay would "flip" and allow current to flow from the battery pack. The current from the battery pack would send a signal to a pin on the arduino telling it to send the signal to the Pi's shutdown pin(designated by the program I run on the Pi), it would also trigger a time delay relay that will cut out after 10 minutes or so severing the batteries connection as well. When power returns the next morning everything resets and the battery pack recharges.
Sounds like you have a pretty good plan going. Instead of waiting 10 minutes to kill the battery pack, you could monitor the UART TX pin on the Pi by setting a digital pin on the arduino as input. If that pin stays low for more than ~200ms, then the Pi's shutdown is completed. That way you could cut power in like 30 seconds instead of 10 minutes.
The Pi can't turn itself back on. There is no "on" switch; it simply starts up whenever power is present.
To the OP, instead of looking for power from the wall outlet I'd focus on the battery voltage alone. When power from the wall is present the battery voltage should stay at a continuous level so you'll know that power is present.
Single-cell lithium chargers and boost circuits are pretty cheap. You just need to add a wall wart and a mosfet for low voltage disconnect. And the Arduino to control everything.
Dalton - the timed relay idea came about because using the Arduino to cut its own power seemed odd, but I follow what your saying and now realize its not that odd at all. 10 minutes is just a number I threw out there because I haven't yet timed how long it takes the pi to shutdown.
TomGeorge - I probably could do this entirely on the Pi but it would require alot more hardware. I am already using up most of my GPIO header. Also the Pi runs a dedicated program and I would need to either integrat the additional code into my program or build a script that runs in the background, can override the script running in the foreground and not effect the performance. Also I plan to use the Pi on some other projects as well and it would be alot more convienent to plug in something that is already goo to go then to figure out each time how to set up the code.
Chagrin- I think I am following you, but i have been burning the midnight oil on this project and my brain is frazzled, would it be to much to ask you to elaborate?
Simplest UPS would be a 12v lead-acid battery charged from a wall-wart that can supply enough power to keep the Arduino and the RPi running.
If the mains power fails neither the Arduino nor the RPi will notice - until the battery is discharged enough so the voltage falls too low. But that won't be allowed to happen.
If you put a diode on the DC line from the charger to the battery (so that the battery cannot back feed to the charger) and if you arrange a voltage divider upstream of the diode a pin on the Arduino can easily test whether there is mains power available. When it detects a failure of mains power it can go into whatever shutdown routine you want.
You could arrange for the Arduino either to go to sleep and wake up when the power comes back on or put it into a low power mode and leave it running if the battery can comfortably cope with a few mA of power drain.
Robin I think you may be describing what I was thinking, only you know what your talking about and I am just learning.
My whole goal is to keep it simple, I started drawing a diagram to help organize my thoughts and all the input you guys are throwing at me, I opened Fritzing to look at the parts library and stumbled on this little GEM, USB LiIon/LiPoly charger [v1.2] : ID 259 : $12.50 : Adafruit Industries, Unique & fun DIY electronics and kits. I think It would be pretty easy to tap into the power status LED and use that to trigger my shutdown. When the device is plugger into wall power the Power light is on, when you unplug it the power light goes on, so by tapping into the Power Status LED, when its on my pin would be help high, when the pin goes low , send the command for shutdown, when it gets plugged back in the Pi should in theory come back on, if not it has this nifty little reset header on it that I can tap into. It pains me to say it but I don't think I even need to have an arduino in the circuit at all. But I know I could count on the forums to get me though....
The Adafruit board has no low voltage disconnect for the battery -- the battery is always connected to the load. There's a question as to what happens when power is lost and the battery is in that almost-dead state. My concern is that once the Pi shuts down the battery voltage will slowly/slightly rise and then cause the Pi to boot again before power is restored. That is why I suggested a mosfet between the battery and boost circuit so that an Arduino can control that low voltage disconnect intelligently.
Also, aside from the thermistor I don't think that Adafruit charger has any advantages over the $2.50 charger I linked earlier. It just has more connectors. Also, you'll still need the boost circuit I linked earlier to bring the 3.7V battery voltage up to 5V.
Chagrin- I'm sorry i didn't realize they where links, You are right its not much different but aside from more connectors it also provides the pass through power making my life that much easier. I figured I would need a booster for the 5v and i think I've come up with a solid plan. Also in the data sheet for the charger it says it has "Low-Dropout Linear Regulator Mode". I didn't think about the pi coming back on once the power level on the battery rose, if i use the mosfet as you suggested It would be Normally Open? so the pi would have to power on and close the gate before it could draw from the battery?
I will remove power indicator LED (if I can't find another connection) and use that to signal my "shutdown pin"
I am not set on these specific items I am going to look around for other alternatives but this is the preliminary...
tell me what you think...
twelch:
Also in the data sheet for the charger it says it has "Low-Dropout Linear Regulator Mode".
That refers to the type of voltage regulator. It's a linear regulator, meaning that its efficiency is (output voltage + dropout voltage) / input voltage. A low-dropout linear regulator has a lower dropout voltage.
it seems like I have two options at this point, go ahead and buy the parts and experiment a little, or buy an ots back ups and try to hack into for a shutdown signal...