esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

i2c on esp32 only works direclty after an ota update #1132

Closed ChrisOboe closed 3 years ago

ChrisOboe commented 4 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

Docker

ESP (ESP32/ESP8266, Board/Sonoff):

ESP32. It's a liligo tt-higrow (https://github.com/Xinyuan-LilyGO/TTGO-HiGrow)

Affected component:

i2c/bh1750

Description of problem: The bh1750 only works directly after an ota update. It does not work under following conditions:

Problem-relevant YAML-configuration entries:

ota:
  password: "password"

logger:
  level: very_verbose

i2c:
  - id: bus_a
    sda: 25
    scl: 26
    scan: true

sensor:
  - platform: bh1750
    i2c_id: bus_a
    name: "Illuminance"
    address: 0x23
    update_interval: 60s

The YAML is shortened to the relevant parts.

Logs (if applicable):

Here is the run after the ota update:

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
[I][logger:156]: Log initialized
[VV][preferences:038]: LOAD 0: valid=YES, 0=0x00000000 1=0x0DEFE4E3 (Type=233825507, CRC=0x0DEFE4E3)
[C][ota:364]: There have been 0 suspected unsuccessful boot attempts.
[VV][preferences:051]: SAVE 0: 0=0x00000001 1=0x42F4583F (Type=233825507, CRC=0x42F4583F)
[I][app:028]: Running through setup()...
[V][app:029]: Sorting components by setup priority...
[V][esp32-hal-i2c.c:1484] i2cInit(): num=0 sda=25 scl=26 freq=0
[V][esp32-hal-i2c.c:1680] i2cSetFrequency(): freq=100000Hz
[V][esp32-hal-i2c.c:1696] i2cSetFrequency(): cpu Freq=240Mhz, i2c Freq=100000Hz
[V][esp32-hal-i2c.c:1704] i2cSetFrequency(): Fifo delta=1
[V][esp32-hal-i2c.c:1680] i2cSetFrequency(): freq=50000Hz
[V][esp32-hal-i2c.c:1696] i2cSetFrequency(): cpu Freq=240Mhz, i2c Freq=50000Hz
[V][esp32-hal-i2c.c:1704] i2cSetFrequency(): Fifo delta=1
[C][dht:011]: Setting up DHT...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=14043)
[C][adc:018]: Setting up ADC 'Soil'...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=7741)
[C][adc:018]: Setting up ADC 'Salt'...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=18196)
[C][bh1750.sensor:012]: Setting up BH1750 'Illuminance'...
[VV][i2c:056]: Beginning Transmission to 0x23:
[VV][i2c:093]:     Writing 0b00000001 (0x01)
[VV][i2c:061]:     Transmission ended. Status code: 0x00
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=423)
[C][wifi:033]: Setting up WiFi...
[V][wifi_esp32:033]: Enabling STA.
[VV][esp-idf:000]: I (185) wifi: wifi driver task: 3ffb5830, prio:23, stack:3584, core=0
[VV][esp-idf:000]: I (558) wifi: wifi firmware version: 7997e4b
[VV][esp-idf:000]: I (558) wifi: config NVS flash: enabled
[VV][esp-idf:000]: I (560) wifi: config nano formating: disabled
[VV][esp-idf:000]: I (567) wifi: Init dynamic tx buffer num: 32
[VV][esp-idf:000]: I (573) wifi: Init data frame dynamic rx buffer num: 32
[VV][esp-idf:000]: I (581) wifi: Init management frame dynamic rx buffer num: 32
[VV][esp-idf:000]: I (589) wifi: Init management short buffer num: 32
[VV][esp-idf:000]: I (596) wifi: Init static rx buffer size: 1600
[VV][esp-idf:000]: I (603) wifi: Init static rx buffer num: 16
[VV][esp-idf:000]: I (609) wifi: Init dynamic rx buffer num: 32
[VV][esp-idf:000]: I (690) wifi: mode : softAP (fc:f5:c4:0c:f5:95)
[VV][esp-idf:000]: I (691) wifi: Total power save buffer number: 16
[VV][esp-idf:000]: I (693) wifi: Init max length of beacon: 752/752
[VV][esp-idf:000]: I (701) wifi: Init max length of beacon: 752/752
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 14 - AP_STOP
[V][wifi_esp32:357]: Event: WiFi AP start
[V][wifi_esp32:302]: Event: WiFi ready
[VV][esp-idf:000]: I (728) wifi: mode : sta (fc:f5:c4:0c:f5:94)
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
[V][wifi_esp32:311]: Event: WiFi STA start
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
i[VV][esp-idf:000]: I (750) wifi: Set ps type: 1

