tonylhansen / raspberry-pi-safe-off-switch Goto Github PK
View Code? Open in Web Editor NEWA set of scripts that can be used to provide a "safe power off switch" for a Raspberry Pi.
A set of scripts that can be used to provide a "safe power off switch" for a Raspberry Pi.
Hi, you reference MagPI 52 but it is actually MagPI 42
On a Zero W running Buster I could get this working but it killed my wifi.
Changing the rc.local line of "~pi/shutdown-led-simple.py" to "python /home/pi/shutdown-led-simple.py &" is what it took to get it working again.
I know this is not directly related to your code. Your repo works brilliantly and I have it running on my pi, thank you. However, I initially followed this article by Christian Crawley (2019) which gives the following incorrect instructions:
To ensure this works following a reboot, append /etc/rc.local:
sudo nano /etc/rc.local
In the final line before the exit statement, add:
echo '~pi/shutdown-press-simple.py'
Save and exit as before, then try the button out.
As your repo correctly details, a line should be added to /etc/rc.local before the exit 0
line and this line should be:
~pi/shutdown-press-simple.py &
In the progressive blinking sample, there are some character not recognized as ASCII (½ and ¼) that gives the following error
SyntaxError: Non-ASCII character '\xc2' in file test.py on line 17, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
I would write just "a half second" and "one fourth".
Please see the comment at the bottom of
https://www.raspberrypi.org/magpi/off-switch-raspberry-pi from Aaron Henderson.
The comments suggests that the instructions as the stand will not work if the os is stretch.
Hi @TonyLHansen, using one of your scripts I was able to turn off my Pi 5 in an Arcade cabinet using a toggle switch across pins 5 and 6 but as yet I cannot figure out how to turn it back ok using the same switch (In the opposite direction).
Would you know if this is even possible please?
I realise the Pi 5 now has a power button but as I am moving from a Pi 4 all the hardware is already in place and I was hoping to be able to migrate from the working RPi.GPIO to gpiozero but so far not got it working.
Many thanks.
"
Then add a line to the end of /etc/rc.local to run it at boot time:
$ sudo su
"
I think in the rc.local there should be something like this:
python3 /home/pi/shutdown-press-simple.py &
Because:
I have installed according to instructions, but the Raspberry does not shut down after pressing the button.
Tried to shorten the button pins. No reaction.
shutdown-press-simple.py
Raspberry Pi 3+
2022-09-22-raspios-bullseye-armhf-lite
~ $ ls -l
total 4
-rwxr-xr-x 1 root root 121 Jan 28 11:15 shutdown-press-simple.py
pi@aqua:~ $ python shutdown-press-simple.py
Failed to set wall message, ignoring: Interactive authentication required.
Failed to power off system via logind: Interactive authentication required.
Failed to open initctl fifo: Permission denied
Failed to talk to init daemon.
What could it be?...
sudo python shutdown-press-simple.py
... did the "trick". - Which tells us it is a permissions problem. Must have created the file with sudo in front.
Just changing to create the script without sudo first, did not solve the problem entirely.
Here what works (for me):
´´´
pi@aqua:~ $ ls -l
total 4
-rwxr-xr-x 1 pi pi 124 Jan 28 13:30 shutdown-press-simple.py
´´´
And for me it needs to have "sudo shotdown now" as command for shutting down.
´´´
#!/usr/bin/env python3
from gpiozero import Button
import os
Button(21).wait_for_press()
os.system("sudo shutdown now")
´´´
Hi, I am trying to use your program on ubuntu mate 18.04 with a raspberry pi 3 b. I got the program installed, and when I run the program, and press the button, it says segmentation fault. I am not sure how to fix this. Thanks!
The read.me sould be updated with:
sudo apt install python3-gpiozero
beacuse "headless" image does not contain this package by default.
I know that this tripped me up, and searching around the internet shows I'm not the only one.
The section on editing rc.local is giving terminal commands. NOT the lines that we should be adding to rc.local.
I entered these 2 lines into rc.local and it did not go well.
$ sudo su
Tony,
I've downloaded all of your shutdown scripts and none of them work on a pi3b running raspbian jessi.
Have you been able to get this to work? when I try to run I ge tthe following output:
/shutdown-led-simple.py
Traceback (most recent call last):
File "./shutdown-led-simple.py", line 22, in
btn = Button(offGPIO, hold_time=holdTime)
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 95, in call
self = super(GPIOMeta, cls).call(*args, **kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 292, in init
pin, pull_up, bounce_time, pin_factory=pin_factory
File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 338, in init
super(HoldMixin, self).init(*args, **kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 95, in init
self.pin.when_changed = self._fire_events
File "/usr/lib/python3/dist-packages/gpiozero/pins/init.py", line 388, in
lambda self, value: self._set_when_changed(value),
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 289, in _set_when_changed
self._enable_event_detect()
File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py", line 219, in _enable_event_detect
bouncetime=self._bounce)
RuntimeError: Failed to add edge detection
thanks
Hello! Great information thank you! I wrote my script to look at PIN 3 and my button properly "shutsdown" but reboots the system. I'm hoping to use my button like an on/off where a second button press brings the Pi back to life. Is this possible?
Thanks in advance for your help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.