tinypico / tinypico-arduino

Arduino libraries and example code for TinyPICO
MIT License
45 stars 20 forks source link

Support for esp32 calibrated voltage conversion #5

Closed Joey232 closed 4 years ago

Joey232 commented 4 years ago

Used the esp32 esp_adc_cal_raw_to_voltage() function to get a more accurate battery voltage reading. Note, we call Arduino analogRead() to let that code setup the ADC for us. We need to do the adc1_get_raw() call because it looks like the Arduino code is messing with the raw value before returning it in analogRead().

Once we have the actual voltage on the pin, we use the resistor divider ratio to get the voltage at the battery, which then gets converted from mv to volts.

I also did some tab/space cleanup.