PiicoDev Distance Sensor VL53L1X - Raspberry Pi Guide

Michael just shared a new tutorial: “PiicoDev Distance Sensor VL53L1X - Raspberry Pi Guide”



This guide will help you read distance data from your PiicoDev® Distance Sensor and a Raspberry Pi single-board computer!

Read more

3 Likes

Hello. If I am using a headless RPi, can I just run pip install piicodev to install the Python package, and then run the Python script shown in that guide, rather than firing up a GUI and then running Thonny?

(I’d test this myself but I haven’t bought the parts yet to test with…)

Thanks in advance.

3 Likes

@David64815
Totally!
I recommend installing with pip3 install piicodev and then running your script with python3

4 Likes

Great, thanks. I’ll place an order shortly. :slight_smile:

I recently bought a house and the kitchen cupboard has a roller door sort of thing on it (sounds weird, but actually looks kinda cool). There’s a power point inside for e.g. toaster etc. It gets a bit dark in there so I’ve already got a small LED light mounted in there, but the problem is the light switch is high up and hard to reach. I plan to use this sensor and a Raspberry Pi, which will be mounted at the back of the cupboard, to detect the distance to the roller door. If it exceeds a certain value, the door will be considered open. In which case, it will then use hueadm to control a Philips Hue Smart Plug to turn on/off the light, depending on whether or not the roller door is open or closed.

3 Likes

This sounds like a great project :smiley: We’d love for you to share your progress at any step in the process on our projects module.

2 Likes

Following the steps of the tutorial, after installation there was no PiicoDev folder created and a quick search showed no main.py associated with piicodev. I uninstalled and reinstalled piicodev and tried again. Seems I’m missing a step, please help

1 Like

Hi @Tom111921 , copying my reply in the other thread:

Hi Tom,
You can download the example code right away here: main.py - right-click and save link as.
That’s pretty strange. It seems like some content has gone missing from the tutorial - you can see in the video that we save a file from a link… In any case, I’ve fixed the article and the update should appear soon.

2 Likes

Thanks a lot for the quick response, all good now. I do have another question regarding ranging. I’m getting great accuracy below 3 metres, but it’s pretty wild beyond that. The VL53L1X sensor has 3 modes, 1-short, 2-medium and 3-long. Any advice how I can check the mode?

@Michael - another great product from you guys.

Btw, just to let you know, i tested my VL53L1X sensor using your library and also the Pimoroni library and yours provide a lot more accurate readings.

The reason I tried their library is because they have a number of good examples, that was the whole reason. Could you please point me to an advanced usage example with Piicodev library please?

In my setup I am looking to use 2x VL53L1X sensors - both on seperate bus (I2C0 and I2C1). Hopefully different bus means no conflict. I am after an example that helps me define bus for each of the sensors and thus isolating their outputs.

2 Likes

Ok i figured it out. on your github repo it shows how to declare bus. in case anyone else is looking for it.

tof1 = PiicoDev_VL53L1X(bus=0)
tof2 = PiicoDev_VL53L1X(bus=1)

4 Likes

Hey Riddhi,

Thanks for letting us know, I am sure that will be helpful for anyone else looking for configuration of these boards.

Cheers,
Blayden

1 Like

Hi Riddhi
I also use 2x VL53L1X sensors - both on separate bus (I2C0 and I2C1)
I changed my software to configure the 2 sensors as you advised

tof1 = PiicoDev_VL53L1X(bus=0)
tof2 = PiicoDev_VL53L1X(bus=1)

Code:

from PiicoDev_VL53L1X import PiicoDev_VL53L1X

from time import sleep
import math
from machine import Pin

DistSensor_Left = PiicoDev_VL53L1X(bus=0)
DistSensor_Right = PiicoDev_VL53L1X(bus=1)

Error:
I get the following. error

MPY: soft reboot
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "PiicoDev_VL53L1X.py", line 109, in __init__
  File "PiicoDev_Unified.py", line 189, in create_unified_i2c
  File "PiicoDev_Unified.py", line 64, in __init__
Exception: Please provide at least bus, sda, and scl

Where do I configure the I2C pins for bus=0 and bus=1 ?
Your support will be appreciated.

Hi @Roy263988 , the docs are found on the github repo

try passing in the pins like this. change the pin numbers to whatever is appropriate for you

from PiicoDev_VL53L1X import PiicoDev_VL53L1X

from time import sleep
import math
from machine import Pin

DistSensor_Left = PiicoDev_VL53L1X( bus=0, sda=Pin(8), scl=Pin(9), freq = 400_000)
DistSensor_Right = PiicoDev_VL53L1X( bus=0, sda=Pin(6), scl=Pin(7), freq = 400_000 )