ESP32 restart randomly - nothing special, only 2xpcf8574, ina3221, htu21d, and webserver

Hello,

I have used this board: Wemos D1 UNO R32 ESP32 WIFI Bluetooth Arduino from the polish shop/auction (Allegro) service. It was not expensive - about 8 USD.

I am not sure if that was the proper choice.
I used this board as I am using many of physical switches and easyness of connecting it.
ESP32 as I wanted to add ble_tracker in the future…

I have developed some circuit, and… only one problem which I cannot solve is that it restart from time to time. I cannot found specific cause of that.
The only one I guess is the overloading value of uptime sensor - biggest value I had saw was about 4500s.

When I saw the problem on 5s update threshold of the uptime I have lowered it to 300s but that doesn’t helped.

I totally don’t know where is the problem, I only thought if the setup could be little complicated? (Lines of code).
There is some commented parts about mqtt - I have tried to disable it when looking if disabling lot of transferred data could help. Doesn’t helped :frowning:
ESP32 board is powered through the USB port, there is enough power in DC adapter. I am sure, checked few different power sources :slight_smile:

esphome:
  name: a_cc
  platform: ESP32
  board: esp32dev
  
wifi:
  ssid "redacted"
  passwor "redacted"
  use_addres redacted
  
# Enable logging
logger:
# Enable Home Assistant API
api:
  reboot_timeout: 0s
ota:
web_server:
  port: 80
binary_sensor:
  - platform: gpio 
    name: 5_14-btn3
    pin: 
        number: 14
        mode: input  
    on_double_click:
      min_length: 50ms
      max_length: 350ms        
      then:
        - switch.toggle: b2
    #on_press:
     # 
      #  then:
       #   - rtttl.play: 'two short:d=4,o=5,b=100:16e6'
#
          #- switch.toggle: a10
  - platform: gpio 
    name: 4_25-btn1
    pin: 
        number: 25
        mode: input  
    on_press:
        then:
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6'
          - switch.toggle: rll30a        
  - platform: gpio 
    name: 6_27-btn2
    pin: 
        number: 27
        mode: input  
    on_press:
        then:
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6'
          - switch.toggle: a5
  - platform: gpio 
    name: 2_39-btn5
    pin: 
        number: 39
        mode: input  
    on_press:
      
        then:
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6,16e6,16e6'

          - switch.toggle: rll3
  - platform: gpio 
    name: 3_dupa36-btn4
    pin: 
        number: 36
        mode: input  
    on_press:
        then:
          - switch.toggle: a1
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6'
  - platform: gpio 
    name: 9_fiol26-btn8
    pin: 
        number: 26
        mode: input  
    on_press:
        then:
          - switch.toggle: a7
          #- switch.toggle: rll1
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6'
  - platform: gpio 
    name: 1_dupa34-btn6
    pin: 
        number: 34
        mode: input  
    on_press:
        then:
            - rtttl.play: 'two short:d=4,o=5,b=100:16e6,16e6'
            - switch.toggle: a1
  - platform: gpio 
    name: 8_dupa4-btn9
    pin: 
        number: 4
        mode: input  
    on_press:
        then:
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6,16e6,16e6'
          - switch.toggle: rll2
  - platform: gpio 
    name: 7_siodmy-pin16-btn7
    pin: 
        number: 16
        mode: input  
    on_press:
      
        then:
          - rtttl.play: 'two short:d=4,o=5,b=100:16e6,16e6,16e6'
          #- switch.toggle: a10
