Wemos D1 clone: digitalRead is unreliable

Sorry, I don't get it. I have literally any cable and any component that I have here on my table also in the schematics. There's nothing more. If you are of the opinion that there must be something missing, then that might be part of the problem.

That's the black wiring going from the ESC to the G (short for Ground) of the Wemos and to the right sides of the buttons.

That are the two lines going from the DC power supply to the ESC. It's actually even labeled with 5.5V.

3 x 1.5V AA Batteries (Alkaline) chained to provide 4.5V

As I wrote, the power supply can output up to 5A so that should not be a problem.

I've added some Serial.prints. Perhaps you can see if the WeMos is "biffing" or the ESC has a problem, some interaction.
Running it here, at start it sends 90s till Up or Down gets ticked Low, then it stays 0's or 180's till there's a U/D change.

void loop()
{
  int readD3 = digitalRead(upperPin);
  delay(1);
  int readD4 = digitalRead(lowerPin);
  delay(1);

  int isFullUp = readD3 == LOW;
  int isFullDown = readD4 == LOW;

  Serial.print(isFullUp);
  Serial.print("  ");
  Serial.print(isFullDown);
  Serial.print("  ");
  
  if (isFullUp && isFullDown)
  {
    //should never happen - more of an emergency stop
    value = 90;
  }
  else if (isFullDown)
  {
    value = 180;
  }
  else if (isFullUp)
  {
    value = 0;
  }
  myservo.write(value);
  Serial.println(value);
}

Here's the log:
log.pdf (100.9 KB)

(I only pushed the upper button once and didn't touch anything afterwards. I marked it in the log)

You pressed pushbutton only once.
It IS changing states and output results.
noted on pages 5, 13, 17, 19

It was suggested, but have you tried going with INPUT (cf. INPUT_PULLUP) and using pullup resistors? (2kΩ?)
And that doesn't pose a boot state conflict with GPIO0,2

Yep, maybe I should've explicitly mentioned that before: The reason for the direction change of the motor is a (falsely) noticed push of the button. The question is: what is causing it and how I can fix it? It looks like it has sth. to do with the power supply, because with a battery instead of the DC power adapter it works fine, so it seems the adapter is causing any kind of interference signal that the Wemos pin picks up as push of the button (=potential drop) which makes the motor go into the other direction.

I'll try this next week. I don't have the right resistors at hand.

What do you have? Perhaps you could "parallel for value".

Nevermind, I found some 1kΩ resistors . It feels a little bit more stable than before, but still has some of these false button press recognitions from time to time. I also tried a pull-down configuration with the same result.

Pulled-up to 3V, yes?

Ooopsi, pulled it up to 5V...but 3V shows the same result.

Add 0.1uF ("100nF") from Input to GND.

These and the resistors -- minimal/minimize lead lengths

Awesome, works like a charm. Thank you so much!

Excellent.

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