Skip to content

Commit 06843a1

Browse files
committed
update change i2c address
1 parent 93f35b1 commit 06843a1

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

python/VL53L0X.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def clear_interrupt(self):
204204
raise Vl53l0xError('Error clearing VL53L0X interrupt')
205205

206206
def change_address(self, new_address):
207+
if self._dev is not None:
208+
raise Vl53l0xError('Error changing VL53L0X address')
209+
210+
self._i2c.open(bus=self._i2c_bus)
211+
207212
if new_address == None:
208213
return
209214
elif new_address == self.i2c_address:
@@ -221,3 +226,5 @@ def change_address(self, new_address):
221226
self._i2c.write_byte_data(self.i2c_address, self.ADDR_I2C_SEC_ADDR, new_address)
222227

223228
self.i2c_address = new_address
229+
230+
self._i2c.close()

python/VL53L0X_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
# Create a VL53L0X object
2929
tof = VL53L0X.VL53L0X(i2c_bus=1,i2c_address=0x29)
30+
# I2C Address can change before tof.open()
31+
# tof.change_address(0x32)
3032
tof.open()
3133
# Start ranging
3234
tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER)

0 commit comments

Comments
 (0)