I'm running the Arduino platform with VS Code.
I have a single input pin for a button but lately it has gotten sporadic and seems to be stuck low according to digitalRead but both my DMM and analog sampling of the pins show it high. I can toggle it with the button and it moves from high to low (DMM and analog samples) however the digitalRead thinks it's still 0.
I tried switching input pins on the development board but I keep getting similar results. I also tried running the code on the brand new board and keep getting the same thing. It's very strange because it's been working fine for a while, but I noticed if the device sat for hours it would start to think the button was stuck low. Now it appears to think the button is always low (even with nothing connected).
I've tried a 10k pullup. I've tried switching the input type back and forth with INPUT_PULLUP or just INPUT. I've tried this on the brand new board and found similar behavior, but it seems to be stuck all the time now. It used to seem to drift high and low, or work as expected. But now it's stuck low.
Normally I would just replace the hardware, but I've gone through 4 of these (2 of them had issues with the I2C bus not working) and now this problem.
Doesn't anyone have any thoughts on this or heard of similar issues with this board?
Here's my test code, I've stripped it down just to look at this issue.
Code: Select all
#include <Arduino.h>
#include <SPI.h>
#include <FS.h>
#include <SPIFFS.h>
#define BUTTON_PIN 14
void setup()
{
// setup serial
Serial.begin(115200);
Serial.println();
// setup input/output
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop()
{
// Read the value from the input pin
int pinValue = digitalRead(BUTTON_PIN);
// Print the value to the Serial Monitor
Serial.print("The value of the input pin ");
Serial.print(BUTTON_PIN);
Serial.print(" is: ");
Serial.println(pinValue);
// Measure and print the actual voltage at the input pin
int analogValue = analogRead(BUTTON_PIN);
float voltage = analogValue * (3.3 / 4095.0);
Serial.print("Voltage at input pin: ");
Serial.println(voltage);
// Add a delay to avoid flooding the Serial Monitor
delay(1000);
}
The value of the input pin 14 is: 0
Voltage at input pin: 3.30
The value of the input pin 14 is: 0
Voltage at input pin: 3.30
The value of the input pin 14 is: 0
Voltage at input pin: 3.30
The value of the input pin 14 is: 0
Voltage at input pin: 3.30