[D][wifi:304]: Starting scan...
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294889237 (now=415)
[D][adc:056]: 'Salt': Got voltage=0.00V
[V][sensor:013]: 'Salt': Received new state 0.000000
[D][sensor:092]: 'Salt': Sending state 0.00000 V with 2 decimals of accuracy
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294893366 (now=415)
[VV][dht:153]: Data: Hum=0b0001000100000010, Temp=0b0001011100001001, Checksum=0b00110011
[D][dht:048]: Got Temperature=23.0°C Humidity=17.0%
[V][sensor:013]: 'Temperature': Received new state 23.000000
[D][sensor:092]: 'Temperature': Sending state 23.00000 °C with 1 decimals of accuracy
[V][sensor:013]: 'Humidity': Received new state 17.000000
[D][sensor:092]: 'Humidity': Sending state 17.00000 % with 0 decimals of accuracy
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294899680 (now=415)
[D][adc:056]: 'Soil': Got voltage=1.10V
[V][sensor:013]: 'Soil': Received new state 1.100000
[D][sensor:092]: 'Soil': Sending state 1.10000 V with 2 decimals of accuracy
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294907040 (now=415)
[VV][i2c:056]: Beginning Transmission to 0x23:
[VV][i2c:093]:     Writing 0b00100001 (0x21)
[VV][i2c:061]:     Transmission ended. Status code: 0x00
[VV][scheduler:025]: set_timeout(name='illuminance', timeout=180)
[VV][scheduler:131]: Running timeout 'illuminance' with interval=180 last_execution=557 (now=737)
[VV][i2c:083]: Requesting 2 bytes from 0x23:
[VV][i2c:126]:     Received 0b0000000000100011 (0x0023)
[D][bh1750.sensor:071]: 'Illuminance': Got illuminance=29.2lx
[V][sensor:013]: 'Illuminance': Received new state 29.166666
[D][sensor:092]: 'Illuminance': Sending state 29.16667 lx with 1 decimals of accuracy
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 1 - SCAN_DONE
[V][wifi_esp32:307]: Event: WiFi Scan Done status=0 number=5 scan_id=128
[D][wifi:319]: Found networks:
[I][wifi:365]: - 'kendo_2.4' (E4:95:6E:45:11:CA) ▂▄▆█
[D][wifi:366]:     Channel: 1
[D][wifi:367]:     RSSI: -35 dB
[D][wifi:369]: - 'WLED-AP' (CE:50:E3:E8:48:D6) ▂▄▆█
[D][wifi:369]: - 'banzai_2.4' (E4:95:6E:45:11:8A) ▂▄▆█
[D][wifi:369]: - 'UPC5392988' (38:43:7D:A3:6C:ED) ▂▄▆█
[D][wifi:369]: - 'CelenoInitialAP7EDCAE' (1C:3A:DE:7E:DC:AE) ▂▄▆█
[I][wifi:193]: WiFi Connecting to 'kendo_2.4'...
[V][wifi:195]: Connection Params:
[V][wifi:196]:   SSID: 'kendo_2.4'
[V][wifi:199]:   BSSID: E4:95:6E:45:11:CA
[V][wifi:203]:   Password: ''
[V][wifi:205]:   Channel: 1
[V][wifi:215]:   Using DHCP IP
[V][wifi:217]:   Hidden: NO
[VV][esp-idf:000]: I (2672) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1
[VV][esp-idf:000]: I (3410) wifi: state: init -> auth (b0)
[VV][esp-idf:000]: I (3423) wifi: state: auth -> assoc (0)
[VV][esp-idf:000]: I (3434) wifi: state: assoc -> run (10)
[VV][esp-idf:000]: I (3449) wifi: connected with kendo_2.4, channel 1, BW20
[VV][esp-idf:000]: I (3449) wifi: pm start, type: 1

