I read the ESP32 ADC voltage range can be set in firmware to either 0-1V, 0-1.4V, 0-2V, or 0-4V.
Can you change the range in code or does it have to be set when the firmware is built?
Does anyone know the default range of the MicroPython.org daily builds?
I'm guessing it is 0-1.4V with a 12bit resolution (0-4095).
ESP32 ADC Range
Re: ESP32 ADC Range
Once you created an adc object, you can call adc.atten() to change the range, and adc.width to change the bit size e.g.:
This sets the range to 0..2 V. You can also add arguments as atten=value and width=value to the constructor. Do a dir(machine.ADC) to see the possible values. As far as I can recall, only ADC1 is supported at the moment.
Note: from my tests I can say that the ESP32 ADC is lousy, very noisy and non-linear. If you have a need for precision, use an external ADC.
Code: Select all
import machine
adc = machine.ADC(machine.Pin(36)
adc.atten(adc.ATTN_6DB)
Note: from my tests I can say that the ESP32 ADC is lousy, very noisy and non-linear. If you have a need for precision, use an external ADC.
Re: ESP32 ADC Range
Thanks for the detailed response!
Re: ESP32 ADC Range
Hello all,
https://docs.espressif.com/projects/esp ... alibration
provides very useful information regarding the ESP32 ADCs' limitations regarding noise, input voltage range and calibration.
For esp-edf, ADC calibration and conversion routines can be found here:
https://github.com/espressif/esp-idf/bl ... al_esp32.c
I have partly ported the conversion routine using the Vref (voltage reference) calibration value to MicroPython:
https://github.com/matthias-bs/MicroPython-ADC_Cal
The code is currently limited to
Hope this helps!
Best regards,
MatthiasP
https://docs.espressif.com/projects/esp ... alibration
provides very useful information regarding the ESP32 ADCs' limitations regarding noise, input voltage range and calibration.
For esp-edf, ADC calibration and conversion routines can be found here:
https://github.com/espressif/esp-idf/bl ... al_esp32.c
I have partly ported the conversion routine using the Vref (voltage reference) calibration value to MicroPython:
https://github.com/matthias-bs/MicroPython-ADC_Cal
The code is currently limited to
- ADC1
- 10 bits width
- 6 dB attenuation
- Vref calibration only (as opposed to Two-Point calibration)
Code: Select all
$ espefuse.py --port <port> adc_info
Best regards,
MatthiasP
Re: ESP32 ADC Range
Added internal reading of Vref efuse calibration value to
https://github.com/matthias-bs/MicroPython-ADC_Cal.
https://github.com/matthias-bs/MicroPython-ADC_Cal.
Re: ESP32 ADC Range
https://github.com/matthias-bs/MicroPython-ADC_Cal now supports all ESP32 ADC1 bit widths and 0/2.5/6 dB attenuation.
Re: ESP32 ADC Range
Thanks for providing this improvement, I will try it out next week.
Regarding your comment about noise, every minute and for one second I take 10 samples and average them. Then over a 10 minute period I do a moving average. Good when looking for relatively long-term changes.
Regarding your comment about noise, every minute and for one second I take 10 samples and average them. Then over a 10 minute period I do a moving average. Good when looking for relatively long-term changes.
-
- Posts: 28
- Joined: Mon Aug 27, 2018 4:43 pm
Re: ESP32 ADC Range
I think there's a typo:Roberthh wrote: ↑Sun Jun 25, 2017 6:25 amCode: Select all
import machine adc = machine.ADC(machine.Pin(36) adc.atten(adc.ATTN_6DB)
Code: Select all
adc.atten(machine.ADC.ATTN_6DB)