ESP32 ADC always reads 4095

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
GryKyo
Posts: 8
Joined: Sat Dec 15, 2018 12:43 am

ESP32 ADC always reads 4095

Post by GryKyo » Thu Jan 03, 2019 6:24 pm

Hi All,
New here and not seeing any way to post code, apologies if I am getting up your noses already!

Anyway, I have a Wemos D32 ready to deploy, deep sleeps for most of the time but should check IO35 on wake-up to alarm in case of low battery. Seems that any time I read Vbatt I get full scale 4095 on the ADC? No errors, just 4095 irrespective of battery volts?

on the REPL I get...
>>> import machine
>>> adc = machine.ADC(machine.Pin(35))
>>> adc.read()
4095

Same result any time I call the adc.read() function in my code?

Is the ADC broken in the esp32 port at the moment or am I possibly messing with a fake board with no voltage divider on IO35?

Anybody else come across this?

Many thanks in advance
Garry

User avatar
Roberthh
Posts: 1238
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 ADC always reads 4095

Post by Roberthh » Thu Jan 03, 2019 7:27 pm

The basic voltage range of the ADC is 0-1V. you can change that with an attenuator setting to about 1-3.2V if you need a wider range, you have to add your own voltage divider. The documentation about that for ESP32 is pretty sparse.
Setting the attenuator is something like:

Code: Select all

from machine import Pin, ADC
pin=Pin(35, Pin.IN)
adc = ADC(pin)
adc.atten(ADC.ATTN_11DB)

GryKyo
Posts: 8
Joined: Sat Dec 15, 2018 12:43 am

Re: ESP32 ADC always reads 4095

Post by GryKyo » Thu Jan 03, 2019 7:55 pm

Many thanks @Roberthh, that works well. I must crack out the multi-meter now and calibrate...

Garry

User avatar
mattyt
Posts: 186
Joined: Mon Jan 23, 2017 6:39 am

Re: ESP32 ADC always reads 4095

Post by mattyt » Fri Jan 04, 2019 12:52 am

Roberthh wrote:
Thu Jan 03, 2019 7:27 pm
The documentation about that for ESP32 is pretty sparse.
Tangentially...Note that I've made a start on the ESP32 documentation. You can view it or contribute via a pull request.

I've just created an issue: Need to improve ADC documentation. If someone could submit a PR that'd be great! Otherwise I'll get to it when I can.

User avatar
mattyt
Posts: 186
Joined: Mon Jan 23, 2017 6:39 am

Re: ESP32 ADC always reads 4095

Post by mattyt » Sun Jan 27, 2019 5:16 am

It's not perfect but the ESP32 ADC QuickRef has improved. Well, it exists now. ;)

We also need an ESP32 reference - then we can go into a little more detail about the ADC details. However the QuickRef and least touches on some of these points though it is meant to be terse.

Post Reply