random OSError: I2C bus error with VLX053



  • Hello,

    I am running this library for vl53l0x
    https://bitbucket.org/thesheep/micropython-vl53l0x/src/9077f84e25409532b7ef220fa068605c971ba967/vl53l0x.py?at=default&fileviewer=file-view-default

    and that is what I run as a test

    import time
    import gc 
    from machine import I2C
    import vl53l0x
    
    i2c = I2C(0, I2C.MASTER, baudrate=100000)
    #gc.enable()
    # Initialize I2C bus and sensor.
    vl53 = vl53l0x.VL53L0X(i2c)
    
    
    while True:
        range=vl53.read()
        print(range)
        print("free mem : ")
        print(gc.mem_free())
        
        time.sleep(0.1)
    

    I tried running it in the hardware I2c and in random pins. I tried various delays. I monitored the memory. Whatever I do I just get randomly OSError: I2C bus error that crashes everything, after a few minutes of proper operation.

    Is there a way to bypass the error and not crash?



  • @nalexopo

    Yep I used that library and the pololu breakout board. I can't really give you an exact explanation as to what was going on because I didn't connect the signals to a logic analyser/oscilloscope but the only way I could get the module to start responding was with a full reboot. The sensor is very complex and the library doesn't fully implement everything, and my guess is it doesn't recover from errors very well requiring the full reboot. It works really reliably if I don't fiddle with the wires and make sure it has a clean boot.

    Try lowering your baud rate like I did:

    i2c = I2C(1, pins=('P6', 'P5'), baudrate=5000)
    v = VL53L0X.VL53L0X(i2c)



  • I certainly dont touch wires when it fails as I leave it working on my desk at night. I was testing it with an adafruit break out board as well. Now i am testing it with my own break out board without regulators and level shifter circuits I will see how it is going.

    I have to point out that I already ran the project with the same sensor on stm32 with the official stm C libraries without stability problems. So I guess its not the sensor.

    Do you use the same library as me?



  • @nalexopo

    I have literally just finished a project using this sensor and let me say it is extremely picky.

    I found that the the i2c communication falls over very quickly if you touch any of the wires when its running (and trust me, I painstakingly checked every wire and solder join to make sure it was solid), from that point onward the module seems to fail to respond. The only way to bring it back is to completely unpower the device and try again. I also slowed down the i2c baud rate just in case that made it worse.


Log in to reply
 

Pycom on Twitter