I have a number of Pis running headless and have implemented power buttons for them using this tutorial.
The wake functionality is built in to the Pi as works by shorting GPIO 3 with Ground.
The shutdown functionality is done like this:
#!/usr/bin/env python import RPi.GPIO as GPIO import subprocess GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.wait_for_edge(3, GPIO.FALLING) subprocess.call(['shutdown', '-h', 'now'], shell=False)
The button shorts GPIO 3 with Ground which causes the edge event and triggers a shut down.
I'd like to use the GPIOs on a Wemos D1 mini to toggle this funtionality remotely.
I first tried using a transistor but that didn't work. I suspect that even when no voltage is applied to the base, a small amount of current still leaks through from the collector to the emitter and that was enough to trigger the edge event so the Pi cycled on and off repeatedly, even with no voltage applied to the base.
I discovered that applying a 1k or 10k resistor to GPIO 3 triggers the edge detection.
Are there two pin modes on the D1 mini that I can toggle between to replicate the two states of the physical switch?
I did some experimenting and found that while swiching from INPUT to OUTPUT, LOW did not work, switching from INPUT_PULLUP to OUTPUT, LOW seems to.
My setup is as follows. GPIO 3 on the Pi is set to INPUT_PULLUP. GPIO D5 on the D1 Mini is set to INPUT_PULLUP. A GET request switches the D1 Mini D5 from INPUT_PULLUP to OUTPUT, LOW which triggers the GPIO.wait_for_edge(3, GPIO.FALLING).
Is it OK to keep the two pins shorted most of the time, both set to INPUT_PULLUP?