0

I'm a novice python coder, and even more novice pi user/electronics person. I'm trying to set up an on/off switch on my headless pi with a three-pin arcade switch I found. Right now the switch is plugged into GPIO 16 - GRND - GPIO 12. From googling, I ascertain that I can just write some code to watch for a voltage raise in GPIO 16 or 12 (which one?), and launch a shutdown script thereafter.

Will I fry my board if I plug it in with this switch on the pins? I specifically made sure not to plug it into any 3.3/5v pins, so I think I'm safe, but also don't want to buy a new board.

1 Answer 1

2

The "one button ON-OFF" switch function has been built into the Raspberry Pi device tree since July, 2017. All that's really required is two pieces of wire, but a momentary push-button switch can be added if you wish - perhaps your "three pin switch" can serve in this role?

One Button?

Let me explain in the following schematic what is meant by "one button ON-OFF" function, as there has been some confusion on this point:

schematic

simulate this circuit – Schematic created using CircuitLab

Two items of note:

  1. While no software is required to implement the one-button-ON/OFF feature, the device tree overlay shown below must be added to the file /boot/config.txt:

at the command prompt, open the file for editing:

$ sudo nano /boot/config.txt 

once the file is open, add the following line of text:

dtoverlay=gpio-shutdown,gpio_pin=3
  1. The RPi will cease processing in the "OFF" state, but will continue to draw power. As of this writing, reaching a "ZERO POWER" state for all RPi models may be achieved only by "pulling the plug".

Background

Matthijs Kooijman developed the dtoverlay for gpio-shutdown. His blog post discusses his motivation, and provides some details: "Raspberry pi powerdown and powerup button". If you're interested in the source code for this particular dtoverlay, you can find that here in the RPi GitHub repo.

While the overlay allows the user to specify any GPIO, only GPIO 3 (the default) allows one to shutdown and startup using the same single button. If the user selects a different GPIO, the user may shutdown the RPi, but a startup requires a power cycle - i.e. unplug the power cord & plug it in again. And finally, on the subject of power, know that the RPi will continue to draw power even after the shutdown. The power consumption will be reduced, but not eliminated.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.