Hello,
I have built a code for reading a battery voltage - initially on pin GPIO_NUM_35 on normal ESP32
There was no setup for this pin, I only did analogRead(GPIO_NUM_35) and I was getting some values (0-4095) that afterwards I convert in voltage.
My problem is, I have the same code but on ESP32-S3 and GPIO_NUM_41
The code was not modified, the hardware itself was not modified - only the ESP32 was upgraded to ESP32-S3.
analogRead(GPIO_NUM_41) is returning 0 all the time.
It seems the default of this pin is MTDI (and not GPIO) and the GPIO default function is F0 (type I1 - input only). I see type I/O/T is for function F1, but I guess input only is fine for what I need. So not sure if I need any configuration or something.
Does anyone have any idea why analogRead is retuning 0 all the time on this pin?
Is it because there is no Analog Function on ESP32-S3 GPIO 41?
Any help is very much appreciated!
Thank you,
Marius
Read battery voltage on GPIO 41 (ESP32-S3 and Arduino IDE)
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: Read battery voltage on GPIO 41 (ESP32-S3 and Arduino IDE)
That was it. I changed the pin while waiting for the post to be approved and is all good.ESP_Sprite wrote: ↑Thu Dec 22, 2022 2:36 amExactly that. If you want a pin with an ADC function, check the ESP32-S3 datasheet and pick one of the pins that also have ADC1_CHx as a function. (ADC2 is not really usable on the S3 iirc.)
Thank you for reconfirming!
Re: Read battery voltage on GPIO 41 (ESP32-S3 and Arduino IDE)
Hello,
I have the same problem. I'm tryng to make a voltage meter for a battery using a Tension Partitor.
i'm connecting the partitor to PIN 2 but the voltage when i switch on the ESP32 at the output of the partitor change.
Can i ask you how your have solve?
I have the same problem. I'm tryng to make a voltage meter for a battery using a Tension Partitor.
i'm connecting the partitor to PIN 2 but the voltage when i switch on the ESP32 at the output of the partitor change.
Can i ask you how your have solve?
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Read battery voltage on GPIO 41 (ESP32-S3 and Arduino IDE)
Your translation is incorrect. The term you are looking for is voltage divider.
Use resistors to get the output voltage to be about 0.7V at your full range. This will give you the greatest accuracy. I use 10000 & 2200 ohm for a lithium battery. Then, set the attenuation to 0db and read the voltage.
Use resistors to get the output voltage to be about 0.7V at your full range. This will give you the greatest accuracy. I use 10000 & 2200 ohm for a lithium battery. Then, set the attenuation to 0db and read the voltage.
Code: Select all
#define PIN_BATTERY 7
void setup() {
Serial.begin(115200);
analogSetAttenuation(ADC_0db);
}
void loop() {
Serial.printf("reading: %lumV\n", analogReadMilliVolts(PIN_BATTERY));
Serial.printf("battery voltage: %lumV\n", analogReadMilliVolts(PIN_BATTERY) * (10000 + 2200) / 2200);
delay(1000);
}
Who is online
Users browsing this forum: No registered users and 36 guests