poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Automatic power down

Mon Jan 23, 2017 10:24 am

Hi all, this is my first post and project with pi too, so pls bare with me.
I try to do the project from here http://forum.madeinfr.org/topic/43/raspower/ with has the nice part of shutdown the power entirelly.
The OS is Retropie 4.1.
The hardware is right, i doit and work as expected, but software not so much and the author wont respond, project is too old i guess.
Basically this is a script :
#!/bin/sh

# GPIO numbers should be from this list
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25
GPIO_PIN=4

do_stop () {
# Set up $GPIO_PIN and set to output
echo "$GPIO_PIN" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_PIN/direction
# Set output to high level
echo "1" > /sys/class/gpio/gpio$GPIO_PIN/value
}



case "$1" in
start|restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
do_stop
;;
*)
echo "Usage: $0 stop" >&2
exit 3
;;
esac

I will copy the script to /etc/init.d/ and name it "powersupply" then make it executable:
cp powersupply /etc/init.d/powersupply
chmod 755 /etc/init.d/powersupply
Now i have to "update-rc.d /etc/init.d/powersupply stop 01 0" wich give error update-rc.d cannot read /etc/init.d/ / etc/init.d/powersupply but if i do this "update-rc.d powersupply defaults" then "update-rc.d powersupply stop 01 0" seem ok with no notable errors besides some "inserv " ones wich i get isnt essential but just warnings.
Problem is, as guess, it not work ..
I verify, a K01powersupply process is created, and if i do :
"echo "4" > /sys/class/gpio/export" then "echo "out" > /sys/class/gpio/gpio4/direction" pin is tied to gnd and with "echo "1" > /sys/class/gpio/gpio4/value" pin is up to 3,3v.
Here i give up being over my head, and ask you guys and maybe girls too, whoat is wrong with this script.
Thank you.

poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Re: Automatic power down

Tue Jan 24, 2017 11:11 am

Further advance, maybe someone can figure out:
If i execute the script manually with "sudo ./powersupply" i get :
"sh: echo: I/O error" but pin4 get from undefined voltage (~1,6v) to 3,3v instantly.
Even if i set the GPIO pin "hardcoded", not as a variable, so no problem there..

danjperron
Posts: 2855
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Automatic power down

Tue Jan 24, 2017 12:30 pm

It is possible to set one GPIO to be activate/de-activate on power down.

This what I do with a DC/DC converter and a RTC to power down via a gpio and power up via the rtc interrupt.

It is also in french.
viewtopic.php?p=1074313&sid=fb843bd26b1 ... 5#p1074313

To power it up the first time just ground the transistor base until the computer boot.
If you do a sudo shutdown -h now it will power down. ( if you set the gpio pin )

poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Re: Automatic power down

Tue Jan 24, 2017 12:56 pm

Another try, more compliant :

#! /bin/sh
# /etc/init.d/powersupply

### BEGIN INIT INFO
# Provides: powersupply
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 1 2 3 4 5 6
# Default-Stop: 0
# Short-Description: Simple script
# Description: A simple script .
### END INIT INFO


# GPIO numbers should be from this list
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25
GPIO_PIN=4

do_stop () {
# Set up $GPIO_PIN and set to output
echo "$GPIO_PIN" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_PIN/direction
# Set output to high level
echo "1" > /sys/class/gpio/gpio$GPIO_PIN/value
}



case "$1" in
start|restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
do_stop
;;
*)
echo "Usage: $0 stop" >&2
exit 3
;;
esac

Same result, pin 4 is down, beside
sudo update-rc.d powersupply defaults #give no errors now about insserv
cat sys/class/gpio/gpio4/value #the same, still give error no such file or directory
Running this manually with "sudo ./powersupply stop" raise the pin4 up and give no errors in terminal.
Can anyone help ?

poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Re: Automatic power down

Wed Jan 25, 2017 8:25 am

