ADC input stuck on one level

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ParaPashka
Posts: 4
Joined: Tue Apr 20, 2021 6:18 pm

ADC input stuck on one level

Post by ParaPashka » Tue Apr 20, 2021 6:49 pm

Hi all!
I am using ESP32 WROOM-32 board.
When i read data from light sensor, the first value that i get is correct. After that i change the voltage on the pin. But the data that I get is still on the same level (changes just a little bit).
The input voltage is around 0.5v. I get:
...
533
534
575
...
I change the voltage to 1.8v. But i still get the same:
...
534
546
538
...

I reset and start the program starting with 1.8v input:
...
2009
1958
2007
...
I change the input to 0.5v, but still get the same:
...
2007
2008
2001
...

This is the code:

Code: Select all

from machine import ADC
from machine import Pin
light_sensor = ADC(Pin(33))
light_sensor.atten(ADC.ATTN_11DB)
while True:
    print(light_sensor.read())
I tryed it on 2 equal esp32 boards. I tryed using different pins. Tryed to reinit the ADC object before getting each value in the cycle. Nothing helps to get actual data.
What is the problem?

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

Re: ADC input stuck on one level

Post by Roberthh » Tue Apr 20, 2021 7:13 pm

That's strange. With the 11db setting, you could try to connect the ADC input to GND and 3.3V. Then you should read 0 and 4095 as adc.read() value. That's what I tried here.

ParaPashka
Posts: 4
Joined: Tue Apr 20, 2021 6:18 pm

Re: ADC input stuck on one level

Post by ParaPashka » Wed Apr 21, 2021 9:41 am

I got the solution.
After I added small pause between reading data, everything went correct.
New code:

Code: Select all

from machine import ADC
from machine import Pin
import time

light_sensor = ADC(Pin(34))
light_sensor.atten(ADC.ATTN_11DB)
while True:
    print(light_sensor.read())
    time.sleep_ms(10) #added this line

Post Reply