digitalRead forces INPUT_PULLUP #30
Description
When creating a simple program to read a button with a pull-down resistor (10k) the input registers no voltage for as long as digitalRead is not called. Once digitalRead is issued, the pin seems to go into internal pull-up configuration, what makes the pin to be always up for the above-mentioned pull-down resistor.
Reproduce the error
- Investigating the issue requires using a multimeter and making a simple program:
void setup() {
pinMode(2, INPUT);
}
void loop() {
}
On the multimeter this reads: 0V
- Change the program to contain a digitalRead():
void setup() {
pinMode(2, INPUT);
}
void loop() {
digitalRead(2);
}
The multimeter goes then into 3v3 for that pin.
On the other hand, when checking into the way digitalRead is defined, we find that it returns:
return (PinStatus)mbed::DigitalIn(digitalPinToPinName(pin)).read();
(as seen at: https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/master/cores/arduino/wiring_digital.cpp#L79)
This call to DigitalIn seems to be lacking PullNone, what could be the reason for this not to work. However, this requires a deeper revision, as just adding PullNone, would force it also in the case when we would like INPUT_PULLUP to be active.