How do we know that our connection to the distance sensor is wired correctly? The quick way to test this is to run a program called the I2C scanner. It will return a list of all the devices it finds on the I2C bus.
We first run the I2C scanner program to verify that the sensor is connected correct and is responding to the I2C bus scan.
importmachine# Pins on the Grove Connector 1 on the Maker Pi RP2040 are GP0 and GP1sda=machine.Pin(0)scl=machine.Pin(1)i2c=machine.I2C(0,sda=sda,scl=scl,freq=400000)print("I2C device ID list:",i2c.scan())
This should return a list of the devices it finds. If you just have the Time-of-Flight sensor it will look like this:
device_id = i2c.scan()
Testing for the Time-of-Flight Sensor
1 2 3 4 5 6 7 8 9101112131415
importmachinesda=machine.Pin(0)scl=machine.Pin(1)i2c=machine.I2C(0,sda=sda,scl=scl,freq=400000)# i2c.scan() returns a list of devices that have been found# i2c.scan() is the first device founddevice_id=i2c.scan()print("Device found at decimal",device_id)ifdevice_id==41:print("TEST PASS")else:print("No device found at decimal 41")print("TEST FAIL")