switch:
  - platform: template  
    name: relayll
    id: rll1
    turn_on_action:
       - switch.turn_on: a1
       - delay: 900ms
       - switch.turn_off: a1
  - platform: template
    name: relayll2-patttern-R
    id: rll2
    turn_on_action:
       - switch.turn_on: a2
       - delay: 300ms
       - switch.turn_off: a2
  - platform: template  
    name: rrll3-patternL
    id: rll3
    turn_on_action:
       - switch.turn_on: a3
       - delay: 300ms
       - switch.turn_off: a3
  - platform: template  
    name: relayll4
    id: rll4
    turn_on_action:
       - switch.turn_on: a4
       - delay: 900ms
       - switch.turn_off: a4
  - platform: template  
    name: relayll5
    id: rll5
    turn_on_action:
       - switch.turn_on: a5
       - delay: 900ms
       - switch.turn_off: a5
  - platform: template  
    name: relayll6
    id: rll6
    turn_on_action:
       - switch.turn_on: a6
       - delay: 900ms
       - switch.turn_off: a6

  - platform: gpio
    name: d17-relay30a
    restore_mode: always_off
    id: rll30a
    pin:
      number: 17
      inverted: False

  - platform: gpio
    restore_mode: always_off
    name: "PCF8574 Pin #1"
    id: a1
    pin:
      pcf8574: e1_p
      number: 1      
      mode: OUTPUT
      inverted: true      
  - platform: gpio
    restore_mode: always_off
    name: "PCF8574 Pin #2"
    id: a2
    pin:
      pcf8574: e1_p
      number: 2      
      mode: OUTPUT
      inverted: true      
  - platform: gpio
    restore_mode: always_off
    name: "PCF8574 Pin #3"
    id: a3
    pin:
      pcf8574: e1_p
      number: 3      
      mode: OUTPUT
      inverted: true      
  - platform: gpio
    restore_mode: always_off
    name: "hgw-horn__PCF8574 Pin #4"
    id: a4
    pin:
      pcf8574: e1_p
      number: 4      
      mode: OUTPUT
      inverted: true
  - platform: gpio
    restore_mode: always_off
    name: "PCF8574 Pin #5"
    id: a5
    pin:
      pcf8574: e1_p
      number: 5      
      mode: OUTPUT
      inverted: true
  - platform: gpio
    restore_mode: always_off
    name: "pusty_PCF8574 Pin #6"
    id: a6
    pin:
      pcf8574: e1_p
      number: 6      
      mode: OUTPUT
      inverted: true
  - platform: gpio
    restore_mode: always_off
    name: "PCF8574 Pin #7"
    id: a7
    pin:
      pcf8574: e1_p
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: gpio
    restore_mode: always_off
    name: "pusty__PCF8574 Pin #7"
    id: a7true7relay
    pin:
      pcf8574: e1_p
      number: 7
      mode: OUTPUT
      inverted: true
      
      
  - platform: gpio
    restore_mode: always_off
    name: "bagrelay_e2_PCF8574 pin#0"
    id: b0
    pin:
      pcf8574: e2_p
      number: 0      
      mode: OUTPUT
      inverted: true
 
  - platform: gpio
    restore_mode: always_off    
    name: "bagrelay_e2_PCF8574 Pin #1"
    id: b1
    pin:
      pcf8574: e2_p
      number: 1
      mode: OUTPUT
      inverted: true      
  - platform: gpio
    restore_mode: always_off
    name: "FRONT_bagrelay_e2_PCF8574 Pin #2"
    id: b2
    pin:
      pcf8574: e2_p
      number: 2
      mode: OUTPUT
      inverted: true      
  - platform: gpio
    restore_mode: always_off
    name: "KAM360_bagrelay_e2_PCF8574 Pin #3"
    id: b3
    pin:
      pcf8574: e2_p
      number: 3      
      mode: OUTPUT
      inverted: true      
#  - platform: gpio
#    restore_mode: always_off
#    name: "bagrelay_e2_PCF8574 Pin #4"
#    id: b4
#    pin:
#      pcf8574: e2_p
#      number: 4
#      mode: OUTPUT
#      inverted: true
#  - platform: gpio
#    restore_mode: always_off
#    name: "bagrelay_e2_PCF8574 Pin #5"
#    id: b5
#    pin:
#      pcf8574: e2_p
#      number: 5      
#      mode: OUTPUT
#      inverted: true
#  - platform: gpio
#    restore_mode: always_off
#    name: "PCF8574 Pin #6"
#    id: b6
#    pin:
#      pcf8574: e2_p
#      number: 6
#      mode: OUTPUT
#      inverted: true
#  - platform: gpio
#    restore_mode: always_off
#    name: "bagrelay_e2_PCF8574 Pin #7"
#    id: b7
#    pin:
#      pcf8574: e2_p
#      number: 7
#      mode: OUTPUT
#      inverted: true
    


    
  - platform: restart
    name: "OSTROZNIE___RESTART"

sensor:
# commented out due to looking for cause of restarting
#  - platform: wifi_signal
#    name: "esp32 car WiFi signal"
#    update_interval: 300s

  - platform: uptime
    name: "esp32 car uptime"
    update_interval: 300s


  - platform: htu21d
    update_interval: 300s
    i2c_id: e1
    temperature:
        name: "temp"
    humidity:
        name: "hum"     
  - platform: ina3221
    i2c_id: e2
    update_interval: 30s
    address: 0x40
    channel_1:
      shunt_resistance: 0.1 ohm
      current:
        name: "INA3221 Channel 1 Current"
