OpenMarine

Full Version: How to safe-shutdown a RPI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all,

I'm looking for some guidance to find a valid solution for the a safe-shudown. Using the main electric board I can switch-on the RPI with no issue. As you understand the other way is not safe as it just cut the main power. Unfortunately, the main electric board switches are old and don't offer control to connect to a GPIO, or I did not understand it. I found a few HAT that allows via a watchdog to safely shutdown the RPI (PIJuice, PIVoyager, Zero2Go) but not sure if it is the best approach. Physical buttons on the RPI are not helpful as the RPI is not easily accessible.


How do you guys did it?

My current setup include the following:
- step-down 12v-5v 10A
- RPI4B
- Seatalk1
I use 2 x buck converters, 2x diodes, a resistor and a relay board.  

with a connection to both the constant 12v and the switched 12v from the 'main electric board'.  
[attachment=1372]

When the switched power is on the 3.3V board and the 5V board get power, once the Pi has booted GPIO Pin 40 becomes 3.3V and trips the relay.  This makes the 5V board connected to both switched and constant power.

when the switched power is turned off, the 3.3V supply goes to zero, but the 5V supply remains powered.  the 3.3V board being unpowered is sensed at pin38 and this causes the Pi to shutdown, once down Pin 40 is de-energised and the relay released uncoupling the power

cost of the parts is about $10, there are 2 lines of code needed to be added

video demonstration below: 

https://youtu.be/45IxpEa0ZcM
Why hardware? If you have remote access to the RPi using a keyboard, you can shutdown using the GUI or command line.
(2021-03-10, 01:59 AM)EarlWer Wrote: [ -> ]Why hardware? If you have remote access to the RPi using a keyboard, you can shutdown using the GUI or command line.

because breakers 'accidently' get switched off by well intentioned crew members or in the heat of moment when trying to exit the boat. this just ensures there are no corrupt SD cards
Question: what about a USB connected SSD? It could be corrupted but could it also be damaged or even destroyed?
I made the shutdown circuit like this. Also, a script is monitoring the "halt pin" status and shut down RPi when the power switch is OFF (and "halt pin" goes down to 0)
After the power switch turns OFF, the power is still ON for about 1 min, enough time for RPi to safe halt

[attachment=1396]

Of course, the power regulator can be a different one, i used this for an RPi0w
(2021-03-16, 01:19 PM)sebba Wrote: [ -> ]I made the shutdown circuit like this. Also, a script is monitoring the "halt pin" status and shut down RPi when the power switch is OFF (and "halt pin" goes down to 0)
After the power switch turns OFF, the power is still ON for about 1 min, enough time for RPi to safe halt



Of course, the power regulator can be a different one, i used this for an RPi0w

Good idea!  I like the way you have used a Capacitor to trigger a transistor to keep the permanent 12V hot until the Pi is down, well until Capacitor is drained
Thanks
Yeah, I think this is the simplest way to have a safe shutdown.
Of course, it require pi to halt in less than 1 min, but this should be fine in most cases.

LE: I made an annotation mistake in diagram: R5 should be 100k and R6 to be 22k.
Yes, I thought your voltage divider was backwards.

I used a second Power supply instead of a voltage divider because I was a little worried about the variation on the 12v line. With your voltage divider you get 2.1v at 12v and 2.6v at 14.5 - does that work? Is that enough for the Pi to see it as high/low?
yes, it is! u can also add a 3v3 zenner diode there, even recommended, for more safety
Pages: 1 2