2022-07-09 21:51:40 +00:00
|
|
|
import smbus
|
2022-07-06 16:34:46 +00:00
|
|
|
import time
|
|
|
|
|
2022-07-09 21:51:40 +00:00
|
|
|
address = 0x57
|
|
|
|
sensor = smbus.SMBus(1)
|
2022-07-06 16:41:32 +00:00
|
|
|
|
2022-07-09 21:51:40 +00:00
|
|
|
while True:
|
|
|
|
sensor.write_byte(address, 0x01)
|
|
|
|
|
|
|
|
time.sleep(0.2)
|
2022-07-06 17:44:02 +00:00
|
|
|
|
2022-07-09 21:51:40 +00:00
|
|
|
bytes = sensor.read_i2c_block_data(address, 0, 3)
|
|
|
|
distance = ((bytes[0] << 16) + (bytes[1] << 8) + bytes[2]) / 10000
|
|
|
|
|
|
|
|
print(distance)
|