Remap Pins in Setup?

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.

Thanks,
Fish

If you connect a signal to it (to be read with digitalRead) then you can no longer read the battery voltage.

Tell us about what is connected, the forum can probably suggest ways to free-up one or two.

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 ?

afbeelding

afbeelding

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.

1 Like

That is what I was thinking as well.

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.

unfortunately it is. I thought the same thing when I first wired it up and the display won't fire up without the reset pin.

I would make the alarm in software, so you don't need the SQW output from the RTC.

https://www.pjrc.com/teensy/td_libs_TimeAlarms.html

Will this work even in deep sleep? I know in deep sleep the RTC on the esp32 still functions. I wasn't aware you could set alarms as well.

Fish

Good point. I don't know anything about a sleep mode or RTC capabilities of the ESP32-C3.

I'll look into it, though. If the alarms can be made to trigger even in deep sleep it's a good catch.

Fish

Did you connect the reset pin to 3.3V?

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?

Fish

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 left it unconnected. I will try connecting to +3.3V. This would be great if it works. I'll let you know.

Fish

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.

Fish

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