Voltage measurement with I35

Piscenois
Posts: 11
Joined: Wed Nov 07, 2018 8:58 pm

Voltage measurement with I35

Postby Piscenois » Wed Nov 07, 2018 9:12 pm

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

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: Voltage measurement with I35

Postby ESP_Sprite » Thu Nov 08, 2018 2:45 am

Moved to the Arduino subforum, as that's what you seem to be using.

Piscenois
Posts: 11
Joined: Wed Nov 07, 2018 8:58 pm

Re: Voltage measurement with I35

Postby Piscenois » Fri Nov 09, 2018 9:37 am

I'm not sure it's an Arduino problem. But, why not ?! ;)

Piscenois
Posts: 11
Joined: Wed Nov 07, 2018 8:58 pm

Re: Voltage measurement with I35

Postby Piscenois » Tue Nov 27, 2018 6:18 pm

No one has ever tried to measure the voltage ?

Leonos
Posts: 4
Joined: Wed Nov 28, 2018 8:16 am

Re: Voltage measurement with I35

Postby Leonos » Thu Nov 29, 2018 11:43 am

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.

Piscenois
Posts: 11
Joined: Wed Nov 07, 2018 8:58 pm

Re: Voltage measurement with I35

Postby Piscenois » Sat Dec 01, 2018 3:51 pm

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.

Leonos
Posts: 4
Joined: Wed Nov 28, 2018 8:16 am

Re: Voltage measurement with I35

Postby Leonos » Sun Dec 02, 2018 4:09 pm

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.

Piscenois
Posts: 11
Joined: Wed Nov 07, 2018 8:58 pm

Re: Voltage measurement with I35

Postby Piscenois » Mon Dec 03, 2018 8:44 am

I just took my multimeter and measured the battery voltage. LiPo are given for 3.7V and I found 3.64V.

Regards.

Who is online

Users browsing this forum: No registered users and 58 guests