Thank you for answer danjperron.
The french language wont help me, luckly there is google translate ^^
Now there is a problem with keeping pushing some button a period of time, the "client" of this project is a child, so i would not trust his pushing time precision .. i prefer a standard pushing time <0.5sec.
Besides the pi is in a non standard enclosure so green led is not visibil.

B.Goode
Posts: 5846
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Automatic power down

Wed Jan 25, 2017 9:10 am

sudo update-rc.d powersupply defaults #give no errors now about insserv
cat sys/class/gpio/gpio4/value #the same, still give error no such file or directory
Running this manually with "sudo ./powersupply stop" raise the pin4 up and give no errors in terminal.
Can anyone help ?
So the only error you report in this post is this one:
cat sys/class/gpio/gpio4/value #the same, still give error no such file or directory
Maybe that should be:

Code: Select all

cat /sys/class/gpio/gpio4/value 

poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Re: Automatic power down

Thu Jan 26, 2017 7:25 pm

This was just a typo, actually is "cat /sys/class/gpio/gpio4/value" , and just for fun there is a led on pin4 to see the status of the pin faster.
The actual problem is still up ..

poiu
Posts: 6
Joined: Mon Jan 23, 2017 9:46 am

Re: Automatic power down

Fri Feb 10, 2017 3:19 pm

After some tinkering i decide to go another way, hardware and software, to acomplish same goal, shutdown of the power of pi, but entirelly, prolonging the life of the board, power source, and any periferals connected to it.
The "software" is line
dtoverlay=gpio-poweroff,gpiopin=17,active_low
in /boot/config.txt at the end of file, nothing else.
The hardware act as a temporizated shutdown, this way :
-sudo shutdown now (sudo poweroff) will shutdown the power entirelly 30 sec after the command is issued, so the sdcard will have plenty time to write down whatever he need.
-sudo restart now (or press reset button) will execute flawlessy because the hardware will cut power in 30 sec after gpio pin is down, but cpu will be up and the gpio pin too in 10 sec (at least on pi3 in my case), so the raise of the gpio will override the shutdown process.
The 30 sec time is ease to modify, raise the C1 to 660uF for 60sec or lower the value to 20uF for 20 sec temporization, if needit.
I recomand to use a tantal capacitor, lower losses is important in this circuit.
The hardware is pretty ease to understand, second trigger will light the opto led instantly at the first press of the button "power on" because the C1 is discharged so the lvl is 0 - the output will be 1 (74hc14 is inversor triggerschmitt), so no need to keep press the button for a time as in some designs i see..
The voltage on C1 will raise in 30 sec (conditioned by R1 too and the output of first inversor wich will be 1 because the input is yet at 0) to the lvl enough to flip the trigger and stop the led in optocuplor wich evidently will cut the power totally.
The raise of the voltage on C1 is intrerupted in normal boot process by software, the gpio will switch to 1 so the first trigger will go 0 at output so the C1 will be keeped at 0v.
The project is powered by pi via 3,3V pin, led will drain 10mA and the rest of circuit another 5mA.
From my tests the triac is ambient cold without any cooling or radiator, being the 15-20w power wich is a joke, so all can be build in 2,5x2,5cm pcb (using smd parts offcourse, and respecting the 5mm space between hot and cold part of circuit).
The power on button is connected to hot, so take care of proper isolation, between button and user and between button and the pi too.
Another thing, if power (240vac) is connected of disconnected nothing happend, so no problem if the pi is remote and power flip up and down, the pi will stay powered off.
All this is allready executed and work flawlessy.
As a end note, at this moment is very ease to add a power down button too, just drive the gpio to 0 by another gpio set as input, but for me that is useless.
Thank you all for the help wich get me here.
All we do to see a smile on the face of our child ... i do this for a retropie machine for wich is perfect.
Attachments
power pi3 1.jpg
power pi3 1.jpg (50.84 KiB) Viewed 1002 times

Return to “Other projects”

Who is online

Users browsing this forum: Gencho and 7 guests