Newb Question:
I have an esp32-C3 dev board and have used up all the pins except the voltage and GND pins. There is a gpio/analog pin also labeled "VBAT" that is connected to a built-in voltage divider (see C3 pico — WEMOS documentation) . I want to be able to use use that pin to read my battery level but really only need to do so once each time when it wakes from sleep. Is there anything wrong with putting an analogRead in setup() to read the voltage into a variable, then setting the pinmode to a digital input e.g. pinMode(BUTTON_PIN, INPUT_PULLUP);? Seems straight-forward, but it's the easy things that get you.
Hmm. What about (bat+ to divider to (10k) to pin(pullup); if R were, say, 10k, and the pin were otherwise used for a button input, where the button is wired pin-to-ground? In that case, the normal behavior of the pin when used as a digital input just has a bit of current flowing from pin to battery, but at startup with the pin as an AI, there's no reason for current to flow, so the battery reading would be valid?
Of course, the battery discharges through the 10k and switch when the button is pressed, but that shouldn't be a big deal your parasitic drain is the divider to start with.
I can't think of a reason for this to not work. Maybe, try it?
Otherwise, show us your schematic, maybe something else is more appropriate.
Are you sure that the IO3 pin on the board is connected ?
You could add a button to IO3 and GND. If the button is not pushed at startup, then you can read the battery. In the sketch you can use analogRead() to check if the button is pressed.
Great Idea...you guys are really smart. My project is a digital watch that has different menus and will eventually be able to update via WiFi and BLE. I have a 3-way navigation button. Surface Mount Navigation Switch - COM-08184 - SparkFun Electronics. This takes up pins 5, 20, and 21 (I have to have one of them on pin 5 because on the esp32-c3 can only be awaken by pins 0-5). I have an SH1106 oled screen. It is an SPI. I tried an I2C (fewer pins) but the refresh rate was too slow for my application. The SPI takes up 5 pins (I know, what a scam, huh?) I have CLK on pin 2, MOSI on pin 4, RESET on pin 1, DC on pin0, and CS on pin 7. I have a buzzer on pin 6. I have a DS3234 RTC CS on pin 10 and the SQW signal from the RTC alarm on pin 3. That leaves only pin 8 which I currently have planned for another push button.
Is that absolutely needed? Some libraries for oled displays allow you to omit the reset pin, or give a "no pin" value to the constructor or .begin() method.
The navigation button can only only pull either pin 20 or 21 down at any instant, but not both at the same time. Your other button could pull both of them down together if you wire it with a couple of diodes.
Perhaps your display doesn't have a built in auto reset. One could be added using apx803 or MCP100-300 but I guess you want to avoid adding more components for your project.
Can't I just connect reset to +3.3V? I found a data sheet for SH1106 and it says the following:
Power Reset for Controller and Driver This pin is reset signal input. When the pin is low, initialization of the chip is executed. Keep this pin pull high during normal operation.
So the chip will initialize upon waking from sleep I guess. How is this different from Vcc?
Try it. To be honest, I thought you already did that and found it didn't work. Or did you mean you left the reset pin unconnected? I would expect the oled board to have a pull-up resistor on the RESET pin, but perhaps not.
I connected Reset to +3.3V and it seems to be working fine. I've run it through some sleep/wake cycles, and it seems to be working normally. Paul just put me back in the +1 gpio column! Thanks, man.