PiUser69
Posts: 2
Joined: Sat Jul 06, 2019 2:53 am

Could I use python to shut down the Pi when pushing the button on the Fan Shim on Rpi4?

Sat Jul 06, 2019 2:58 am

There is a button on the fan shim and I’d like to program it to shut down the unit when pushed

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Could I use python to shut down the Pi when pushing the button on the Fan Shim on Rpi4?

Sat Jul 06, 2019 4:01 pm

Short answer: yes.

There is a discussion @pimoroni about pin assignment: https://forums.pimoroni.com/t/fan-shim- ... held/10784
and also some GPIO library updates needed to switch the pullup/down correctly on pi4.
In github, there are some examples, also for the button.
https://github.com/pimoroni/fanshim-python/tree/master/

Last, looking around on how to shutdown pi from python. One example is https://www.raspberrypi.org/forums/view ... p?t=133665
Last edited by ghp on Sat Jul 06, 2019 4:02 pm, edited 1 time in total.

PiUser69
Posts: 2
Joined: Sat Jul 06, 2019 2:53 am

Re: Could I use python to shut down the Pi when pushing the button on the Fan Shim on Rpi4?

Sat Jul 06, 2019 4:01 pm

Example: here is the code for the button press from the readme

@fanshim.on_press()
def button_pressed():
print("The button has been pressed!")

Could I just replace the print with <sudo shutdown> and then it will shutdown the pi?

Return to “Python”