2

I've been through tags "power-supply" and "power" of this website and surfing on a lot more but I did not found any answers or information about the subject I'm about to talk about.

So, I'm looking forward to design and implement a solution that will :

1 - detects when the power-supply can't supply anymore (like a power shutdown from the building) and gives a bit to one of RPi's GPIOs.

2 - when detecting (1), having a script to "sudo halt" the Pi.

3 - supply enough power and buy enough time for the Pi shutdown properly

Please find below what HW and OS I have : HW : - RPi rev B - Power supply : 5V - 1500mA - Class 10 SD card, SanDisk 16GBytes - Wifi Dongle (no reference, sticker ran away)

OS : Raspbian (updated, a few packages added)

The main purpose of this is to protect the Pi's SD card from getting corrupted.

The second part of the project is to add a timer (at least the time for the Pi to shutdown) that will block the power-supply (with a relay or MOS-FET transistor) for the Pi to boot again when power will be available again.

I already have a few ideas but none of them seem to be time-resistant.

Here are the questions :

Does a 10 seconds power-supply will get the Pi enough time to "sudo halt" ?

Might a relay on the power input be dangerous for the Pi ?

Thanks for your time, knowledge and help.

Raspberry Pi-ly yours,

TDT

  • What is the question, then? – Krzysztof Adamski Dec 18 '13 at 12:52
  • Oh right... I'll edit it right now. – TDT Dec 18 '13 at 13:06
  • Have you considered a cheap UPS instead of recreating the wheel. – Steve Robillard Dec 18 '13 at 20:55
  • The system won't have any use in case of a power down (it will get its data from internet and a lot more objects in the house). That's why I would like to shut the Pi down, not keeping it on. But it's a good idea for future projects, thank you. – TDT Dec 19 '13 at 9:02
2

Timing question

The answer is unfortunately - no, there is no amount of time that is sufficient for RaspberryPi to halt. The time is not constant and it depends on what packages are installed (each package may add additional shutdown script) and what is happening on the system. It is possible that it will not shutdown cleanly at all. So there is no warranty.

What you can do is to test what is the typical time your system needs to shut down and use this as a reference value, then add some buffer to this.

Relay question

Using relay should not be more dangerous to the Pi than physically disconnecting it from the power and this is actually the only way you can power it off.

As far as I know, the only problem with relays is that there is some energy in the coil which may produce voltage spike in it's circuit. This may be prevented by the diode but this is not always enough (but those are rare cases). This shouldn't be a problem for RaspberryPi, however, since it won't be connected to the coil circuit (it won't be controlling the relay).

Also, if you are going to control AC voltage for the power adapter connected to the Pi instead of 5V connected directly, there is even less concern here - it's much harder to damage power adapter than RapsberryPi.

Please keep in mind that I'm not an electronics expert so I may be missing something in that regards.

Side note

You may be interested in ATXRaspi project. It tries to solve quite similar (but not identical) problem as you. In first revision, it used relay but they had some problems (but not related with damaging RaspberryPi) and started using MOSFET instead.

  • For the shutdown time : Thanks for pointing this out, I'll use this method to dimension my emergency power source. Do you think using a lighter OS (like ArchLinux) could help reduce this delay ? And for the relay, I was worried about the possible impulse that can occure (even with diod protection I was told). – TDT Dec 18 '13 at 13:28
  • 1
    The same thing stands for ArchLinux - all normal distributions share the same solution - each package may add additional startup and shutdown script. I don't suspect their shutdown scripts are significantly faster than in Debian. As for the relay, I updated my question. – Krzysztof Adamski Dec 18 '13 at 13:47
  • OK Krzystof, I'm writing this distributions precision down as a reminder for my future self ! In order to verify your sayings about the relay I'll ask a few people around me and check electronic specialised websites. Again thanks for your help and time. – TDT Dec 18 '13 at 13:53
  • Hi again, In the link below (French language, sorry) I found a card that should allow me to switch to a Lithium battery in case of a power loss. evola.fr/product_info.php/chargeur-lipo-pro-p-187 In case someone has the time to take a quick look at it, may I have your opinion on it ? Thanks again, TDT – TDT Dec 18 '13 at 15:59
0

You can also attach some sort of those USB Battery Packages that allow passthrough when charging the package.

When the power cuts (or I don't know how you call it, English is not my native language) your Pi will continue to run until the Battery is empty (mine can charge my iPhone up to 3 to 4 times max.; 5400mAh capacity)

Obviously you won't get any notification or something to the GPIOs but this is an alternative maybe? of Course if you're tech-savy (don't know how to spell it) in the means of wires etc. You can do something with these things that when the power cuts a device BEFORE the battery pack (or the battery pack itself if it's a "smart"-battery or you make it smart) you get a notification and then shut the Pi down by yourself or something. Don't blame me if it isn't possible, just using my imagination over here

I don't dare to guess how long your Pi will survive on that battery before it's empty, but it depends on the battery capacity

  • HI Shivam, What you depict is the purpose of this card (evola.fr/product_info.php/chargeur-lipo-pro-p-187) but does not suit my needs. The feature I would like to implement is to shutdown the Pi, not able it to survive ;) Also one of the problems with the battery thing is the spoilage (battery looses capacity with time and usage) of the battery. Anyway thanks for your idea and the approx capacity of your battery. – TDT Dec 20 '13 at 13:29
  • I can't help you with that yeah, I just came up with an alternative, but you're welcome! – Subject Dec 20 '13 at 13:34
  • And oh, I forgot. I managed to find the key word for what I needed ! It's called voltage (or power) supervisor. Those are simple and mostly out of the box devices that watch the power supply line. Comes in all size and shapes (and prices), but DC only. – TDT Dec 20 '13 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.