Help with simple ADC samples on ESPHOME YAML [samples] is an invalid option for [sensor.adc]

Hi everyone,

I’m having some problems with the ADC component. I’m using an Wemos ESP32-S2 mini (That with the purple board):


And I want to set up sampling on three ADC sensors, for GPIO7, 8 and 9. When I configure the ADC component by default (1 sample), it compiles without a problem. But when I add the "samples: " entry, it refuses to compile.

This is the yaml that compiles (Note that I cannot add the “samples” entry):

esphome:
  name: nevera
  friendly_name: nevera

esp32:
  board: esp32-s2-saola-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "+-----="

ota:
  password: "-------"

wifi:
  networks:
  - ssid: !secret wifi_ssid3
    password: !secret wifi_password3
  manual_ip:
    static_ip: 192.168.1.19
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
    dns2: 8.8.4.4
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Nevera Fallback Hotspot"
    password: "----------"

captive_portal:
    
web_server:
  port: 80

text_sensor:
  - platform: wifi_info
    ip_address:
      name: Direccion IP
    ssid:
      name: Nome da rede
    scan_results:
      name: Redes Dispoñibles


sensor:
  - platform: adc
    pin: GPIO7
    name: "Tension ADC1"
    attenuation: 11db
    id: ADC1
    update_interval: 1s
  - platform: adc
    pin: GPIO8
    name: "Tension ADC2"
    update_interval: 1s
    attenuation: 11db
    id: ADC2
  - platform: adc
    pin: GPIO9
    name: "Tension ADC3"
    update_interval: 1s
    attenuation: 11db #Segun a web de espresif, desde 0 a 2500 mV
    id: ADC3

Notes:

  • I use GPIO7, 8 and 9 because the recomended 32-39 raises an error:
    imaxe
    The documentation lets me use this pins on an ESP32-S2, with the ADC1:
    Analog To Digital Sensor — ESPHome
  • This is what I get when I write the “samples” entry:
  • I have also read that if I am using auto gain, samples are ignored. But I am setting the gain to a value, so this should not be the problem. Or am I missynderstanging something?
  • I unploaded screenshots of the error because I don’t know if it makes sense to upload a faulty code, does it?
    Thank your everyone for your help!

Difficult to follow…
Ok, your pins should be ok, 32-39 are not adc pins on your board.
On your yaml I don’t see line “samples: 10”, but in your error there is…

board: esp32-s2-saola-1
Have you tried some other boar definition ?

ps. when prototyping, use wroom 32 board. After everything works, try to adapt for “weird” boards if you need to.

Hi @Karosm

Thank you a lot for reading!.

Sorry for that. I edited the post a little, I hope it helps.

Yes. I uploaded the code that compiles. Should have I posted the code that gives me an errror? If so, I will post it.

Nope, I didn’t know that I could change the boards. I will try with the Wroom32 as you suggest.

Thank you again!

EDIT:
I tried to change the board definition. When I set the board name to “nodemcu-32s” (The wroom 32 as mencioned here:

And I can’t compile, because GPIO definition is different. So I tried with the “lolin_s2_mini” as suggested here:

And I get the same error.

If it helps, here is the faulty code (with the new board definition):

esphome:
  name: nevera
  friendly_name: nevera

esp32:
  board: lolin_s2_mini
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: 

ota:
  password:

wifi:
  networks:
  - ssid: !secret wifi_ssid2
    password: !secret wifi_password2
    # O 3 é Cacharrada
  - ssid: !secret wifi_ssid3
    password: !secret wifi_password3
  manual_ip:
    static_ip: 192.168.1.19
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
    dns2: 8.8.4.4
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Nevera Fallback Hotspot"
    password: "7DXF1upJDny3"

captive_portal:
    
web_server:
  port: 80

text_sensor:
  - platform: wifi_info
    ip_address:
      name: Direccion IP
    ssid:
      name: Nome da rede
    scan_results:
      name: Redes Dispoñibles


sensor:
  - platform: adc
    pin: GPIO7
    name: "Tension ADC1"
    attenuation: 11db
    id: ADC1
    update_interval: 1s
    samples: 10 ##### HERE IS THE PROBLEM#####
  - platform: adc
    pin: GPIO8
    name: "Tension ADC2"
    update_interval: 1s
    attenuation: 11db
    id: ADC2
  - platform: adc
    pin: GPIO9
    name: "Tension ADC3"
    update_interval: 1s
    attenuation: 11db #Segun a web de espresif, desde 0 a 2500 mV
    id: ADC3

Thanks!

Board looks good
Gpios look good

Still the same “samples is an invalid option” error?

Yes, it still has the error:

Hi
I got rid of this using one ads1115

If you need accurate values, I recomend this.

1 Like

I just tried it on an ESP32-C3 and got no errors, but as I do not have an ESP32-S2, the following might be the reason:

Support for ESP32 variants such as the S2, S3 and C3 is still in development and there could be issues.

I recommend opening an issue here: Issues · esphome/issues · GitHub