TFmini-s lidar i2c picaxe 20x2 communication

bastiaan

New member
hi everyone, i have hit a bit of snag with my project and would love a second opinion.

The project
i have staircase where i want to make each step make a sound when stepped on, unfortunately it's a concrete staircase so i can't use bending or weight sensors.
this is where the TFmini-s lidar comes in. this is a great little lidar that has a serial and a I2C mode. i tested it with the serial and it works great, but to save myself a lot of wiring i trying to read the distance through I2C with a 20x2 picaxe.

the problem
i successfully switched the TFmini-s to i2c mode and it shows up as 0x10 on a i2c scan, so i know it works and is able to send and receive data
25798

but when i try to get any kind of data it just fills any requested byte with 1's
25799

here is the code, i have been tweaking it in a attempt to get anything for it with no results

Code:
setfreq m8
hi2csetup i2cmaster, 0x10, i2cslow_8, i2cbyte    ; set PICAXE as master

main:
hi2cin 0x01,(b0,b1,b2,b3,b4,b5,b6,b7)    ; read data
debug
pause 500
goto main
here is the data sheet of the lidar
https://cdn.sparkfun.com/assets/8/a/f/a/c/16977-TFMini-S_-_Micro_LiDAR_Module-Product_Manual.pdf



please let me know if you have any hints or spot any obvious mistakes
 

hippy

Ex-Staff (retired)
i tested it with the serial and it works great, but to save myself a lot of wiring i trying to read the distance through I2C with a 20x2 picaxe.
Not sure how it will mean less wiring as it will still require two-signal wires no matter which is used.

i successfully switched the TFmini-s to i2c mode and it shows up as 0x10 on a i2c scan, so i know it works and is able to send and receive data
It seems to me that commands need to be sent over serial or packaged as I2C packets, that you can't simply read I2C registers and expect meaningful data.

Other possibilities are that the I2C scan is showing a 7-bit I2C address which needs to be specified as 8-bit for PICAXE, perhaps 0x20, the I2C pull-ups may be missing, or the signals crossed-over.
 

julianE

Senior Member
did a little google sleuthing and others are having issues with I2C, recommendation from the manufacturer is to stick with serial.
 

neiltechspec

Senior Member
I played with a couple of TFmini (non s suffix) a few years ago.
Serial output changed to 9600 baud & update rate to 500ms, worked really well.
Couldn't see the point of i2c.
 

inglewoodpete

Senior Member
I have no experience with this device. Reading the data sheet on i2c working (page 13), doing a read operation needs to be preceded 100mS before by a write. I presume the write is to send a command in preparation for your following read operation. I may be wrong but your code may need to send a command prior to doing a read.
 

bastiaan

New member
ok, after a whole lot of trying i got the TFmini-s to spill the beans and read the data.

here is the code to switch the TFmini to i2c (note the pins)
(i used a 20x2 picaxe, connections may vary depending on the model)
Code:
    setfreq m8
;setting the TFmini to i2c through serial
;connect the power, ground and pin 3 of the lidar to c.1 (hser)

hsersetup B115200_8, %00
    
    
hserout 0,($5A,$05,$0A,$01,$6A)

main:

hserin 1,8
get 1,b0,b1,b2,b3,b4,b5,b6,b7

debug
goto main
and here is the code to read the distance through i2c (again note the pins)
Code:
setfreq m8
;TFmini-s lidar i2c readout
;before you can use the i2c you need to switch it to i2c using serial
;b2 seems to be the distance readout

hi2csetup i2cmaster, %00100000, i2cslow_8, i2cword    ; set PICAXE as master
;default i2c adres is 0x10 but it requires a extra 0 on the end

;pin 1 GND
;pin 2 5V
;pin 3 B.5 (i2c SDA)
;pin 4 B.7 (i2c SCL)

main:

hi2cout ($5A, $05, $00, $01, $60 ); send command "obtain data frame" $60 for cm #65 fot mm
pause 1
hi2cin (b0,b1,b2,b3,b4,b5,b6,b7)    ; read data
debug

goto main
thanks for everyone's input, and if you are running in the same problem, goodluck
 

Buzby

Senior Member
What a strange system, having to use serial before you can use I2C.

Are you sure there is no pin-selectable method of enabling I2C coms ?.
 

hippy

Ex-Staff (retired)
It is somewhat odd, at least unusual, but I guess it does save needing to have an additional pin, ensures a known starting configuration for all users.
 
Top