ESP32 and ADC class - pin numbering scheme?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
timg11
Posts: 19
Joined: Sun Feb 14, 2021 10:51 pm

ESP32 and ADC class - pin numbering scheme?

Post by timg11 » Mon May 03, 2021 1:18 pm

First time using Micropython on ESP32.
I've got the ESP32-WROOM-32 with esp32-20210418-v1.15.bin

I'm using a development board with this pinout

I'm trying to use the ADC library described in the documentation
ADC (analog to digital conversion)
On the ESP32 ADC functionality is available on Pins 32-39.
Pins 32-39 correspond to 8 ADC channels. On my development board there appears to be 16 ADC inputs.

Code: Select all

from machine import ADC
adc = ADC(Pin(32))          # create ADC object on ADC pin
adc.read()                  # read value, 0-4095 across voltage range 0.0v - 1.0v
As this refers to "Pin", it is confusing what numbering scheme is being used. The ADC channels have a numbering scheme from ADC0 to ADC15. I rule it out since the library docs say "pins 32-39". The GPIOs have a numbering scheme. The pins of the ESP-WROOM-32 module also have a numbering scheme.

What numbering scheme is used in the statement "adc = ADC(Pin(32)) " ?

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

Re: ESP32 and ADC class - pin numbering scheme?

Post by Roberthh » Mon May 03, 2021 2:27 pm

Micropython uses the GPIO numbers.

timg11
Posts: 19
Joined: Sun Feb 14, 2021 10:51 pm

Re: ESP32 and ADC class - pin numbering scheme?

Post by timg11 » Mon May 03, 2021 4:59 pm

Thank you - I've got one channel working on GPIO34 now.

For future understanding, I'm trying to relate the ADC numbers to the GPIO numbers used in the library.

The library says "pins 32-39" which would imply the following mapping

Code: Select all

GPIO     ADC
32           4
33           7
34           6
35           7
36           0
37           N/A
38          N/A
39           3
Are additional ADC channels available? Would they be referenced by GPIO pins outside the range of "pins 32-39". Why are GPIO 37 and 38 seeming to be missing?

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

Re: ESP32 and ADC class - pin numbering scheme?

Post by Roberthh » Mon May 03, 2021 6:19 pm

It' sup to the board designers which ESP32 pin they expose to the board's pins. If they use for instance the espressif Wroom or Wrover module, then GPIO37 and 38 are not accessible outside theses modules.

Post Reply