Is it possible to dynamically change adc pin on esp32?

I want to use an esp32 to measure current and voltage, I don’t have high accuracy requirements and want to save costs, so I don’t plan to use a separate measurement chip such as INA226.
esp32 has two adc components, but only one will work when wifi enabled.

https://esphome.io/components/sensor/adc.html

# Example configuration entry
sensor:
  - platform: adc
    pin: GPIOXX
    name: "test"
    update_interval: 60s

Is it possible to dynamically change adc pin? So that I can measure voltage and current using different pins in turn.

You’re misinterpreting the docs. adc2 is a set of pins, with Esp 32’s you can use multiple pins. You can only use pins labeled adc1 when wifi is used. Typically GPIO32 - GPIO39. See the chart for your specific board type.

https://esphome.io/components/sensor/adc.html#esp32-pins

I think what was meant was whether you can dynamically select which pin to use with adc1. Get the measurement using one pin and then swap to another pin, to get the other measurement, which unfortunately isn’t possible afaik.

I did use adc2 once by turning wifi off while doing the reading, and turning wifi on again afterwards. It was a bit of a kludge though.

Btw. It is possible to use adc2 with wifi on Esp32-s2, however wifi has higher priority.

is a group of pins, that is all.

set up 2 adc sensors, each on a different pin, only use pins in the adc1 group.

Ah yeah, I forgot that each adc has multiple channels. My mistake.

It works, thank you very much.

1 Like