2025-03-23 6:52 AM
Hi,
I'm using an ESP32 (the RAK11200 module) with my own board (https://github.com/cyclops1982/TOFBoard/tree/main/TOFBoard).
I'm using this helper file and basically do:
1. A init() during the arduino setup()
2. During the arduino loop() i run the GetDepthInMiliMeters()
When i start this the first time, it all works fine. Measurements work as expected. I can run GetDepthInMiliMeters() multiple times and it all works gloriously.
When i reset the ESP (via the reset button), it doesn't work anymore. The VL53L4CX_SetXTalkCompensationEnable() returns 2; (not -2).
If i unplug my own board, and plug it back in and then run the GetDepthInMiniMeters, then it fails on the VL53L4CX_SetDistanceMode() with a division by zero error.
unplugging the ESP and booting it again seems to work fine.
I'm wondering if this has anything to do with my board design, or with my code. Or maybe just the combination of the ESP32 board and my own board.
Solved! Go to Solution.
2025-03-24 7:14 AM - edited 2025-03-24 7:15 AM
The easy way to fix this is to drop the XShut line and bring it back up again at every reboot. That way both your MCU and the sensor know exactly where they are.
It's my conjecture that the I2C bus it what is biting you. (It's not a very reliable bus. If the sensor and the host get out of sync in any way, you will lose the ability to communicate. )
I start all my code with something like this:
/* Toggle Xshut pin to reset the sensor */
HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_RESET);
HAL_Delay(5);
HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_SET);
HAL_Delay(5);
But of course that only works on an STM32.
But you can write something similar for your MCU.
- john
2025-03-24 7:14 AM - edited 2025-03-24 7:15 AM
The easy way to fix this is to drop the XShut line and bring it back up again at every reboot. That way both your MCU and the sensor know exactly where they are.
It's my conjecture that the I2C bus it what is biting you. (It's not a very reliable bus. If the sensor and the host get out of sync in any way, you will lose the ability to communicate. )
I start all my code with something like this:
/* Toggle Xshut pin to reset the sensor */
HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_RESET);
HAL_Delay(5);
HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_SET);
HAL_Delay(5);
But of course that only works on an STM32.
But you can write something similar for your MCU.
- john
2025-03-24 9:42 AM - edited 2025-03-24 9:44 AM
Ha, thank you
I do not have XSHUT wired up in the current version of the PCB, because on the example PCB's i used I didn't use it. I was about to order a new version of my own design... guess i need to add some XSHUT support :)
thank you!