Skip to main content
carlosdelfino
Senior
July 9, 2025
Solved

VL53L0X and RP Pico W

  • July 9, 2025
  • 4 replies
  • 973 views

I'm trying to port the VL53L0X library for use with the RP Pico W for academic reasons, but I can't map the calls between the VL53L0X SDK and the RP Pico W SDK.

For example, the function

int32_t VL53L0X_read_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count)

would theoretically need to be adjusted to call the function

int i2c_read_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop)


Attempt to read specified number of bytes from address, blocking.

Am I right? Or should it be another way?
Thanks

Best answer by carlosdelfino

After extensive reading of the datasheet and other guides, research with the support of chatGPT, and analysis of various codes, I ended up reverse-engineering the Pololu library. The final code is at https://github.com/RapportTecnologia/VL53L0X-RP2040-2350. As far as I've tested, it's working well, but I'd like your help with suggestions for improvements.

The code allows for easy adaptation to other microcontrollers; just review the I2C calls in the I2C library that comes with the module.

Have fun or try your hand at this wonderful distance sensor from STM.

4 replies

Zhiyuan.Han
Technical Moderator
July 15, 2025

Hi

Your understanding is correct, inside VL53L0X some API I2C read/write function need read more than 4 registers at same time, so it need read_multi and wirte_multi function. 

You can find below information form the datasheet, below reg can be used to test the I2C reading function. 

 

ZhiyuanHan_0-1752571889166.png

 

 

Br

Zhiyuan.Han

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
carlosdelfino
Senior
July 15, 2025

I'm having trouble mapping the functions to the RP2040's I2C. I think the example I got isn't the best fit, and the VL53L1CB_SimpleRanging example I got from CubeMX doesn't compile. It's not for the VL53L0, but it would be a good reference. I found another code on the other computer, and I'll cite it tomorrow, but it's completely different from this one. I'm still having trouble adjusting the file for the platform.

Buy me a coffeeMy Portal about Analog ElectronicsMy Youtube Channel where I share my learning about Analog Electronic
carlosdelfino
carlosdelfinoAuthorBest answer
Senior
July 30, 2025

After extensive reading of the datasheet and other guides, research with the support of chatGPT, and analysis of various codes, I ended up reverse-engineering the Pololu library. The final code is at https://github.com/RapportTecnologia/VL53L0X-RP2040-2350. As far as I've tested, it's working well, but I'd like your help with suggestions for improvements.

The code allows for easy adaptation to other microcontrollers; just review the I2C calls in the I2C library that comes with the module.

Have fun or try your hand at this wonderful distance sensor from STM.

Buy me a coffeeMy Portal about Analog ElectronicsMy Youtube Channel where I share my learning about Analog Electronic
Zhiyuan.Han
Technical Moderator
July 31, 2025

Hi 

Glad to know you have made it works from your side. 

The API porting work is more relay on the platform I2C read and write functions. if you have a mature one form on line search, that will easy your work.

Br

Zhiyuan.Han

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
carlosdelfino
Senior
July 31, 2025

I found this path easier. Using the library offered by STM seemed quite complete, but I was having difficulty porting it even though I only had to replace the I2C calls. But now that I'm more experienced with the landing process, I'm reviewing the original.

Buy me a coffeeMy Portal about Analog ElectronicsMy Youtube Channel where I share my learning about Analog Electronic