ESP32-S Crashes and will not read DAC or Resistance

Hey folks,

I am very new to ESPHome and excited with all the features it provides, but reality has bene giving me a very hard time…

I am working with the ESP32-S module:

I tried to accomplish a few things with my first node:

  • Act as a BLE server to connect and propagate data from BLE devices I use
  • Measure Gas using the MQ2 sensor
  • Measure light using a photoresistor.

Once I managed to flash my ESP32-S I quickly realized that using the BLE Server component was a non-starter as the chip would crash in the first couple of minutes… So i commented out that section…

Now the chip crashes after about 10 minutes… which is obviously a huge problem…

The other set of problems is that neither the “adc” nor the “resistance” platforms, will read any values from my two sensors… I have them hooked up on GPIO32 (MQ2) and GPIO33 (Photoresistor).

Both the MQ2 and photoresistor are pulled down with a 10k resistor and use 5v VCC.

I tried both the “adc” standalone configuration and then added the “resistance” configuration on top of that, but both were reading default values…

I enabled verbose logging in an effort to understand why no values were being read and why the chip was crashing, the only notable thing was the log:

[18:20:02][V][component:200]: Component adc.sensor took a long time for an operation (0.05 s).
[18:20:02][V][component:201]: Components should block for at most 20-30ms.

Which I don’t know what sense to make of… it also happens that this is usually the last log before the chip crashes and won’t come back up…

Here are the last ~20 or so lines of remote logging before the crash:

