Page 1 of 1

Voltage measurement with I35

Posted: Wed Nov 07, 2018 9:12 pm
by Piscenois
Hi,

I work with Wemos D32 pro.
I would want to measure the battery voltage through the named _VBAT pin (= 35, see pins_arduino.h).
I have 2 push buttons connected to GPIO 25 and 26 ( = DAC 1, = DAC2), using internal pullup resistors and declared interrupts on falling edge.
When I read the voltage (analogRead(_VBAT)) it fires the ISR method of these two buttons, but not others (GPIO 32, 33, 00).

I suspect DAC to be "activated" when reading _VBAT, also I tried :
1/ to disable DAC :

Code: Select all

  dac_output_disable(DAC_CHANNEL_1);
  dac_output_disable(DAC_CHANNEL_2);
  dac_i2s_disable();
2/ to disable interrupts and wait a little :

Code: Select all

  noInterrupts();
  int measure = analogRead(_VBAT);
  delay(100);
  interrupts();
nothink worked ! :(

Could someone help me ?
Am I wrong with the method to read voltage ?

Regards

Re: Voltage measurement with I35

Posted: Thu Nov 08, 2018 2:45 am
by ESP_Sprite
Moved to the Arduino subforum, as that's what you seem to be using.

Re: Voltage measurement with I35

Posted: Fri Nov 09, 2018 9:37 am
by Piscenois
I'm not sure it's an Arduino problem. But, why not ?! ;)

Re: Voltage measurement with I35

Posted: Tue Nov 27, 2018 6:18 pm
by Piscenois
No one has ever tried to measure the voltage ?

Re: Voltage measurement with I35

Posted: Thu Nov 29, 2018 11:43 am
by Leonos
Yes, I have, but since I am not using 25 and 26 that way (interrupts), I didn't experience the issues you have. Can't you move those buttons to another pair of pins?

Regarding measuring voltage: I have to use (analogRead(35) * 3.3 * 2.0 * 1.12) / 4095.0f
3.3: is normally the max voltage a pin can read;
2.0: According to Adafruit (I am using their ESP32 Feather Huzzah), pin 35 only provides half the voltage;
1.12: a strange conversion factor I need to include in order to assure that the calculated voltage is the same as my multimeter shows when measuring the battery directly;
4095: the maximum value analogRead reports if you're using 12-bits resolution.

Re: Voltage measurement with I35

Posted: Sat Dec 01, 2018 3:51 pm
by Piscenois
Thank you for replying :)

Tihs is my function to calculate voltage :
voltage = 2.0 x 3.64 x measure / 4096.0 (=> 3.64 x measure / 2048 to avoid useless operations)
with :
- measure = analogRead(_VBAT)
- 3.64 = battery voltage

I already have other buttons, 4 more, on GPIO 00 - 13 - 32 - 33, and no interrupt is thrown on these ones when I read _VBAT.

Regards.

Re: Voltage measurement with I35

Posted: Sun Dec 02, 2018 4:09 pm
by Leonos
Tihs is my function to calculate voltage :
voltage = 2.0 x 3.64 x measure / 4096.0 (=> 3.64 x measure / 2048 to avoid useless operations)

So it looks like you came to almost the same thing. Where did you get this extra factor 1.10 (3.64 / 3.3) from? I can't find any reference to it, nor an explanation for it, and Adafruit does not document it in their ESP32 learning document (just saying 3.3 * 2 / 4095). But that does not result in a voltage that I measure. I therefore just multiplied with 1.12 to get agreement between calculated and measured voltage.

Re: Voltage measurement with I35

Posted: Mon Dec 03, 2018 8:44 am
by Piscenois
I just took my multimeter and measured the battery voltage. LiPo are given for 3.7V and I found 3.64V.

Regards.