Closed bkari02 closed 10 months ago
Might be related to #6436 #4941 and #4386 but these have all been closed a long time ago and not mentioned the relation to the analogWidth/readResolution.
Hello @bkari02, can you please try to run your sketch on latest dev release 3.0.0-alpha3 or on master? The ADC got refactored to new ESP-IDF NG drivers. Thanks!
Hey @P-R-O-C-H-Y thanks for the quick response! Indeed, everything does work as expected in the 3.0.0-alpha3 release, so the refactoring solved the issue here.
Since there are some other breaking changes that does not allow us to fully migrate to v3 yet, is there a chance this can get fixed in a new v2.x release? I could also try to contribute a PR if that helps.
Hello @bkari02, feel free to open a PR targeting https://github.com/espressif/arduino-esp32/tree/release/v2.x branch. We are now collecting fixes for v2.X and will decide at the beginning of 2024 if it makes sense to release v2.0.15. I am adding this issue to that milestone for tracking.
Solved in #9006
Board
ESP32-S2
Device Description
Tested with Unexpected Maker FeatherS2 & senseBox MCU-S2 ESP32-S2
Hardware Configuration
Any analog sensor (e.g. Truebner SMT50 or SparkFun SEN-13322) is connected.
Version
v2.0.14
IDE Name
ArduinoIDE
Operating System
macOS 14.1.2
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600
Description
Expected behaviour: When using ESP32-S2 and
analogReadMilliVolts(pin)
I should always get the measured voltage in milliVolts.Weird behaviour: When changing the default 13 bit resolution of the ADC1 to e.g. 12bit using
analogReadResolution(12);
the outputs of analogReadMilliVolts(pin) are incorrect (half in size in case of 12bit).Tried to track it down and found this to be happening (in esp32-hal-adc.c): The
__analogRead()
function uses the 12 bit resolution (as expected because ofanalogReadResolution(12)
). But__analogReadMilliVolts()
internally also uses__analogRead()
which returns a 12bit ADC value. But during transformation inesp_adc_cal_raw_to_voltage((uint32_t)adc_reading, &chars)
the adc_reading is always expected to be the raw 13bit value in case of the ESP32-S2. There it assumes the 12 bit value to be 13 bit and the resulting value in milliVolts half of the correct value.I assume this also happens with other chips than the S2, but haven't tested it so far.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide