# Fan Shim Button to turn Pi on and off FYI post

**URL:** <https://forums.pimoroni.com/t/fan-shim-button-to-turn-pi-on-and-off-fyi-post/12169>\
**Category:** Discussion\
**Created:** [November 13, 2019, 2:57pm UTC](https://forums.pimoroni.com/t/fan-shim-button-to-turn-pi-on-and-off-fyi-post/12169 "2019-11-13T14:57:14Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![sandman-gamma](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@sandman-gamma](https://forums.pimoroni.com/u/sandman-gamma)\
**Post date:** [April 11, 2020, 10:31pm UTC](https://forums.pimoroni.com/t/fan-shim-button-to-turn-pi-on-and-off-fyi-post/12169/8 "2020-04-11T22:31:55Z")

</div>

![Fan_Shim_Modified](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/c/c940b44684e70244a0d13d36c0aa76245e12df09.jpeg)  
P.S. It looks like the new users like me are limited to 3 messages per post so this would be my last message for now.  
P.P.S. Please see below the Python code for a RPI shutdown. CPU usage next to none. Just save this code into a whatever\_name.py file and execute it. Then hold the fan shim button for 3 seconds and you will get a clean shutdown (make sure to save first whatever other work you have open…just saying ;-) ).

Off topic: I still find the Pimoroni policy of putting a 3 messages limit per post for new users pure BS so how about my own policy: one pimoroni product on my desk is one too many.  
This being said, really nice chatting with you, alphanumeric!

```auto
import RPi.GPIO as GPIO
import os

button_pin = 17
hold_time = 3000 # in ms

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    GPIO.wait_for_edge(button_pin, GPIO.FALLING)
    if GPIO.wait_for_edge(button_pin, GPIO.RISING, timeout=hold_time) is None:
        os.system("sudo shutdown -h now")
```

---

_[View the full topic](https://forums.pimoroni.com/t/fan-shim-button-to-turn-pi-on-and-off-fyi-post/12169)._
