Error when i use two i2c sensors ESP32 DevKitC


#1

When i try to use 2 proximity sensors vcnl4010 with i2c, the program crashes in casual moments.
The error is:

Persons:/tmp/tmp3w89rsqk/r2.1.1/common/vos/esp32-rtos/esp-idf-v3.0-rc1/components/freertos/./queue.c:1445 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40085e6c on core 0
Backtrace: 0x4008939f:0x3ffdd390 0x400893cb:0x3ffdd3b0 0x40085e6c:0x3ffdd3d0 0x40085fa9:0x3ffdd410 0x4008324f:0x3ffdd430 0x4008333d:0x3ffdd470 0x4012e87f:0x3ffdd490 0x4012a63d:0x3ffdd750 0x4012a5c5:0x3ffdd7a0 0x400867a5:0x3ffdd7d0 0x40088a39:0x3ffdd7f0 0x40088b01:0x3ffdd810 0x40087d98:0x3ffdd830

The code that gives an error is:

import streams
import i2c
from espressif.esp32net import esp32wifi as wifi_driver
from wireless import wifi

streams.serial()
sleep(5000)
try:
    print("Init I2C")
    bus_1 = i2c.I2C(I2C0, 0x13)
    bus_2 = i2c.I2C(I2C1, 0x13)
    print("Configure I2C")
    bus_1.start()
    bus_1.write([0x80, 0x07])
    bus_1.write([0x82, 0x00])
    bus_1.write([0x84, 0x9D])
    bus_1.stop()
    
    bus_2.start()
    bus_2.write([0x80, 0x07])
    bus_2.write([0x82, 0x00])
    bus_2.write([0x84, 0x9D])
    bus_2.stop()
    
    print("Init WI-FI")
    wifi_driver.auto_init()
    print("Establishing wifi Link...")
    for i in range(0,5):
        try:
            wifi.link("WifiName",wifi.WIFI_WPA2,"Password") #Insert value for connection
            print("wifi Link Established")
            break
        except Exception as e:
            print("Can't link",e)
    else:
        print("Impossible to link!")
        while True:
            sleep(1000)
            
    persons = 0
    exit = False
    enter = False
    
    while True:
            
        bus_1.start()
        data1 = bus_1.write_read(0x85, 4)#Read values from proximity/light sensor
        bus_1.stop()
        
        bus_2.start()
        data2 = bus_2.write_read(0x85, 4)
        bus_2.stop()
        
        if (not enter) and (not exit): # if no pir triggered check for pir to be triggered
            pr1_state = data1[2] * 256 + data1[3]
            if pr1_state > 2500:
                enter = True
                print("Enter ON")
                print("Proximity of the Device 1: ",pr1_state)
            
            pr2_state = data2[2] * 256 + data2[3]
            
            if pr2_state > 2500 and persons > 0:
                exit = True
                print("Exit ON")
                print("Proximity of the Device 2: ", pr2_state)
                
        elif enter: # if enter pir triggered check for pir 2 to be triggered
            pr2_state = data2[2] * 256 + data2[3]
            
            if pr2_state > 2500:
                persons += 1
                enter = False
                print("Person enter")
            
        elif exit:# if exit pir triggered check for pir 1 to be triggered
            pr1_state = data1[2] * 256 + data1[3]
            
            if pr1_state > 2500:
                persons -= 1
                if persons == 0:
                    exit = False
                print("Person exit")
                
        print("Persons:", persons)
        sleep(500)
except Exception as e:
    print(e)

#2

Hi @CrysK,

there is no need to start and stop the i2c bus after each write or read operation.
Could you try to do a single start after i2c instance creation and tell me if the program still crashes?


#3

i’ve just tried, but in this way don’t work becouse he read only the first sensor