[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 4 - STA_CONNECTED
[V][wifi_esp32:324]: Event: Connected ssid='kendo_2.4' bssid=E4:95:6E:45:11:CA channel=1, authmode=WPA2 PSK
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:381] _eventCallback(): STA IP: 192.168.12.252, MASK: 255.255.255.0, GW: 192.168.12.1
[V][wifi_esp32:349]: Event: Got IP static_ip=192.168.12.252 gateway=192.168.12.1
[I][wifi:423]: WiFi Connected!
[C][wifi:283]:   SSID: 'kendo_2.4'
[C][wifi:284]:   IP Address: 192.168.12.252
[C][wifi:286]:   BSSID: E4:95:6E:45:11:CA
[C][wifi:287]:   Hostname: 'planttest'
[C][wifi:291]:   Signal strength: -31 dB ▂▄▆█
[V][wifi:293]:   Priority: 0.0
[C][wifi:295]:   Channel: 1
[C][wifi:296]:   Subnet: 255.255.255.0
[C][wifi:297]:   Gateway: 192.168.12.1
[C][wifi:298]:   DNS1: 192.168.12.1
[C][wifi:299]:   DNS2: 0.0.0.0
[C][ota:029]: Over-The-Air Updates:
[C][ota:030]:   Address: planttest.local:3232
[C][ota:032]:   Using Password.
[C][api:022]: Setting up Home Assistant API server...
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.3 compiled on Apr  9 2020, 18:37:01
[C][wifi:415]: WiFi:
[C][wifi:283]:   SSID: 'kendo_2.4'
[C][wifi:284]:   IP Address: 192.168.12.252
[C][wifi:286]:   BSSID: E4:95:6E:45:11:CA
[C][wifi:287]:   Hostname: 'planttest'
[C][wifi:291]:   Signal strength: -31 dB ▂▄▆█
[V][wifi:293]:   Priority: 0.0
[C][wifi:295]:   Channel: 1
[C][wifi:296]:   Subnet: 255.255.255.0
[C][wifi:297]:   Gateway: 192.168.12.1
[C][wifi:298]:   DNS1: 192.168.12.1
[C][wifi:299]:   DNS2: 0.0.0.0
[C][i2c:028]: I2C Bus:
[C][i2c:029]:   SDA Pin: GPIO25
[C][i2c:030]:   SCL Pin: GPIO26
[C][i2c:031]:   Frequency: 50000 Hz
[I][i2c:033]: Scanning i2c bus for active devices...
[I][i2c:040]: Found i2c device at address 0x23
[C][gpio.output:010]: GPIO Binary Output:
[C][gpio.output:011]:   Pin: GPIO4 (Mode: OUTPUT)
[C][logger:175]: Logger:
[C][logger:176]:   Level: VERY_VERBOSE
[C][logger:177]:   Log Baud Rate: 115200
[C][logger:178]:   Hardware UART: UART0
[C][dht:017]: DHT:
[C][dht:018]:   Pin: GPIO16 (Mode: INPUT)
[C][dht:022]:   Model: DHT11
[C][dht:027]:   Update Interval: 60.0s
[C][dht:029]:   Temperature 'Temperature'
[C][dht:029]:     Unit of Measurement: '°C'
[C][dht:029]:     Accuracy Decimals: 1
[C][dht:029]:     Icon: 'mdi:thermometer'
[C][dht:030]:   Humidity 'Humidity'
[C][dht:030]:     Unit of Measurement: '%'
[C][dht:030]:     Accuracy Decimals: 0
[C][dht:030]:     Icon: 'mdi:water-percent'
[C][adc:026]: ADC Sensor 'Soil'
[C][adc:026]:   Unit of Measurement: 'V'
[C][adc:026]:   Accuracy Decimals: 2
[C][adc:026]:   Icon: 'mdi:flash'
[C][adc:035]:   Pin: 32
[C][adc:038]:  Attenuation: 0db (max 1.1V)
[C][adc:051]:   Update Interval: 60.0s
[C][adc:026]: ADC Sensor 'Salt'
[C][adc:026]:   Unit of Measurement: 'V'
[C][adc:026]:   Accuracy Decimals: 2
[C][adc:026]:   Icon: 'mdi:flash'
[C][adc:035]:   Pin: 34
[C][adc:038]:  Attenuation: 0db (max 1.1V)
[C][adc:051]:   Update Interval: 60.0s
[C][bh1750.sensor:019]: BH1750 'Illuminance'
[C][bh1750.sensor:019]:   Unit of Measurement: 'lx'
[C][bh1750.sensor:019]:   Accuracy Decimals: 1
[C][bh1750.sensor:019]:   Icon: 'mdi:brightness-5'
[C][bh1750.sensor:020]:   Address: 0x23
[C][bh1750.sensor:040]:   Resolution: 0.5
[C][bh1750.sensor:041]:   Update Interval: 60.0s

