I will make these changes available and let you mnow when it is ready for testing.
Thanks
Sam
I will make these changes available and let you mnow when it is ready for testing.
Thanks
Sam
Hi
Hopefully the issue is now addressed with the following commit:
I’d appreciate it if you could test this and provide feedback before we potentially release this as an update to other users. To test this update:
/etc/apt/sources.list
deb http://apt.osmc.tv stretch-devel main
sudo apt-get update && sudo apt-get dist-upgrade && reboot
Please see if the issue is resolved.
I also recommend you edit /etc/apt/sources.list
again and remove the line that you added after updating. This will return you to the normal update channel.
Cheers
Sam
Many thanks,
I’ve reinstall osmc (November 2018) and followed your instructions, so my rPi is running osmc version 4.14.78-4.
Unfortunately, after set the dtoverlay (gpio-shutdown), i’m not able to shutdown as expected the rPi. (GPIO3 & GPIO5 as default => do nothing, GPIO5 & GPIO17 as wished => nothing). I haven’t enough knowledge , but I continue to investigate
If you have any idea or informations, let’s me know many thanks in advance
This will be very difficult for us to debug from a distance.
I think your next step should be to install Raspbian, ideally on a separate SD card if you have one, and see if you can get it to work. If it works, it will at least prove that the firmware you flashed onto the DAC is working and that your hardware is generally ok.
Hi @dillthedog,
I’ve successfully installed the latest version of Rasbian (lite & desktop) and do nothing else except adding these lines to /boot/config.txt & reboot :
dtoverlay=gpio-shutdown:gpio_pin=17,active_low=0
dtoverlay=gpio-poweroff:gpiopin=22
The firmware flashed is working as expected, this confirm that issue is NOT caused by the firmware.
That’s useful information…
As I said, this is very difficult to debug from a distance, since I/we have no easy way to replicate your set-up. Nevertheless, I’ll see if I can find anything that might be missing or configured differently in OSMC.
I understand. If you have a rPI 3 and if you can initiate a shutdown with the regular gpio 5&3 (shunt these pins with a push button and a resistor, no need DAC) then you will probably solve the issue. Else I wish you a lot of courage to compare the both OS :). I really apreciate your helps @dillthedog and @sam_nazarko
What numbering system is this for the pins: BCM?
I do have a Pi3 that I use as a sandbox but won’t have physical access to it until the weekend – and then very little free time . I also don’t have any jumper wires to attach to the GPIO pins (though I guess it’s about time I bought some!)
So unless there’s any way I can emulate over SSH what you’re proposing, I’m afraid physically reproducing it is not going to be possible for a while.
I’m afraid that i’ve made a mistake when namming gpio pin. It’s NOT gpio pin 3 & 5, sorry for that, but it’s gpio pin 5 (BCM 3) and gpio pin 6 (GND) that’s the default behavior for shutdown:
Name: gpio-shutdown
Info: Initiates a shutdown when GPIO pin changes. The given GPIO pin
is configured as an input key that generates KEY_POWER events.
This event is handled by systemd-logind by initiating a
shutdown. Systemd versions older than 225 need an udev rule
enable listening to the input device:ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \ SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \ ATTRS{keys}=="116", TAG+="power-switch" This overlay only handles shutdown. After shutdown, the system can be powered up again by driving GPIO3 low. The default configuration uses GPIO3 with a pullup, so if you connect a button between GPIO3 and GND (pin 5 and 6 on the 40-pin header), you get a shutdown and power-up button.
Load: dtoverlay=gpio-shutdown,=
Params: gpio_pin GPIO pin to trigger on (default 3)active_low When this is 1 (active low), a falling edge generates a key down event and a rising edge generates a key up event. When this is 0 (active high), this is reversed. The default is 1 (active low). gpio_pull Desired pull-up/down state (off, down, up) Default is "up". Note that the default pin (GPIO3) has an external pullup.
Note, in my case i need to replace BCM3 by BCM17 but doesn’t matter for this test
Some progress.
Using WiringPI, with dtoverlay=gpio-shutdown
set in /boot/config.txt, I found that I was able to shutdown Raspbian (4.14.90-v7+) using the command gpio -g mode 3 out
. Without the dtoverlay, it has no effect.
Moving to OSMC (4.14.78-2), I was able to reproduce the same behaviour as above.
With dtoverlay=gpio-shutdown,gpio_pin=17
, running gpio -g mode 3 out
has no effect, but shutdown does work with gpio -g mode 17 out
, so it all appears to work as expected.
Finally, with dtoverlay=gpio-shutdown,gpio_pin=17,active_low=0
, running gpio -g mode 17 out
no longer works, so the active_low=0 part has disabled the shutdown.
So my first suggestion is to see if it works with only dtoverlay=gpio-shutdown,gpio_pin=17
. If not, I’ll investigate further.
Hi and merry christmas 2018 ,
I don’t understand how this can work.
I expect gpio_pin 17 as INPUT but you configure as OUTPUT “gpio -g mode 17 out”. How OSMC can detect somethign with output pin ?
Best wishes,
I assume that it detects a change in the state of the pin. It’s not crashing the system, since this appears in the log when I run the command:
Dec 27 16:44:31 osmc systemd-logind[330]: Power key pressed.
Dec 27 16:44:31 osmc systemd-logind[330]: Powering Off...
Dec 27 16:44:31 osmc systemd-logind[330]: System is powering down.
You haven’t said whether removing active_low=0
or using active_low=1
makes a difference.
As I mentioned, I don’t have any jump wires right now, so can’t test by physically shorting pins. You’ll have to do that yourself to confirm that it works. I’d suggest that you start with the default (BCM 3 → GND) and work up from there.
Hope you enjoy what’s left of the festive holiday!
Update: I came across this thread on GitHub Gpio-shutdown overlay not working on pi 3b or 3b+ · Issue #434 · osmc/osmc · GitHub where it was suggested that Kodi was (still is?) capturing the events and doing nothing with them. What’s the current state of play @sam_nazarko?
@oliv1 What happens if mediacenter is shut down first? Does it then work?
Hi @dillthedog and @sam_nazarko - has there been any progress on this project?
I had previously (before the systemd update) had GPIO shutdown working, but since rebuilding the system, and rc.local not working any more under systemd, I find I’m now stuck as to how to re-engineer it.
My application is a Raspberry Pi Zero (not W) with HiFiBerry DAC installed in a car. To configure it it over ssh I use an Ethernet to USB adaptor.
I have made some analogue circuitry to pull down a GPIO pin about 1 minute after the ignition key is removed (to cater for stalling / re starting the engine). Then a second timer turns off the 5V power supply after 4 minutes to save the car battery, but allowing plenty of time for the Pi to shut down after the first 1 minute timer. (I found this circuitry a lot more straightforward to figure out than the software minefield!)
We have a very long car journey coming up soon, the OSMC install really makes this possible by entertaining the kids, for parts of the journey, but I can’t see that I’m going to succeed in time for this trip. (I jut purchased a new OSMC remote for this as my eldest lost the last OSMC remote on our last trip to France… grrr…)
ANY help is really really appreciated… I really hope I can get this working in time…
Many thanks… Scott.
Please see the update to my previous post regarding Kodi possibly capturing the events. Does it work when mediacenter is shut down?
Hi,
I’d been trying to get it working using the python3-gpiozero or python-gpiozero libraries, as there are many tutorials online for this method, but it seems I can’t install either of them using apt-get.
That’s when I found this thread, but I think i need to learn some of the basics of how this overlay method works, as I’ve stumbled into it at this debug stage. How do I install / activate this method?
Only thing I’ve had working when it’s shut down is the processor reset button which wakes it up.
Cheers, Scott
Well, tonight has been a world of pain of dependencies etc… and still I have failed.
Thanks @dillthedog for the tip about pip, that is where I needed to go.
In progressing down this route, I found the following:
gpiozero relies on RPi-GPIO.
RPi-GPIO relies on wheel, and once wheel is installed, still fails to install PRi-GPIO on the next dependency:
I then find I can’t just install arm-linux-gnueabihf-gcc either without a million other dependencies.
There’s got to be a better way, this has been a horrid experience.
All the systemd stuff of calling the python script with a unit file was straightforward, and seemed to want to work, but can’t as RPi-GPIO can’t easily be installed.
I even installed python-dev and setuptools as another shot in the dark, but still no joy.
osmc@osmc:~$ sudo pip install RPi.GPIO
Collecting RPi.GPIO
Using cached https://files.pythonhosted.org/packages/af/2f/407b6e4cc8a0bdf434825a160bba1807991886b63cce16a5f1a6e1f24cdf/RPi.GPIO-0.6.5.tar.gz
Building wheels for collected packages: RPi.GPIO
Running setup.py bdist_wheel for RPi.GPIO ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-J014FR/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpa0132xpip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
creating build/lib.linux-armv6l-2.7/RPi
copying RPi/__init__.py -> build/lib.linux-armv6l-2.7/RPi
creating build/lib.linux-armv6l-2.7/RPi/GPIO
copying RPi/GPIO/__init__.py -> build/lib.linux-armv6l-2.7/RPi/GPIO
running build_ext
building 'RPi._GPIO' extension
creating build/temp.linux-armv6l-2.7
creating build/temp.linux-armv6l-2.7/source
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-Ub3vap/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv6l-2.7/source/py_gpio.o
unable to execute 'arm-linux-gnueabihf-gcc': No such file or directory
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for RPi.GPIO
Running setup.py clean for RPi.GPIO
Failed to build RPi.GPIO
Installing collected packages: RPi.GPIO
Running setup.py install for RPi.GPIO ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-J014FR/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-4xuK6b-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
creating build/lib.linux-armv6l-2.7/RPi
copying RPi/__init__.py -> build/lib.linux-armv6l-2.7/RPi
creating build/lib.linux-armv6l-2.7/RPi/GPIO
copying RPi/GPIO/__init__.py -> build/lib.linux-armv6l-2.7/RPi/GPIO
running build_ext
building 'RPi._GPIO' extension
creating build/temp.linux-armv6l-2.7
creating build/temp.linux-armv6l-2.7/source
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-Ub3vap/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv6l-2.7/source/py_gpio.o
unable to execute 'arm-linux-gnueabihf-gcc': No such file or directory
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-J014FR/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-4xuK6b-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-J014FR/RPi.GPIO/
Giving up now, as sleep is required, but if @sam_nazarko or @oliv1 have any ideas too, please do suggest them.
I did start making a web page guide on how to do thihs… was just noting down my actions as I went along… had to go back to the top when I ran into the GPIO nonsense, but it may show you the hoops I jumpsed through to get ti close to working before I gave up:
http://scottbouch.com/osmc-gpio-guide.htm
Cheers, Scott.
Thanks @sam_nazarko that seemed to work to enable me to use pip to install rpi.gpio.
As it was all in lowercase letters I changed the python script to call in lowercase too, but still it claims:
osmc@osmc:~$ sudo systemctl status power-off-pi.service
* power-off-pi.service - Power Off Pi Service
Loaded: loaded (/lib/systemd/system/power-off-pi.service; enabled; vendor pre
Active: failed (Result: exit-code) since Wed 2019-04-10 06:59:21 BST; 21s ago
Process: 361 ExecStart=/usr/bin/python /home/osmc/power-off-pi.py (code=exited
Main PID: 361 (code=exited, status=1/FAILURE)
Apr 10 06:59:15 osmc systemd[1]: Started Power Off Pi Service.
Apr 10 06:59:21 osmc python[361]: Traceback (most recent call last):
Apr 10 06:59:21 osmc python[361]: File "/home/osmc/power-off-pi.py", line 7, i
Apr 10 06:59:21 osmc python[361]: import rpi.gpio as GPIO
Apr 10 06:59:21 osmc python[361]: ImportError: No module named rpi.gpio
Apr 10 06:59:21 osmc systemd[1]: power-off-pi.service: Main process exited, code
Apr 10 06:59:21 osmc systemd[1]: power-off-pi.service: Unit entered failed state
Apr 10 06:59:21 osmc systemd[1]: power-off-pi.service: Failed with result 'exit-
lines 1-14/14 (END)
So I tried it again as RPi.GPIO:
osmc@osmc:~$ sudo systemctl status power-off-pi.service
* power-off-pi.service - Power Off Pi Service
Loaded: loaded (/lib/systemd/system/power-off-pi.service; enabled; vendor preset: enabl
Active: failed (Result: exit-code) since Wed 2019-04-10 07:04:12 BST; 2min 0s ago
Process: 346 ExecStart=/usr/bin/python /home/osmc/power-off-pi.py (code=exited, status=1
Main PID: 346 (code=exited, status=1/FAILURE)
Apr 10 07:04:11 osmc systemd[1]: Started Power Off Pi Service.
Apr 10 07:04:12 osmc python[346]: Traceback (most recent call last):
Apr 10 07:04:12 osmc python[346]: File "/home/osmc/power-off-pi.py", line 7, in <module>
Apr 10 07:04:12 osmc python[346]: import RPi.GPIO as GPIO
Apr 10 07:04:12 osmc python[346]: ImportError: No module named RPi.GPIO
Apr 10 07:04:12 osmc systemd[1]: power-off-pi.service: Main process exited, code=exited, s
Apr 10 07:04:12 osmc systemd[1]: power-off-pi.service: Unit entered failed state.
Apr 10 07:04:12 osmc systemd[1]: power-off-pi.service: Failed with result 'exit-code'.
Such a shame, thought we were so close with that last tip!
The python script is exactly as per here: https://www.instructables.com/id/Simple-Raspberry-Pi-Shutdown-Button/ apart from I’m using GPIO pin BCM 22.
Cheers, Scott.