Friday, December 11, 2020

ESP32 Wifi-Analogread problem

 For an index to all my stories click this text

I was experiencing a strange error. And I could not find what I was doing wrong.

Short situation sketch.

I had an LDR attached with a 10K pull-down resistor to a pin of my ESP32 and I was going to send the sensors data over Wifi.

However the analog reading just gave 4095 all the time. So I presumed a faulty LDR. I exchanged it to a new one but no avail. I checked the connections over and over and still no result. The output of the ESP kept telling me the measured value was 4095.

Well then there could be only one conclusion. The analog input pin of the ESP32 should be defective. So I attached the LDR to another pin and presto: immediate result.

But something was nagging me. I had used that pin all the time when I was writing my book. So why would it suddenly be faulty. Therefore I started testeing other analog input pins and guess what:  some where working OK others were dead.

Wifi and Analog read do not mix on all pins !!!

Then I started digging in the technical literature and on the internet and then I found it. The ESP32 has two ADC converters ADC1 with 8 channels that are connected to GPIO 32 till 39 and ADC2 which has 10 channels. The problem is that ADC2 is used to manage wifi functions. So if you use Wifi you can not use ADC2 !!!

So the bottom line is: if you are using Wifi you can only use GPIO32 till GPIO39.

My Doit Dev Kit has not all of these pins exposed so I can only use GPIO32, GPIO33, GPIO34, GPIO35, GPIO36 and GPIO38. And testing revealed that these indeed worked as they should.



Above is a pin layout of the ESP32 Doit Devkit board with the Analog input pins exposed. You can use all these pins when you are not using wifi.

If you need Analog pins and Wifi only use the next pins:

pin D33 ADC5  GPIO33 OK
pin D32 ADC4  GPIO32 OK
pin D35 ADC7  GPIO35 OK
Pin D34 ADC6  GPIO34 OK
pin D39 ADC3  GPIO39 OK
pin D36 ADC0  GPIO36 OK

It is annoying but in the end I was just pleased that my ESP32 was not broken.

Till next time
Have fun

Luc Volders