Hi,
I am just a new-bie for QWIIC Systems. I have purchased a TFMini 14786 Lidar and need support for reading data from Raspberry Pi + Python environment. In the product document, there is an example for C/C++ with the use of “Wire.h” file which helps talking to Ardunio. But, I can not adapt this solution into Raspberry Pi + Python environment unfortunately. If possible, could anyone suggest a solution with a python example please?
PS: I am able to see the device at 0x10 address via “i2cdetect -y 1”.
I have tried the following code but it does not work as it returns IOError: 121 all the time
#!/usr/bin/python
import smbus
valid_data = False
distance = 0
strength = 0
rangeType = 0
bus = smbus.SMBus(1) # OK (No Error)
DEVICE_ADDRESS = 0x10 #7 bit address (will be left shifted to add the read write bit)
bus.write_byte(DEVICE_ADDRESS, 83) # byte’S’ OK (No Error)
bus.write_byte(DEVICE_ADDRESS, 0x01) # OK (No Error)
bus.write_byte(DEVICE_ADDRESS, 0x02) #OK (No Error)
bus.write_byte(DEVICE_ADDRESS, 7) # OK (No Error)
bus.write_byte(DEVICE_ADDRESS, 83) # byte’S’ OK (No Error)
bus.read_i2c_block_data(DEVICE_ADDRESS, 7) # returns IOErr: 121 Device busy
#bus.read_i2c_block_data(DEVICE_ADDRESS, 0, 7) # returns IOErr: 121 Device busy
#bus.read_byte_data(DEVICE_ADDRESS, 7) # returns IOErr: 121 Device busy
for x in range(7):
incoming=bus.read_byte(DEVICE_ADDRESS)
if incoming != 80: # byte’P’
if x==0:
if incoming == 0x00:
valid_data=False
elif incoming == 0x01:
valid_data = True
elif x==2:
distance=incoming
elif x==3:
distance = (distance<<8) + incoming
elif x==4:
strength = incoming
elif x==5:
strength = (strength<<8) + incoming
elif x==5:
rangeType += incoming
else:
print (‘Stop byte has been received …’)
print (‘Distance=’, distance)