TFMini 14786 Lidar support needed for reading data by Raspberry Pi with Python

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 :frowning:

#!/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)

Hi ccamkoy,

Unfortunately, the only example we have for the Qwiic version of the TFMini is for Arduino. It looks like you are on the right track here but we cannot help debug custom code. Other users may have some input to help you out here.

If possible, it may be better to use the serial version of the TFMini found [here. There are several examples for using that version of the Micro LIDAR with Raspberry Pi. The [TFMini GitHub Repo will have a few examples.](TFmini&TFmini-Plus · GitHub)](TFMini - Micro LiDAR Module - SEN-14588 - SparkFun Electronics)