Multiple VL53L1X pololu sensors on the same i2c bus cause Core 1 panic'ed Error on ESP32

Hi all,

I am trying to setup and read 2 VL53L1X sensors on an esp32. I am trying to set the adr of the sensors to 0x30, and reset one of them, so its i2c adr goes back to the default ox29, as explained here.

When I run my program, I get this error printed continuoously

Backtrace: 0x400d12a4:0x3ffb1f20 0x400d14eb:0x3ffb1f40 0x400d1525:0x3ffb1f60 0x400d0d89:0x3ffb1f80 0x400d3752:0x3ffb1fb0 0x40086a75:0x3ffb1fd0

Rebooting…

�
�␜ޠ��J��1���␘s�␌�␌�
���Guru Meditation Error: Core  1 panic'ed (IntegerDivideByZero). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d12a4  PS      : 0x00060930  A0      : 0x800d14ee  A1      : 0x3ffb1f20  
A2      : 0x40000000  A3      : 0x000000ff  A4      : 0x3ffc0038  A5      : 0x00000001  
A6      : 0x00060520  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb1f00  
A10     : 0xffffffff  A11     : 0x00000029  A12     : 0x00000001  A13     : 0x00000001  
A14     : 0x00000000  A15     : 0x3ffb0060  SAR     : 0x0000001c  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

Here is my code. I dont understand what can cause this, how am I dividing an int by 0 here??

#include <Arduino.h>

#include <VL53L1X.h>

#include <Wire.h>

VL53L1X Lsensor;

VL53L1X Rsensor;

#define VL53L1X_DEFAULT_ADR (0x29)

#define LEFT_VL53L1X_ADR (VL53L1X_DEFAULT_ADR)   // default adr is reset

#define LEFT_VL53L1X_XSHUT_PIN (34)

#define RIGHT_VL53L1X_ADR (0x30)

#define RIGHT_VL53L1X_XSHUT_PIN (-1)

void setup(void)

{

  Serial.begin(9600);

  Wire.begin();

  Wire.setClock(400000); // use 400 kHz I2C

  pinMode(LEFT_VL53L1X_XSHUT_PIN, OUTPUT);

  digitalWrite(LEFT_VL53L1X_XSHUT_PIN, HIGH);

  

  Rsensor.setAddress(RIGHT_VL53L1X_ADR);

  delay(10); 

  digitalWrite(LEFT_VL53L1X_XSHUT_PIN, LOW);

  delay(10); 

  Lsensor.init();

  Lsensor.setTimeout(500);

  Lsensor.setDistanceMode(VL53L1X::Long);

  Lsensor.setMeasurementTimingBudget(50000);

  Lsensor.startContinuous(50);

  Rsensor.init();

  Rsensor.setTimeout(500);

  Rsensor.setDistanceMode(VL53L1X::Long);

  Rsensor.setMeasurementTimingBudget(50000);

  Rsensor.startContinuous(50);

}

void loop()

{

  Serial.print("reading L ");

  Serial.println(Lsensor.read());

  Serial.print("reading R ");

  Serial.println(Rsensor.read());

  delay(500);

}

Hm at first glance I don’t, either.

Please add the following to the platformio.ini:

monitor_filters = esp32_exception_decoder
build_type = debug
monitor_speed = 115200

while modifying the Serial.begin(9600); to Serial.begin(115200); (to keep the application messages baud and bootloader / panic baud the same); this should enable the backtrace to be decoded to human-readable form and show the line of error. (docs, docs).

Thank you, I added the .ini args, I have been too lazy to setup the debugger for my env…

I finally had it working last night. I do not directly understand what was wrong, it seems like the timing is important between resetting the sensor, changing the adr, and other initializing functions. Here is a function I use that lets me operate and use .read() from both sensors on the same i2c bus (Its part of a class I created, but you just need to remove this from the fct and change pointers to objects.)

int8_t TOF::init()

{

  Wire.begin();

  Wire.setClock(400000); // use 400 kHz I2C

  _leftSensor->setTimeout(500);

  // Toggle XSHUT pins to reset the sensors

  pinMode(_rightShutPin, OUTPUT);

  pinMode(_leftShutPin, OUTPUT);

  pinMode(_rightShutPin, INPUT);

  pinMode(_leftShutPin, INPUT);

  if (!_leftSensor->init())

  {

    return -1;

  }

  _leftSensor->setAddress(42);

  pinMode(_rightShutPin, OUTPUT);

  pinMode(_rightShutPin, INPUT);

  _rightSensor->setTimeout(500);

  if (!_rightSensor->init())

  {

    return -1;

  }

  _rightSensor->setDistanceMode(VL53L1X::Long);

  _rightSensor->setMeasurementTimingBudget(50000);

  _rightSensor->startContinuous(50);

  _leftSensor->setDistanceMode(VL53L1X::Long);

  _leftSensor->setMeasurementTimingBudget(50000);

  _leftSensor->startContinuous(50);

  return 0;

}
1 Like