Here is the log after i power off the device and power it on again:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
[I][logger:156]: Log initialized
[VV][preferences:038]: LOAD 0: valid=YES, 0=0x00000001 1=0x42F4583F (Type=233825507, CRC=0x42F4583F)
[C][ota:364]: There have been 1 suspected unsuccessful boot attempts.
[VV][preferences:051]: SAVE 0: 0=0x00000002 1=0x13D89D5A (Type=233825507, CRC=0x13D89D5A)
[I][app:028]: Running through setup()...
[V][app:029]: Sorting components by setup priority...
[V][esp32-hal-i2c.c:1484] i2cInit(): num=0 sda=25 scl=26 freq=0
[V][esp32-hal-i2c.c:1680] i2cSetFrequency(): freq=100000Hz
[V][esp32-hal-i2c.c:1696] i2cSetFrequency(): cpu Freq=240Mhz, i2c Freq=100000Hz
[V][esp32-hal-i2c.c:1704] i2cSetFrequency(): Fifo delta=1
[W][esp32-hal-i2c.c:1411] i2cCheckLineState(): invalid state sda(25)=0, scl(26)=0
[E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=0, scl=0
[C][dht:011]: Setting up DHT...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=29431)
[C][adc:018]: Setting up ADC 'Soil'...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=22558)
[C][adc:018]: Setting up ADC 'Salt'...
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=13524)
[C][bh1750.sensor:012]: Setting up BH1750 'Illuminance'...
[VV][i2c:056]: Beginning Transmission to 0x23:
[VV][i2c:093]:     Writing 0b00000001 (0x01)
[VV][i2c:061]:     Transmission ended. Status code: 0x01
[W][i2c:067]: Too much data to fit in transmitter buffer for address 0x23
[E][component:092]: Component was marked as failed.
[VV][scheduler:056]: set_interval(name='update', interval=60000, offset=4720)
[C][wifi:033]: Setting up WiFi...
[V][wifi_esp32:033]: Enabling STA.
[VV][esp-idf:000]: I (197) wifi: wifi driver task: 3ffb578c, prio:23, stack:3584, core=0
[VV][esp-idf:000]: I (582) wifi: wifi firmware version: 7997e4b
[VV][esp-idf:000]: I (582) wifi: config NVS flash: enabled
[VV][esp-idf:000]: I (584) wifi: config nano formating: disabled
[VV][esp-idf:000]: I (591) wifi: Init dynamic tx buffer num: 32
[VV][esp-idf:000]: I (597) wifi: Init data frame dynamic rx buffer num: 32
[VV][esp-idf:000]: I (605) wifi: Init management frame dynamic rx buffer num: 32
[VV][esp-idf:000]: I (613) wifi: Init management short buffer num: 32
[VV][esp-idf:000]: I (620) wifi: Init static rx buffer size: 1600
[VV][esp-idf:000]: I (627) wifi: Init static rx buffer num: 16
[VV][esp-idf:000]: I (633) wifi: Init dynamic rx buffer num: 32
[VV][esp-idf:000]: I (713) wifi: mode : softAP (fc:f5:c4:0c:f5:95)
[VV][esp-idf:000]: I (715) wifi: Total power save buffer number: 16
[VV][esp-idf:000]: I (717) wifi: Init max length of beacon: 752/752
[VV][esp-idf:000]: I (724) wifi: Init max length of beacon: 752/752
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 14 - AP_STOP
[V][wifi_esp32:357]: Event: WiFi AP start
[V][wifi_esp32:302]: Event: WiFi ready
[VV][esp-idf:000]: I (752) wifi: mode : sta (fc:f5:c4:0c:f5:94)
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
[V][wifi_esp32:311]: Event: WiFi STA start
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
[[VV][esp-idf:000]: I (774) wifi: Set ps type: 1

[D][wifi:304]: Starting scan...
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294877976 (now=427)
[VV][dht:153]: Data: Hum=0b0001000100000011, Temp=0b0001100100000000, Checksum=0b00101101
[D][dht:048]: Got Temperature=25.0°C Humidity=17.0%
[V][sensor:013]: 'Temperature': Received new state 25.000000
[D][sensor:092]: 'Temperature': Sending state 25.00000 °C with 1 decimals of accuracy
[V][sensor:013]: 'Humidity': Received new state 17.000000
[D][sensor:092]: 'Humidity': Sending state 17.00000 % with 0 decimals of accuracy
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294884862 (now=427)
[D][adc:056]: 'Soil': Got voltage=1.10V
[V][sensor:013]: 'Soil': Received new state 1.100000
[D][sensor:092]: 'Soil': Sending state 1.10000 V with 2 decimals of accuracy
[VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=4294893908 (now=427)
[D][adc:056]: 'Salt': Got voltage=0.00V
[V][sensor:013]: 'Salt': Received new state 0.000000
[D][sensor:092]: 'Salt': Sending state 0.00000 V with 2 decimals of accuracy
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 1 - SCAN_DONE
[V][wifi_esp32:307]: Event: WiFi Scan Done status=0 number=5 scan_id=128
[D][wifi:319]: Found networks:
[I][wifi:365]: - 'kendo_2.4' (E4:95:6E:45:11:CA) ▂▄▆█
[D][wifi:366]:     Channel: 1
[D][wifi:367]:     RSSI: -39 dB
[D][wifi:369]: - 'banzai_2.4' (E4:95:6E:45:11:8A) ▂▄▆█
[D][wifi:369]: - 'WLED-AP' (CE:50:E3:E8:48:D6) ▂▄▆█
[D][wifi:369]: - 'FRITZ!Box 7590 ZP' (DC:39:6F:70:F0:F4) ▂▄▆█
[D][wifi:369]: - 'CelenoInitialAP7EDCAE' (1C:3A:DE:7E:DC:AE) ▂▄▆█
[I][wifi:193]: WiFi Connecting to 'kendo_2.4'...
[V][wifi:195]: Connection Params:
[V][wifi:196]:   SSID: 'kendo_2.4'
[V][wifi:199]:   BSSID: E4:95:6E:45:11:CA
[V][wifi:203]:   Password: ''
[V][wifi:205]:   Channel: 1
[V][wifi:215]:   Using DHCP IP
[V][wifi:217]:   Hidden: NO
[VV][esp-idf:000]: I (2695) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1
[VV][esp-idf:000]: I (3431) wifi: state: init -> auth (b0)
[VV][esp-idf:000]: I (3446) wifi: state: auth -> assoc (0)
[VV][esp-idf:000]: I (3452) wifi: state: assoc -> run (10)
[VV][esp-idf:000]: I (3474) wifi: connected with kendo_2.4, channel 1, BW20
[VV][esp-idf:000]: I (3475) wifi: pm start, type: 1

[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 4 - STA_CONNECTED
[V][wifi_esp32:324]: Event: Connected ssid='kendo_2.4' bssid=E4:95:6E:45:11:CA channel=1, authmode=WPA2 PSK
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:381] _eventCallback(): STA IP: 192.168.12.252, MASK: 255.255.255.0, GW: 192.168.12.1
[V][wifi_esp32:349]: Event: Got IP static_ip=192.168.12.252 gateway=192.168.12.1
[I][wifi:423]: WiFi Connected!
[C][wifi:283]:   SSID: 'kendo_2.4'
[C][wifi:284]:   IP Address: 192.168.12.252
[C][wifi:286]:   BSSID: E4:95:6E:45:11:CA
[C][wifi:287]:   Hostname: 'planttest'
[C][wifi:291]:   Signal strength: -36 dB ▂▄▆█
[V][wifi:293]:   Priority: 0.0
[C][wifi:295]:   Channel: 1
[C][wifi:296]:   Subnet: 255.255.255.0
[C][wifi:297]:   Gateway: 192.168.12.1
[C][wifi:298]:   DNS1: 192.168.12.1
[C][wifi:299]:   DNS2: 0.0.0.0
[C][ota:029]: Over-The-Air Updates:
[C][ota:030]:   Address: planttest.local:3232
[C][ota:032]:   Using Password.
[C][api:022]: Setting up Home Assistant API server...
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.3 compiled on Apr  9 2020, 18:37:01
[C][wifi:415]: WiFi:
[C][wifi:283]:   SSID: 'kendo_2.4'
[C][wifi:284]:   IP Address: 192.168.12.252
[C][wifi:286]:   BSSID: E4:95:6E:45:11:CA
[C][wifi:287]:   Hostname: 'planttest'
[C][wifi:291]:   Signal strength: -33 dB ▂▄▆█
[V][wifi:293]:   Priority: 0.0
[C][wifi:295]:   Channel: 1
[C][wifi:296]:   Subnet: 255.255.255.0
[C][wifi:297]:   Gateway: 192.168.12.1
[C][wifi:298]:   DNS1: 192.168.12.1
[C][wifi:299]:   DNS2: 0.0.0.0
[C][i2c:028]: I2C Bus:
[C][i2c:029]:   SDA Pin: GPIO25
[C][i2c:030]:   SCL Pin: GPIO26
[C][i2c:031]:   Frequency: 50000 Hz
[I][i2c:033]: Scanning i2c bus for active devices...
[I][i2c:049]: Found no i2c devices!
[C][gpio.output:010]: GPIO Binary Output:
[C][gpio.output:011]:   Pin: GPIO4 (Mode: OUTPUT)
[C][logger:175]: Logger:
[C][logger:176]:   Level: VERY_VERBOSE
[C][logger:177]:   Log Baud Rate: 115200
[C][logger:178]:   Hardware UART: UART0
[C][dht:017]: DHT:
[C][dht:018]:   Pin: GPIO16 (Mode: INPUT)
[C][dht:022]:   Model: DHT11
[C][dht:027]:   Update Interval: 60.0s
[C][dht:029]:   Temperature 'Temperature'
[C][dht:029]:     Unit of Measurement: '°C'
[C][dht:029]:     Accuracy Decimals: 1
[C][dht:029]:     Icon: 'mdi:thermometer'
[C][dht:030]:   Humidity 'Humidity'
[C][dht:030]:     Unit of Measurement: '%'
[C][dht:030]:     Accuracy Decimals: 0
[C][dht:030]:     Icon: 'mdi:water-percent'
[C][adc:026]: ADC Sensor 'Soil'
[C][adc:026]:   Unit of Measurement: 'V'
[C][adc:026]:   Accuracy Decimals: 2
[C][adc:026]:   Icon: 'mdi:flash'
[C][adc:035]:   Pin: 32
[C][adc:038]:  Attenuation: 0db (max 1.1V)
[C][adc:051]:   Update Interval: 60.0s
[C][adc:026]: ADC Sensor 'Salt'
[C][adc:026]:   Unit of Measurement: 'V'
[C][adc:026]:   Accuracy Decimals: 2
[C][adc:026]:   Icon: 'mdi:flash'
[C][adc:035]:   Pin: 34
[C][adc:038]:  Attenuation: 0db (max 1.1V)
[C][adc:051]:   Update Interval: 60.0s
[C][bh1750.sensor:019]: BH1750 'Illuminance'
[C][bh1750.sensor:019]:   Unit of Measurement: 'lx'
[C][bh1750.sensor:019]:   Accuracy Decimals: 1
[C][bh1750.sensor:019]:   Icon: 'mdi:brightness-5'
[C][bh1750.sensor:020]:   Address: 0x23
[E][bh1750.sensor:022]: Communication with BH1750 failed!
[C][bh1750.sensor:040]:   Resolution: 0.5
[C][bh1750.sensor:041]:   Update Interval: 60.0s

Additional information and things you've tried: I tried a lot of different stuff in the last two days.

Switching between different arduino frameworks did not help.

Changing the frequency of the i2c bus did not help either.

Also i naively thought that maybe the startup is too fast and it tries to communicate with the bh1750 and the bh1750 is not powered (i don't know a lot about electronics and don't know how this device is wired). This would explain that it works after an ota update but not after an power cycle.

I tested my assumption with adding a long delay on the boot (before i2c gets initialized) so enough time is there that the bh1750 is powered. But it still did not work. So my assumption was wrong.

I also searched a lot about simliar issues with the esp32 and the i2c and tested everything that was proposed, but nothing helped.

I'm running out of ideas what to try. But i'm still pretty optimistic to get it running, since it definetly works fine after an ota update.

Thats why i'm writing this issue, in the hope that we can get this running.

randybb commented 4 years ago

I don't have any issue with i2c, but I have a feeling you have have a problem with it's stability - do you have pull-up resistors on i2c bus?

ChrisOboe commented 4 years ago

I don't know. It's pre-build hardware and there is no electrical wiring diagram available. Also i'm not able to measure it directly, since the smd parts are just too small (at least for the tools i have available). And i don't know other ways how i could find this out.

Also it's not random. I can always reproduce this. It works correctly after the ota update (and i tested it about 20 times). And it never works without it. Also when it works via the update, it works fine for at least an hour (i never tested it longer).

I think, when it would be a general stability issue, it would be more random.

Goganovic commented 4 years ago

I have exactly same problem. Changing i2c speed, delaying boot not helped. Only work after OTA, till next button reset or power down.

ievren commented 4 years ago

[V][esp32-hal-i2c.c:1484] i2cInit(): num=0 sda=25 scl=26 freq=0 [V][esp32-hal-i2c.c:1680] i2cSetFrequency(): freq=100000Hz [V][esp32-hal-i2c.c:1696] i2cSetFrequency(): cpu Freq=240Mhz, i2c Freq=100000Hz [V][esp32-hal-i2c.c:1704] i2cSetFrequency(): Fifo delta=1 [W][esp32-hal-i2c.c:1411] i2cCheckLineState(): invalid state sda(25)=0, scl(26)=0 [E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=0, scl=0

in the log of Here is the log after i power off the device and power it on again: There is a error in your Bus: [E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=0, scl=0

Maybe this is a similar problem like this one: _ESPHome puts SHTC3 sensors to sleep between measurements. While asleep the sensor will only respond to a wake up command. All other commands, including a soft reset are ignored (it even ignores an I2C general call reset). This is problematic if ESPHome is rebooted between measurements, since the sensor will still be asleep when it tries to set it up again after the reboot. For example, doing an OTA update will usually cause the sensor to remain "failed" until power is cycled, because the OTA process will reboot while the sensor is still asleep.

So the trivial fix to this is to send a wake up command during setup() before anything else to make sure it's awake. For me, this fixes SHTC3 sensors "failing" after most OTA updates._ https://github.com/esphome/esphome/pull/993

ievren commented 4 years ago

for the SHTC3 it works adding wake_up in the setup() in the file esphome/components/shtcx/shtcx.cpp

void SHTCXComponent::setup() { ESP_LOGCONFIG(TAG, "Setting up SHTCx..."); ESP_LOGCONFIG(TAG, "Setting up SHTCx..."); this->wake_up(); this->soft_reset(); this->soft_reset();

if (!this->writecommand(SHTCX_COMMAND_READ_ID_REGISTER)) { if (!this->writecommand(SHTCX_COMMAND_READ_ID_REGISTER)) {

but in your component this is missing? @ChrisOboe maybe you can try to edit to something like this: https://github.com/esphome/esphome/blob/dev/esphome/components/shtcx/shtcx.cpp Your component: https://github.com/esphome/esphome/blob/dev/esphome/components/bh1750/bh1750.cpp

glmnet commented 4 years ago

Is this a component that sleeps like the shtc3?

austrisv commented 4 years ago

Ohh, happy to see I'm not alone with the problem. Using the same LilyGO TTGO-HiGrow board. Original Arduino code is working fine with all sensors. dht11 and moisture/salt are working with esphome. But can not make i2c and bh1750 to work with esphome:(

If it helps ... when trying to make blank arduino sketch just for bh1750, I found that the initialization will fail unless I have previous attempt of bme280 init (which I don't have even connected to the board).

#include <Wire.h>
#include <BH1750.h>
#include <Adafruit_BME280.h>

#define POWER_CTRL          4
#define I2C_SDA             25
#define I2C_SCL             26

BH1750 lightMeter(0x23); //0x23
Adafruit_BME280 bmp;     //0x77

void setup() {
  Wire.begin(I2C_SDA, I2C_SCL);

  Serial.begin(115200); 

    pinMode(POWER_CTRL, OUTPUT);
    digitalWrite(POWER_CTRL, 1);
    delay(1000);

     if (!bmp.begin()) {
        Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    } 
    if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
        Serial.println(F("BH1750 Advanced begin"));
    } else {
        Serial.println(F("Error initialising BH1750"));
    }
}

e.g. in the above code, w.out bmp.begin the lightMeter always ends up with error. If I do bmp.begin (which gives error) then lightMeter gives the 'Advanced begin' .

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

MRocketscience commented 3 years ago

wire here you go guys. solved it! :D it seems that the power line for the sensors doesn´t get enough power.