LIDAR-Lite 3 laser range finder in Bascom

I want to read the distance from the LIDAR-Lite 3 laser range finder in Bascom on the I2C. I can’t do it, does anyone have any ideas?

Declare Function Srf02_firmware(byval Slaveid As Byte) As Byte
Declare Function Srf02_entfernung(byval Slaveid As Byte) As Integer

$regfile = “m32def.dat”
$framesize = 42
$swstack = 42
$hwstack = 42

$crystal = 16000000 'Quarzfrequenz
$baud = 9600

Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1

Const Lidar_lite_slaveid = &H62 'Standard I2C Adresse von Lidar_lite

Dim Entfernung As Integer
Dim V As Byte

Wait 3 'Warte 3 Sekunden
I2cinit
Print “Lidar Testprogramm”
Print “Lidar Firmware Version:” ;Lidar_lite_firmware(Lidar_lite_slaveid)

V = 1
Do
Entfernung = Lidar_lite_entfernung(Lidar_lite_srf02_slaveid)
Print “Entfernung:” ; Entfernung ; “cm”
Wait 1
Loop

End
'------------- Hilfsfunktionen für Lidar_lite ----------
Function Lidar_lite_firmware(byval Slaveid As Byte) As Byte
Local Firmware As Byte
Local Slaveid_read As Byte
slaveid_read = Slaveid + 1
I2cstart
I2cwbyte Slaveid
I2cwbyte 0 'Leseregister festlegen
I2cstop
I2cstart
I2cwbyte Slaveid_read
I2crbyte Firmware , Nack
I2cstop
Lidar_lite _firmware = Firmware
End Function

Function Lidar_lite_entfernung(byval Slaveid As Byte) As Integer
Local Lob As Byte
Local Hib As Byte
Local Firmware As Byte
Local Temp As Byte
Local Slaveid_read As Byte

slaveid_read = Slaveid + 1

'Messvorgang in starten
I2cstart
I2cwbyte Slaveid
I2cwbyte 0
I2cwbyte 4
I2cstop

Warteaufmessung:
Waitms 1
Firmware = Lidar_lite_firmware(slaveid)
If Firmware = 0 Then Goto Weiter
Goto Warteaufmessung

Weiter:
I2cstart
I2cwbyte Slaveid
I2cwbyte 2 'Leseregister festlegen
I2cstop
I2cstart
I2cwbyte &H8f
I2crbyte Hib, Ack
I2crbyte low, Nack
I2cstop
Lidar_lite_entfernung = Makeint(lob, Hib)
End Function
End

1 Like

HI @Tom200 ,

Does the LIDAR work at all? Which error are you getting?

Maybe this guide could be helpful LIDAR-Lite v3 Hookup Guide - learn.sparkfun.com