I need a floating GPIO pin

I am using DFPlayer Mini to create some sound effects in my Halloween props this year. I would like to control it from a Wemos D1 Mini, but time is running short and I can't find a programming solution.

I am currently using buttons on the ADKEY1 pin, and I want the Wemos to simulate those buttons:

schematic dfplayer

This bit of code works fine for pulling ADKEY1 low through a series resistor as do buttons S3 and S4 in the schematic. However,

  digitalWrite(D1, 0);
  delay(100);
  digitalWrite(D1, 1);

digitalWrite(D1, 1); pulls ADKEY1 high and prevents any other button press from working.

I can't think of a way to make the GPIO an active low or floating, so how about using a transistor or MOSFET switch?

My question here is, since the current from ADKEY1 is in nanoamps, would the MOSFET even turn on? If I use a transistor, the Rb calculates to a value in the many megohms. What should I use?

Advice would be appreciated.

Have you tried to make the GPIO go from an output to an input (therefore it will float) ?
You would be emulating an open drain situation.


Have you tried to send the commands using the serial option ?
See time code 7:52

I hadn't thought of that.
So to pulse D1 low, then float, I would use:

pinMode(D1, OUTPUT);
digitalWrite(D1, 0);
delay(100);
pinMode(D1, INPUT);

I will give it a try...

I will revisit the serial I/O again, but the buttons are working now. It's October already, and we have other props to work on. (Halloween is my wife's favorite event and it gives me an excuse to design gadgets, and buy parts, for her props).

Thanks for the pinmode tip.

She has a valid excuse to wear a mask with covid rampant.

This is not the solution you were looking for....

back in the Basic Stamp days......
We would use RC-TIME to make a fake analog to digital converter.

resistor and cap create a frequency.
GPIO pin reads frequency.

Offers a possible way to have multiple buttons on one GPIO pin.

Your tip works. Thanks.

Nothing that simple. She will be dressed as a squire. The theme is a dragon's lair. The prop with sound is a monster box. I have a fog generator inside, plus a mechanism to bounce the lid as if there is something inside trying to escape. There's also a drill motor to twitch the dragon's tail sticking out of the side of the box.

Other props include an egg drop where a momma dragon lays plastic eggs with toys inside. Tomorrow, I have to prepare a fire. A 2-ft diameter wood disk with about 25 flickering LEDs (candle replacements). She will cover them with expanding foam from the hardware store then sprinkle some black and red paint over it.

But, thanks for the tip again. It got me back on schedule.

Sounds like fun stuff, stay safe.

digitalWrite(D1, 0);
pinMode(D1, OUTPUT);
delay(100);
pinMode(D1, INPUT);

Why this sequence?

BTW, I looked more at the control over serial I/O, but there seems to be some issues with softwareSerial on ESP chips.
And with your tip, I can control the two sound effects for my project just paralleling the buttons.

There is a simple hardware solution…. Zero software required.

Three diodes acting as ‘steering diodes’, which allow the 0V state to close the switch, and the diodes block the ‘external’ 5V from feeding into the switch input

1N914 / 1N4148 small silicon diodes would be fine in this role.

The fact that you included the

digitalWrite(D1, 0);

at all, implies the possibility that it was at some time before, written HIGH. If it is HIGH and you set it as OUTPUT, you put the full supply voltage on the pin. Since it appears this is what you are attempting to avoid, you need to set it LOW (also disabling any INPUT_PULLUP) and do that before setting it to OUTPUT.

Once you know the pin is written as LOW - and unless anything might alter it - it is sufficient to use only pinMode to thereafter alternate between OUTPUT and INPUT and back again.

Wouldn't it be easier to just send the serial commands to the player to control it? I just shipped a couple of projects using that DF Player and it's pretty straightforward to control with the AT commands. They also have an arduino library to make it easier.

Yes, but there's two problems.

  1. I am using the Wemos D1 Mini and controlling the props over WiFi using MQTT. From my research, WiFi and the DFPlayer library don't like each other. (Interrupt conflicts).
  2. I haven't seen any example sketches using AT commands on the DFPlayer.
  3. I don't have any more time. The prop already works using the DFPlayer as a stand-alone MP3 player (I only have two SFX tracks), so just putting a GPIO pin across the manual buttons is working just fine. I pull ADKEY1 low for two seconds, and that plays track 1 on a loop. I pull ADKEY1 low through a 3K resistor and track 2 plays. That's all I need for this project.

OK, understood.

Gotcha. Sometimes you just go with what works the quickest :slight_smile:

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