[18:18:42][V][component:200]: Component adc.sensor took a long time for an operation (0.05 s).
[18:18:42][V][component:201]: Components should block for at most 20-30ms.
[18:19:02][V][adc:132]: 'mancave_mq2_gas_sensor': Got voltage=0.9530V
[18:19:02][V][sensor:076]: 'mancave_mq2_gas_sensor': Received new state 0.953000
[18:19:02][D][sensor:127]: 'mancave_mq2_gas_sensor': Sending state 0.95300 V with 2 decimals of accuracy
[18:19:02][D][resistance:039]: 'Mancave Gas Sensor' - Resistance 2354.8Ω
[18:19:02][V][sensor:076]: 'Mancave Gas Sensor': Received new state 2354.830811
[18:19:02][D][sensor:127]: 'Mancave Gas Sensor': Sending state 2354.83081 Ω with 1 decimals of accuracy
[18:19:02][V][mqtt:415]: Publish(topic='mancave-esphome/sensor/mancave_gas_sensor/state' payload='2354.8' retain=1)
[18:19:02][V][component:200]: Component adc.sensor took a long time for an operation (0.06 s).
[18:19:02][V][component:201]: Components should block for at most 20-30ms.
[18:19:07][I][ota:113]: Boot seems successful, resetting boot loop counter.
[18:19:07][D][esp32.preferences:113]: Saving 1 preferences to flash...
[18:19:07][V][esp32.preferences:125]: sync: key: 233825507, len: 4
[18:19:07][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[18:19:42][V][adc:132]: 'mancave_light_sensor': Got voltage=1.0450V
[18:19:42][V][sensor:076]: 'mancave_light_sensor': Received new state 1.045000
[18:19:42][D][sensor:127]: 'mancave_light_sensor': Sending state 1.04500 V with 2 decimals of accuracy
[18:19:42][D][resistance:039]: 'Mancave Light Sensor' - Resistance 2642.2Ω
[18:19:42][V][sensor:076]: 'Mancave Light Sensor': Received new state 2642.225098
[18:19:42][D][sensor:127]: 'Mancave Light Sensor': Sending state 2642.22510 Ω with 1 decimals of accuracy
[18:19:42][V][mqtt:415]: Publish(topic='mancave-esphome/sensor/mancave_light_sensor/state' payload='2642.2' retain=1)
[18:19:42][V][component:200]: Component adc.sensor took a long time for an operation (0.06 s).
[18:19:42][V][component:201]: Components should block for at most 20-30ms.
[18:20:02][V][adc:132]: 'mancave_mq2_gas_sensor': Got voltage=0.9440V
[18:20:02][V][sensor:076]: 'mancave_mq2_gas_sensor': Received new state 0.944000
[18:20:02][D][sensor:127]: 'mancave_mq2_gas_sensor': Sending state 0.94400 V with 2 decimals of accuracy
[18:20:02][D][resistance:039]: 'Mancave Gas Sensor' - Resistance 2327.4Ω
[18:20:02][V][sensor:076]: 'Mancave Gas Sensor': Received new state 2327.416504
[18:20:02][D][sensor:127]: 'Mancave Gas Sensor': Sending state 2327.41650 Ω with 1 decimals of accuracy
[18:20:02][V][mqtt:415]: Publish(topic='mancave-esphome/sensor/mancave_gas_sensor/state' payload='2327.4' retain=1)
[18:20:02][V][component:200]: Component adc.sensor took a long time for an operation (0.05 s).
[18:20:02][V][component:201]: Components should block for at most 20-30ms.
INFO 192.168.20.5: Ping timed out!
INFO Disconnected from ESPHome API for 192.168.20.5
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for 192.168.20.5: Timeout while connecting to ('192.168.20.5', 6053)
INFO Trying to reconnect to 192.168.20.5 in the background

And here is my configuration:

esphome:
  name: mancave-esphome
  platform: ESP32
  board: nodemcu-32s
    
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.20.5
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.20.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0  

# esp32_ble_tracker:

# ble_client:
#   - mac_address: A4:C1:38:45:6B:C8
#     id: mancave_atc

mqtt:
  broker: 192.168.20.2
  username: !secret mqtt_user
  password: !secret mqtt_password

sensor:
  - platform: adc
    pin: GPIO32
    id: mancave_mq2_gas_sensor
    # name: "Mancave MQ2 Gas Sensor"
    # update_interval: 60s
  - platform: resistance
    sensor: mancave_mq2_gas_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    reference_voltage: 5
    name: Mancave Gas Sensor

  - platform: adc
    pin: GPIO33
    id: mancave_light_sensor
    # name: "Mancave Light Sensor"
    # update_interval: 60s    
  - platform: resistance
    sensor: mancave_light_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    reference_voltage: 5
    name: Mancave Light Sensor



  # - platform: pvvx_mithermometer
  #   mac_address: A4:C1:38:45:6B:C8
  #   temperature:
  #     name: "Mancave temp"
  #     id: mancave_temp

    # type: characteristic
    # ble_client_id: mancave_atc
    # name: "Mancave Temperature"
    # service_uuid: "2A1F"
    # characteristic_uuid: "2A1F"
    # icon: "mdi:thermometer"
    # unit_of_measurement: "C"


# Enable logging
logger:
  level: VERBOSE

# Enable Home Assistant API
api:

ota:

Any help or guidance would be greatly appreciated…

As it says in the docs

Note

Support for the ESP32-S2 and ESP32-C3 is still in development and there could be issues.

And

ESP-IDF framework

This is an alternative base framework for ESP32 chips, and recommended for variants of the ESP32 like ESP32S2, ESP32S3, ESP32C3 and single-core ESP32 chips.

1 Like

With the help of the kind folks at ESPHome Discord, I learned and figured out the following:

  • The ESP32 ADC module requires the property attenuation: auto to be present, as by default it has a low setting and the ADC module gets saturated (thus i was getting constant false readings). More reading here.
  • The Resistance module required the configuration property to be set to “UPSTREAM” as I’ve pulled down the sensors, so configuration: UPSTREAM, as per the docs.
  • Default WiFi Power Save mode for ESP32 is “light”, I had to switch it to None power_save_mode: none, since this is going to be mains powered. Docs Reference.
    • Sidenote: since I use a specific SSID, I also turned off WiFi scanning to save up on boot time: fast_connect: true.
  • Using “MQTT” alongside the “API” while using home assistant, is redundant, so I removed the MQTT configuration to further save on RAM usage.

With all of the above that resulted in a correct configuration file, stability came. The chip has not crashed for over an hour that I’ve been testing it…

I will now leave the esp running for a couple days before i deploy it on production to make sure there are no other stability issues and will also test adding back the ble_tracker configuration to see how it behaves… I’ll update this thread with the outcome for future reference.

2 Likes

The ESP32S chip I use is neither mentioned in the list you quoted nor is it single core…

1 Like

Sorry you are right. I have been in a lot of threads on S2 chips lately and clearly got myself confused.

Glad you got it working.

Unfortunately I am getting unexplained crashes after about 10-15 hours of operation.

I have the ESP serially connected to my PC, so I can monitor the logs via serial connection and there is nothing being reported on my serial console… normal operation until it just stops, disconnects from WiFi and is never heard from again…

The only notable thing is that I got a bit more stable run with the last update v2022.12.8. Before that version, I would get the following warning messages on each reading of the two analog sensor components I have configured:

[V][component:200]: Component adc.sensor took a long time for an operation (0.05 s).
[V][component:201]: Components should block for at most 20-30ms.

I’ve run out of remedies, I consider reading two analog sensors to be the simplest of operations for an ESP…

At this point I’ve spent much more time on this than writing the program myself, so I’ll call it a day with ESPHome and these particular ESP-32S chips.

This is my final configuration:

esphome:
  name: mancave-esphome
  platform: ESP32
  board: nodemcu-32s
    
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True
  power_save_mode: None
  manual_ip:
    static_ip: 192.168.20.5
    gateway: 192.168.20.1
    subnet: 255.255.255.0
    dns1: 8.8.8.8
    dns2: 1.1.1.1

sensor:
  - platform: adc
    pin: GPIO32
    id: mancave_mq2_gas_sensor
    attenuation: auto
    update_interval: 10s
  - platform: resistance
    sensor: mancave_mq2_gas_sensor
    configuration: UPSTREAM
    resistor: 10kOhm
    reference_voltage: 5
    name: "Mancave Gas Sensor ATN"

  - platform: adc
    pin: GPIO33
    id: mancave_light_sensor
    attenuation: auto
    update_interval: 10s    
  - platform: resistance
    sensor: mancave_light_sensor
    configuration: UPSTREAM
    resistor: 10kOhm
    reference_voltage: 5
    name: "Mancave Light Sensor ATN"

# Enable logging
logger:
  # level: VERY_VERBOSE

# Enable Home Assistant API
api:

ota: