RPi Timed UPS - No more corrupt cards from power failure! - Raspberry Pi Forums
would feedback on - might change, add or remove.
run raspberry pi nas, websever or whatever worry free power issues?
how ups has settable timer safely shut down if power isn't returned in time.
in design stage far. here's how works...
17 volt supply used power entire system , keep 9.6 volt 2200mah battery monitored via max712 smart charging ic power pass through. ptn78020wah 5 volt 6 amp regulator module powers board , 2 raspberry pi's. attiny26 avr microcontroller runs show. 20x2 lcd displays battery percentage , minutes set timer.
when power goes out selectable timer starts (from 5 minutes hour). lcd displays battery life , shows count down of timer. if power returned before timer expires, lcd resets , pi happily runs along if nothing happened. otherwise avr triggers opto-coupled (isolated) switch between gpio 3 , ground (pins 5 & 6) initiate bit of code on pi shuts down pi safely. in 20 seconds, power cut pi , batteries preserving them until power restored.
when power returned, pi powers , batteries begin charging process , happy no micro sd cards harmed day.
how safe shutdown via gpio:
create folder called gpio3 in /home/pi directory.
copy shutdown5.sh gpio3
in gpio3 folder, create folder called shutdown5
copy shutdown5.py shutdown5 folder
in terminal, type following , enter:
cd /home
cd pi
cd gpio3
cd shutdown5
chmod 755 shutdown5.py
cd ..
chmod 755 shutdown5.sh
sudo cp shutdown5.sh /etc/init.d
sudo /etc/init.d/shutdown5.sh start
service should running.
can check status this:
/etc/init.d/shutdown5.sh status
can stop service with:
sudo /etc/init.d/shutdown5.sh stop
autorun on start-up type:
sudo update-rc.d shutdown5.sh defaults
ground pin 5 (gpio 3) pin 6 (gnd) , pi safely shutdown. great headless units running nas, web server or want corruption free.
_____________________________
shutdown5.sh contents
_____________________________
_____________________________
shutdown5.py contents
_____________________________
run raspberry pi nas, websever or whatever worry free power issues?
how ups has settable timer safely shut down if power isn't returned in time.
in design stage far. here's how works...
17 volt supply used power entire system , keep 9.6 volt 2200mah battery monitored via max712 smart charging ic power pass through. ptn78020wah 5 volt 6 amp regulator module powers board , 2 raspberry pi's. attiny26 avr microcontroller runs show. 20x2 lcd displays battery percentage , minutes set timer.
when power goes out selectable timer starts (from 5 minutes hour). lcd displays battery life , shows count down of timer. if power returned before timer expires, lcd resets , pi happily runs along if nothing happened. otherwise avr triggers opto-coupled (isolated) switch between gpio 3 , ground (pins 5 & 6) initiate bit of code on pi shuts down pi safely. in 20 seconds, power cut pi , batteries preserving them until power restored.
when power returned, pi powers , batteries begin charging process , happy no micro sd cards harmed day.
how safe shutdown via gpio:
create folder called gpio3 in /home/pi directory.
copy shutdown5.sh gpio3
in gpio3 folder, create folder called shutdown5
copy shutdown5.py shutdown5 folder
in terminal, type following , enter:
cd /home
cd pi
cd gpio3
cd shutdown5
chmod 755 shutdown5.py
cd ..
chmod 755 shutdown5.sh
sudo cp shutdown5.sh /etc/init.d
sudo /etc/init.d/shutdown5.sh start
service should running.
can check status this:
/etc/init.d/shutdown5.sh status
can stop service with:
sudo /etc/init.d/shutdown5.sh stop
autorun on start-up type:
sudo update-rc.d shutdown5.sh defaults
ground pin 5 (gpio 3) pin 6 (gnd) , pi safely shutdown. great headless units running nas, web server or want corruption free.
_____________________________
shutdown5.sh contents
_____________________________
code: select all
#!/bin/sh ### begin init info # provides: shutdown5 # required-start: $remote_fs $syslog # required-stop: $remote_fs $syslog # default-start: 2 3 4 5 # default-stop: 0 1 6 # short-description: safe shutdown operation # description: shorting gpio 3 (pin 5) gnd, pi perform safe shutdown. ### end init info # change next 3 lines suit install script , want call dir=/home/pi/gpio3/shutdown5 daemon=$dir/shutdown5.py daemon_name=shutdown5 # next line determines user script runs as. # root not recommended necessary if using raspberry pi gpio python. daemon_user=root # process id of script when runs stored here: pidfile=/var/run/$daemon_name.pid . /lib/lsb/init-functions do_start () { log_daemon_msg "starting system $daemon_name daemon" start-stop-daemon --start --background --pidfile $pidfile --make-pidfile --user $daemon_user $ log_end_msg $? } do_stop () { log_daemon_msg "stopping system $daemon_name daemon" start-stop-daemon --stop --pidfile $pidfile --retry 10 log_end_msg $? } case "$1" in start|stop) do_${1} ;; restart|reload|force-reload) do_stop do_start ;; status) status_of_proc "$daemon_name" "$daemon" && exit 0 || exit $? ;; *) echo "usage: /etc/init.d/$daemon_name {start|stop|restart|status}" exit 1 ;; esac exit 0
shutdown5.py contents
_____________________________
code: select all
#!/usr/bin/env python2.7 # script alex eames h t t p ://raspi.tv/ # h t t p ://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio import subprocess import rpi.gpio gpio gpio.setmode(gpio.bcm) # gpio 3 (pin 5) set input. pulled stop false signals gpio.setup(3, gpio.in, pull_up_down=gpio.pud_up) # program nothing until signal on port 3 # starts fall towards zero. why used pullup # keep signal high , prevent false interrupt try: gpio.wait_for_edge(3, gpio.falling) subprocess.call(['shutdown -h "system halted gpio action"'], shell=true) except keyboardinterrupt: gpio.cleanup() # clean gpio on ctrl+c exit gpio.cleanup() # clean gpio on normal exit
raspberrypi
Comments
Post a Comment