# PiicoDev Distance Sensor VL53L1X - Raspberry Pi Guide

**URL:** <https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676>\
**Category:** Guides\
**Created:** [13 July 2021 22:53 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676 "2021-07-13T22:53:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [13 July 2021 22:53 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/1 "2021-07-13T22:53:17Z")

</div>

Michael just shared a new tutorial: [**“PiicoDev Distance Sensor VL53L1X - Raspberry Pi Guide”**](http://core-electronics.com.au/tutorials/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide.html)  
  
 ![](https://core-electronics.com.au/media/kbase/piicodev-distance-sensor-vl53l1x-raspberry-pi1.png)  
  
This guide will help you read distance data from your PiicoDev® Distance Sensor and a Raspberry Pi single-board computer!  
  
[**Read more**](http://core-electronics.com.au/tutorials/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide.html)

---

<div class="post-metadata">

**Author:** ![David64815](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@David64815](https://forum.core-electronics.com.au/u/David64815)\
**Post date:** [11 October 2021 04:35 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/2 "2021-10-11T04:35:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [11 October 2021 22:01 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/3 "2021-10-11T22:01:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David64815](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@David64815](https://forum.core-electronics.com.au/u/David64815)\
**Post date:** [11 October 2021 22:23 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/4 "2021-10-11T22:23:16Z")

</div>

Great, thanks. I’ll place an order shortly. 🙂

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](https://github.com/bahamas10/hueadm) to control [a Philips Hue Smart Plug](https://simply-leds.com.au/products/philips-hue-smart-plug) to turn on/off the light, depending on whether or not the roller door is open or closed.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [11 October 2021 23:37 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/5 "2021-10-11T23:37:42Z")

</div>

This sounds like a great project 😃 We’d love for you to [share](https://core-electronics.com.au/create-project) your progress at any step in the process on our projects module.

---

<div class="post-metadata">

**Author:** ![Tom111921](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tom111921](https://forum.core-electronics.com.au/u/Tom111921)\
**Post date:** [2 May 2022 23:24 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/6 "2022-05-02T23:24:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [3 May 2022 04:16 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/7 "2022-05-03T04:16:00Z")

</div>

Hi @Tom111921 , copying my reply in the [other thread](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi/13937/2):

> Hi Tom,  
> You can download the example code right away here: [main.py](https://raw.githubusercontent.com/CoreElectronics/CE-PiicoDev-VL53L1X-MicroPython-Module/main/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.

---

<div class="post-metadata">

**Author:** ![Tom111921](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tom111921](https://forum.core-electronics.com.au/u/Tom111921)\
**Post date:** [5 May 2022 05:46 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/8 "2022-05-05T05:46:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Riddhi186182](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@Riddhi186182](https://forum.core-electronics.com.au/u/Riddhi186182)\
**Post date:** [8 November 2023 01:26 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/9 "2023-11-08T01:26:11Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Riddhi186182](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@Riddhi186182](https://forum.core-electronics.com.au/u/Riddhi186182)\
**Post date:** [8 November 2023 03:12 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/10 "2023-11-08T03:12:44Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Blayden](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/blayden/32/7535_2.png) [@Blayden](https://forum.core-electronics.com.au/u/Blayden)\
**Post date:** [10 November 2023 04:19 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/11 "2023-11-10T04:19:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Roy263988](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Roy263988](https://forum.core-electronics.com.au/u/Roy263988)\
**Post date:** [10 January 2024 14:03 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/12 "2024-01-10T14:03:10Z")

</div>

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

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

```

Code:

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [10 January 2024 22:12 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/13 "2024-01-10T22:12:26Z")

</div>

Hi @Roy263988 , the docs are found on the [github repo](https://github.com/CoreElectronics/CE-PiicoDev-VL53L1X-MicroPython-Module?tab=readme-ov-file#piicodev_vl53l1xbus-freq-sda-scl-address0x29)

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

```auto
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 )

```

---

<div class="post-metadata">

**Author:** ![Paul76833](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Paul76833](https://forum.core-electronics.com.au/u/Paul76833)\
**Post date:** [14 May 2025 04:05 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/14 "2025-05-14T04:05:13Z")

</div>

I can’t get the module to do anything useful (Pi Zero W 2, no X)  
It’s plugged in and there’s a green light so it’s at least getting power.

I enabled i2c via raspi-config but nothing shows up in i2cdetect

```auto
i2cdetect -y 1
     0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

```

And the example python script just complains about IO error

```auto
raceback (most recent call last):
  File "/home/pi/laser/main.py", line 4, in <module>
    distSensor = PiicoDev_VL53L1X()
                 ^^^^^^^^^^^^^^^^^^
  File "/home/pi/laser/lib/python3.11/site-packages/PiicoDev_VL53L1X.py", line 111, in __init__
    self.reset()
  File "/home/pi/laser/lib/python3.11/site-packages/PiicoDev_VL53L1X.py", line 135, in reset
    self.writeReg(0x0000, 0x00)
  File "/home/pi/laser/lib/python3.11/site-packages/PiicoDev_VL53L1X.py", line 124, in writeReg
    return self.i2c.writeto_mem(self.addr, reg, bytes([value]), addrsize=16)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/laser/lib/python3.11/site-packages/PiicoDev_Unified.py", line 135, in writeto_mem
    self.smbus_i2c_write(addr, memaddr, buf, len(buf), addrsize=addrsize)
  File "/home/pi/laser/lib/python3.11/site-packages/PiicoDev_Unified.py", line 148, in smbus_i2c_write
    self.i2c.i2c_rdwr(msg_w)
  File "/home/pi/laser/lib/python3.11/site-packages/smbus2/smbus2.py", line 660, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 5] Input/output error

```

I’ve tried as both regular user and root incase it was permissions or something)

Any ideas?

---

<div class="post-metadata">

**Author:** ![Zach](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/zach/32/10899_2.png) [@Zach](https://forum.core-electronics.com.au/u/Zach)\
**Post date:** [14 May 2025 04:40 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/15 "2025-05-14T04:40:02Z")

</div>

Hey @Paul76833, welcome to the forums!

If the device is getting an I/O error, it’s more than likely a connection error somewhere (and possibly a faulty board, but our fault rate on these is very low).

Could you send an image of your wiring? We have had some incidents with this error in past that were caused by bad jumper wires, so it could be worth swapping out the data cables for new ones.

Images of the board itself could be useful too!

---

<div class="post-metadata">

**Author:** ![Paul76833](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Paul76833](https://forum.core-electronics.com.au/u/Paul76833)\
**Post date:** [14 May 2025 05:17 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/16 "2025-05-14T05:17:00Z")

</div>

I managed to get i2cdetect to show something and I could run the example briefly and then started getting

```auto
iicoDev could not communicate with module at address 0x29, check wiring

```

I guess my headers are loose or something, but it’s good to know it at least kind of works  
(I used the hammer on header kit which I’ve used before with no issues but I guess it’s not quite right)

Thanks for the quick reply

---

<div class="post-metadata">

**Author:** ![Zach](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/zach/32/10899_2.png) [@Zach](https://forum.core-electronics.com.au/u/Zach)\
**Post date:** [14 May 2025 05:38 UTC](https://forum.core-electronics.com.au/t/piicodev-distance-sensor-vl53l1x-raspberry-pi-guide/10676/17 "2025-05-14T05:38:25Z")

</div>

Hey Paul,

Glad to hear you’re getting signs of life from the board now!

The other option we see periodically is rusted jumper cables. A fair few of the cheaper variant jumper cables are actually copper-plated steel (or some other metal subject to deterioration) rather than pure copper. If you’ve had them for a while, they can rust internally and break without any sign of damage externally.
