Raspberry Pi GPIO 3 wake function, remote control with Wemos D1 Mini

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?

Do post a complete schematic.

Assuming both the Pi and the WeMOS are connected to power (and at the very least share grounds, but maybe the entire 3.3V power supply) it should be safe to connect the two inputs directly; safer would be to connect them through a 10k resistor.

Thanks. First time drawing a schematic, there isn't much to draw.

The Pi and Wemos are currrently connected to separate supplies, the WeMOS from the power module of a breadboard and the Pi from my laptop's USB port. I suppose I can give them a common ground in their deployed setup. Can you please explain why that is necessary?

I don't think I can put a resistor between them as a resistor seems to pull down the Pi's GPIO 3 and trigger the wait for falling edge.

To complete the circuit.
See also this sticky post.

Thanks, I've read the sticky post.

I don't think I'm passing a signal. And it is working with out a common ground. As I understand it, The WeMOS provides a sink for the voltage of the Pi's GPIO 3 which is being held high, to bring it down to low and trigger the wait for falling edge which is detected by the Pi, not a signal received from the WeMOS.

Is there something wrong with my understanding?

There may be a common ground through your power supplies (if both are e.g. USB from the same computer), or due to stray capacitance you may get some reaction, but you mentioned it's not working well, and your symptoms are typical for lack of a common ground.
In any case, electric stuff only works when there's a circuit.

Ok, I will wire them up with a common ground.

Once that is in place, what are the ideal pin modes for me to toggle between on/off meaning ground and disconnected?

Pin connected to ground = output, low.
pin connected to Vcc = output, high.
Pin disconnected = input.

Thank you very much for your help!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.