esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
15.96k stars 13.34k forks source link

I2C VL53L0X Sensors cause WDT resets #7270

Closed martin072 closed 4 years ago

martin072 commented 4 years ago

Basic Infos

Platform

Settings in IDE

Problem Description

I have a system that utilises 2 VL53L0X sensors. This works fine for the majority of time, but after around 20 hours till 2 days (varying), the ESP resets due to Software a WDT, I've managed to do a stack trace, and this is the result:

    PC: 0x40100529: Twi::busywait(unsigned char) at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_si2c.cpp line 271
    EXCVADDR: 0x00000000

    Decoding stack results
    0x40218f25: Twi::readFrom(unsigned char, unsigned char*, unsigned int, unsigned char) at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_si2c.cpp line 405
    0x4010083e: millis() at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_wiring.cpp line 188
    0x4021913c: twi_readFrom(unsigned char, unsigned char*, unsigned int, unsigned char) at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_si2c.cpp line 1042
    0x402090b0: TwoWire::requestFrom(unsigned char, unsigned int, bool) at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/Wire/Wire.cpp line 129
    0x402090dc: TwoWire::requestFrom(unsigned char, unsigned char) at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/Wire/Wire.cpp line 143
    0x402140eb: VL53L0X::readReg(unsigned char) at /Users/martin/Documents/Arduino/libraries/vl53l0x-arduino-1.02/VL53L0X.cpp line 322
    0x40214442: VL53L0X::readRangeContinuousMillimeters() at /Users/martin/Documents/Arduino/libraries/vl53l0x-arduino-1.02/VL53L0X.cpp line 816
    0x40201f00: readVLXSensors() at /Users/martin/Documents/Arduino/TEST_WS2812/TEST_WS2812.ino line 674
    0x402083c7: loop() at /Users/martin/Documents/Arduino/TEST_WS2812/TEST_WS2812.ino line 596
    0x40218404: loop_wrapper() at /Users/martin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_main.cpp line 172

This is the function that reads the sensors (initiated from the main loop):

    void readVLXSensors() {

      if (readTop) {
        distSensorTop_distance = distSensorTop.readRangeContinuousMillimeters();
        if (distSensorTop.timeoutOccurred()) {
          distSensorTop_distance = 99999;
        }
        readTop = !readTop;

      } else {
        distSensorBottom_distance = distSensorBottom.readRangeContinuousMillimeters();

        if (distSensorBottom.timeoutOccurred()) {
          distSensorBottom_distance = 99999;
        }
        readTop = !readTop;
      }

    }

As you can see as last desperate measure, I alternate the reading of the sensors, where as before I just read both sensors after each other. But even this approach still gives the WDT resets.

Any one an approach on this one?

Tech-TX commented 4 years ago

I have that VL53L0X sensor and have seen bad initialization code for it in some demo code (while... without yield) that may cause WDTs. However, that's your app or the 3rd party library for the sensor, and not the Wire library at fault. Nothing in the I2C library is causing it.

devyte commented 4 years ago

At a glance, I see ReadRangeContinuousBlah() has a while loop without yield. It's pretty obvious. Closing due to not a core issue.

martin072 commented 4 years ago

Many thanks for the quick responses. Will dig a bit further

gururajcs commented 6 months ago

Many thanks for the quick responses. Will dig a bit further

Martin072, I was trying to setup my ESP12F with OLED1306 and VL53L0X to i2c. I had similar issue (ie. Soft WDT reset, Exception (4) and exactly same stack strace you have posted above). I added delay/yield in the VL53L0X.cpp file in various places with the hint from stacktraces. Then started getting WDT reset issue at Adafruit_SSD1306::display() Stack trace: display() -> TwoWire::endTransmission->Adafruit_SSD1306::ssd1306_commandList->Twi::writeTo->Twi::write_byte->Twi::busywait

Atlast I used another Library for SSD1306 as provided by in this example Create a height measuring device by combining ESP8266, VL53L0X, and MPU6050...It started working without any issue.

I know its been long for this reply. But thought it will help if someone search for this issue and lands into this page.