#        state_topic: redacted/feeds/ina31c
#        discovery: False
      power:
        name: "INA3221 Channel 1 Power"
#        state_topic: redacted/feeds/ina31p
#        discovery: False
      bus_voltage:
        name: "INA3221 Channel 1 Bus Voltage"
        on_value_range:
          - above: 6
            then:
            - switch.turn_on: b2
          - below: 1
            then:
              - switch.turn_off: b2
#        state_topic: redacted/feeds/ina31bv
#        discovery: False
      shunt_voltage:
        name: "INA3221 Channel 1 Shunt Voltage"
#        state_topic: redacted/feeds/ina31sv
#        discovery: False
    channel_2:
      shunt_resistance: 0.1 ohm
      current:
        name: "INA3221 Channel 2 Current"
#        state_topic: redacted/feeds/ina32c
#        discovery: False
      power:
        name: "INA3221 Channel 2 Power"
#        state_topic: redacted/feeds/ina32p
#        discovery: False
      shunt_voltage:
        name: "INA3221 Channel 2 Shunt Voltage"
#        state_topic: redacted/feeds/ina32sv
#        discovery: False
      bus_voltage:
        name: "INA3221 Channel 2 Bus Voltage"
#        state_topic: redacted/feeds/ina32bv
#        discovery: False
    channel_3:
      shunt_resistance: 0.1 ohm
      current:
        name: "INA3221 Channel 3 Current"
#        state_topic: redacted/feeds/ina33c
#        discovery: False
      power:
        name: "INA3221 Channel 3 Power"
#        state_topic: ${topic_prefix}/ina33p
#        discovery: False
      bus_voltage:
        name: "INA3221 Channel 3 Bus Voltage"
#        state_topic: ${topic_prefix}/ina33bv
#        discovery: False
      shunt_voltage:
        name: "INA3221 Channel 3 Shunt Voltage"
#        state_topic: ${topic_prefix}/ina33sv
#        discovery: False
i2c:
  - sda: 21
    scl: 22
    id: e1
  - sda: 23
    scl: 5
    id: e2
  
pcf8574:
  - id: 'e1_p'
    i2c_id: e1
    address: 0x21
    pcf8575: False
  - id: 'e2_p'
    i2c_id: e2
    address: 0x22
    pcf8575: False
    
    
    
time:
- platform: sntp
  id: my_time
  
  
  # Status Sensors
output:
  - platform: ledc
    pin: GPIO2
    id: rtttl_out

rtttl:
   output: rtttl_out

Yeah you have enough 5V power but the 3.3V LDO regulators fitted to the cheaper Chinese boards barely have enough current to transmit. So if you are supplying any of the sensors with 3.3V that could be your issue.

Buy quality boards like this one to avoid that isse:

Thank you for fast reply.
What is strange - sometime it is stable - without any reason, it restarts.

I do not use 3,3v anywhere in my circuit. So, if I properly understand I need to power the board by 3,3v through the goldpins?

And yes, will bought better boards in the future… :slight_smile:

Sometimes adding a 100uF and 0.1uF capacitor in parallel from 3.3v to GND, keeping the leads as short as possible is enough to restore stability.

BTW - is that possible that Ive just overloaded the board with many lines of code/features?

No. I’ve seen some huge projects.

1 Like

About capacitor - between 3,3v goldpin on the board AND the GND of all circuit?

Sorry I am newbie…

Yes, between the pins marked 3.3v and GND.

In company trash Ive found few new - packaged !:slight_smile:

and I have connected 5v source to it to get 3.3v which I connected to my esp32 board.
Of course I have disconnected 5v supply from the board.
Unfortunately it still has same problem - resets without any reason.
But…
I am not sure - but I was on long drive. I suppose, that in the time when I have hotspot enabled and the board was connected to it - restarts happened less frequently.
But still restarts… :frowning:
When I had needed to disable hotspot it looked like restarting more frequently.

@tom_l thank you for the link you have provided. It looks very interesting but I would rather use something available in Poland - there is about 30days waiting and - shipping is more expensive than the board… So, I would like to use any HQuality boards, but I totally don’t know which one could be.
Maybe Nodemcu? I don’t know it good.

The reason of choosing the first board was lot of female connectors which, I had supposed, that will be easy in connection. But there was not, so I am ready to almost any board could be available to buy in Poland in official distribution.

I suppose that is only way to test my car things more…

regards