teensy 3.x, delay needed after pinMode() and digitalRead()

Status
Not open for further replies.

stevech

Well-known member
Perhaps this is noted somewhere, but I found out the slow way that on a Teensy 3.1 ...
Code:
pinMode(pin, INPUT_PULLUP);
delay(microseconds or 1 mSec);
x = digitalRead(pin);
the delay() is needed else the digitalRead() gets a 0 instead of a 1. I have a jumper block on that pin which if not in place (grounded pin, the problem arises).
Perhaps the delay is needed due to the R/C time constant for the high value pullup.

or read the pin later in the code.
 
Last edited:
Perhaps the delay is needed due to the R/C time constant for the high value pullup.

Yes. This happens with INPUT_PULLUP on all chips. The faster the code runs, the more likely the pin isn't high yet if you try to read immediately after turning on the pullup resistor, due to the brief time needed to charge the small capacitance of the pin, wire, and whatever else is connected. Teensy 3.1 is very fast...
 
ah, thats nice! thanks for the explanation, Paul..
so thats an alternative methode to measure capacitance using 1 pin, switch on the pullup and count cycles till it reads 1.. (I know the touch functions are there for this, but nevertheless, good to know!)
 
Status
Not open for further replies.
Back
Top