I March 2025 I last time worked on a little project that operated 5 TOF-sensors. Today I dealt again with it after updating the IDE and libraries. And after recompiling the project doesn’t provide the expected results. I suspect the Adafruit_VL53L0X library.
What has changed mainly is the Adafruit_VL53L0X library. I just updated the library not testing the program before and freezing the state of libraries used for the project last time it worked.
I first tried the latest Adafruit_VL53L0X (1.2.4) and after that was failing, I installed 1.2.2, the previous version, not being sure that this is the one the app was compiled with when it was last time working. I could well be, that it contains a programming bug that just reveils now. I’m posting the code FWIW below.
#include "Adafruit_VL53L0X.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define XSHUT_5 19
#define XSHUT_4 18
#define XSHUT_3 17
#define XSHUT_2 16
#define XSHUT_1 15
#define LX_ADDR_1 0x30
#define LX_ADDR_2 0x31
#define LX_ADDR_3 0x32
#define LX_ADDR_4 0x33
#define LX_ADDR_5 0x34
#define N_SENSORS 5
/* meine 5 Sensoren */
Adafruit_VL53L0X lox1 ;
Adafruit_VL53L0X lox2 ;
Adafruit_VL53L0X lox3 ;
Adafruit_VL53L0X lox4 ;
Adafruit_VL53L0X lox5 ;
struct {
Adafruit_VL53L0X *lox; // Sensor handle
uint8_t address; // gewünschte Sensoradresse
uint8_t xshut_pin;// pin am ESP32 zum XSHUT
} lox[N_SENSORS]= {
{&lox1,LX_ADDR_1,XSHUT_1},
{&lox2,LX_ADDR_2,XSHUT_2},
{&lox3,LX_ADDR_3,XSHUT_3},
{&lox4,LX_ADDR_4,XSHUT_4},
{&lox5,LX_ADDR_5,XSHUT_5}
};
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
char str[128];
void setup() {
Serial.begin(115200);
int i,j;
// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}
/* shut them all down */
Serial.println("Adafruit VL53L0X test - shutting down sensors");
for(i=0 ; i< N_SENSORS ; i++) {
digitalWrite(lox[i].xshut_pin,0);
delay(10);
}
Serial.println(F("VL53L0X schalte Sensoren ein und setze Adresse\n\n"));
digitalWrite(XSHUT_1,1); // schalte Sensor ein
delay(10);
if (!lox1.begin(LX_ADDR_1)) { // setze Adresse und starte Sensor
Serial.println(F("Failed to boot VL53L0X 1"));
//while(1); /* hang here forever /
}
digitalWrite(XSHUT_2,1); // schalte Sensor ein
if (!lox2.begin(LX_ADDR_2)) { // setze Adresse und starte Sensor
Serial.println(F("Failed to boot VL53L0X 2"));
//while(1); / hang here forever /
}
digitalWrite(XSHUT_3,1); // schalte Sensor ein
if(!lox3.begin(LX_ADDR_3)) { // setze Adresse und starte Sensor
Serial.println(F("Failed to boot VL53L0X 3"));
//while(1); / hang here forever /
}
digitalWrite(XSHUT_4,1); // schalte Sensor ein
if(!lox4.begin(LX_ADDR_4)) { // setze Adresse und starte Sensor
Serial.println(F("Failed to boot VL53L0X 4"));
//while(1); / hang here forever /
}
digitalWrite(XSHUT_5,1); // schalte Sensor ein
if(!lox5.begin(LX_ADDR_5)) { // setze Adresse und starte Sensor
Serial.println(F("Failed to boot VL53L0X 5"));
//while(1); / hang here forever */
}
Serial.println("all sensors done...");
// power
Serial.println(F("VL53L0X Adressen initialisiert\n"));
delay(250); // wait for the OLED to power up
display.begin(i2c_Address, true); // Address 0x3C default
display.display();
delay(1000);
display.clearDisplay();
display.display();
}
void loop() {
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;
VL53L0X_RangingMeasurementData_t measure3;
VL53L0X_RangingMeasurementData_t measure4;
VL53L0X_RangingMeasurementData_t measure5;
int i;
Serial.print("Reading a measurement...\n");
lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!
lox3.rangingTest(&measure3, false); // pass in 'true' to get debug data printout!
lox4.rangingTest(&measure4, false); // pass in 'true' to get debug data printout!
lox5.rangingTest(&measure5, false); // pass in 'true' to get debug data printout!
if (measure1.RangeStatus != 4) { // phase failures have incorrect data
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.fillRect(0,0,120,20,SH110X_BLACK);
sprintf(str,"Abstand: %04d mm",measure1.RangeMilliMeter);
display.println(str);
display.display();
delay(100);
} else {
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.fillRect(0,0,120,20,SH110X_BLACK);
sprintf(str,"Abstand: ---- mm",measure1.RangeMilliMeter);
display.println(str);
display.display();
delay(100);
}
}
Program output:
Rebooting...
ets Jul 29 2019 12:21:46
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:1
load:0x3fff0030,len:4980
load:0x40078000,len:16612
load:0x40080400,len:3500
entry 0x400805b4
Adafruit VL53L0X test - shut down
VL53L0X schalte Sensoren ein und setze Adresse
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400f4eeb PS : 0x00060530 A0 : 0x800d48a4 A1 : 0x3ffc8310
A2 : 0x00000000 A3 : 0x0000008a A4 : 0x3ffc833c A5 : 0x00000001
A6 : 0x00000000 A7 : 0x00060023 A8 : 0x00060023 A9 : 0x3f40ce38
A10 : 0x3ffbe0b0 A11 : 0xffffffff A12 : 0x80000020 A13 : 0x80000000
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x0000000f EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x40085255 LEND : 0x40085265 LCOUNT : 0xffffffff
Backtrace: 0x400f4ee8:0x3ffc8310 0x400d48a1:0x3ffc8330 0x400d49a2:0x3ffc8360 0x400d2174:0x3ffc8380 0x400d1cd4:0x3ffc83a0 0x400d1b84:0x3ffc83c0 0x400da115:0x3ffc83f0 0x40088589:0x3ffc8410
ELF file SHA256: 66f74cff0

