jgoo9410
(John )
February 13, 2022, 9:57pm
1
I have connected up an esp32 devkit V1 to home assistant via ESPhome. I want to read an analogue voltage from GPIO32. I’m currently using the following yaml file:
esphome:
name: main-power
platform: ESP32
board: esp32doit-devkit-v1
#esp32:
# board: nodemcu-32s
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "224c14826fd2a8216b926efc1f0385b5"
wifi:
ssid: "The Manor"
password: "chubster"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Main-Power Fallback Hotspot"
password: "5py8EBGKWeWk"
captive_portal:
sensor:
- platform: adc
pin: GPIO32
name: "Living Room Brightness"
update_interval: 0.5s
When I view the output in the node terminal, I can only get voltages from 0.075V - 1.057V. Even when I short the pin to ground, I still cant get a value of 0V in the readout. I should be getting a range from 0-3.3V. Just to make sure I didn’t have damaged hardware, I used the arduino IDE to load a test sketch and I was able get the full range from the ADC.
Am I doing something stupid?
nickrout
(Nick Rout)
February 13, 2022, 10:09pm
2
What is connected to GPIO32? A wiring diagram may help
jgoo9410
(John )
February 13, 2022, 10:12pm
3
Nothing at the moment, I’m just using the 3v3 and GND to short the pin out for a quick test.
tom_l
February 13, 2022, 11:23pm
4
You need to set the attenuation value to get the full range:
https://esphome.io/components/sensor/adc.html#adc-esp32-attenuation
sensor:
- platform: adc
pin: GPIO32
attenuation: 11db
name: "Living Room Brightness"
update_interval: 0.5s
Mikefila
(Mike Fila)
February 13, 2022, 11:24pm
5
Try setting the attenuation to auto.
sensor:
- platform: adc
pin: GPIO32
name: "Living Room Brightness"
update_interval: 0.5s
attenuation: auto
On the ESP32 the voltage measured with the ADC caps out at ~1.1V by default as the sensing range (attenuation of the ADC) is set to 0db
by default.
tom_l
February 13, 2022, 11:28pm
6
Oooh. When was the auto
option introduced?
Or did I just miss that from the start as it is not listed as a valid option in the docs:
Though it is mentioned further down the page:
Mikefila
(Mike Fila)
February 13, 2022, 11:30pm
7
You didn’t, it showed up a couple of cycles ago.
1 Like
tom_l
February 13, 2022, 11:32pm
8
Neat. I’ll put in a PR to have it included in the valid options.
EDIT: I’m blind. Someone has already added it:
1 Like