News:

;) This forum is the property of Proton software developers

Main Menu

Time Of Flight VL53L0X software

Started by charliecoutas, Today at 07:39 AM

Previous topic - Next topic

charliecoutas

Has anybody got a VL53L0X Time-Of-Flight sensor working, using code in Positron? I bought some of these sensors but the manufacturers data sheet goes into great detail about everything except how to program the registers!

Charlie

Craig

#1
Hi Charlie

I used this in a project and it worked well, a thing to consider is UV Light it doesn't work properly in direct sun light, You do get a UV cover which stops this issue. There was a Post on the forum years ago about this sensor and I based my code around their model and it has worked very well and reads accurately. This should work fine as I grabbed it out of a large piece of code.

Device = 18F47K40
Declare Xtal 16                                        ' Using External Oscillator 16Mhz XTAL (Don't Go Faster as it Causes Glitching!
DelayMS 150                                           ' Let XTAL Stabalize

TRISC   = %10110000
ANSELC  = %00000000                                   
LATC    = 0x00                                       
ODCONC  = 0x00                                       
INLVLC  = 0x00 

'=======================================================================================
' Setup the VL53L0x - I2C
'---------------------------------------------------------------------------------------
    Declare Hbus_Bitrate = 400
    Declare HSCL_Pin = PORTC.3                              ' (WHITE) Symbol SCL (OUTPUT)- VL53L0x TOF Sensor
    Declare HSDA_Pin = PORTC.4                              ' (BLUE)  Symbol SDA (INPUT) - VL53L0x TOF Sensor

'=======================================================================================
' Setup the VL53L0x - TOF Lazer Unit "EAST/POLOLU"
' VL53L0x Registers Write and Read
'-----------------------------------------------------------------------------------------
    Symbol W_ADDRESS = $52
    Symbol R_ADDRESS = $53
'-----------------------------------------------------------------------------------------
 
    Dim J As Byte
    Dim DatoVL As Byte
    Dim DatoSensor[12] As Byte
    Dim Distance As Word
    Dim devError As Byte
    Dim SPAD As Float
    Dim Signal As Word
    Dim Ambient As Word
    Dim DisRest As Word                             ' Load VL53L0X "DISTANCE" from (mm) into (cm) Held in "DisRest"
    Dim BufferArray[12] As Word


'-----------------------------------------------------------------------------------------------
' VL53L0X TOF Sensor
' XSHUNT Pin Must Go (HIGH +5V) To Enable Sensor or (LOW 0V) To Switch Sensor OFF
'===============================================================================================
    VL53Lx:
'System Range Start
    HBusOut W_ADDRESS,[$00,$01]
    DelayMS 5

'Range status
    HBusOut W_ADDRESS,[$14]
    DelayMS 5

' Read The 12 Bit Raw Data Of The VL53L0x Sensor:
    HBusIn R_ADDRESS,[Str DatoSensor]

'=======================================================
    For J = 0 To 11
        BufferArray[J] = (DatoSensor[10]*256) + DatoSensor[11]                        ' Fill All 12 Elements of the BufferArray With Distance Measurements from VL53L0X
        Distance = BufferArray[J]                                                                        ' Load BufferArray J Elements into Distance Variable
  ' HRSOut "BUFj: ",Dec3 BufferArray[J]," "                                                       ' Switch On For TESTING " Be Careful it Slows Everything Down"
  ' HRSOut "Distance: ",Dec distance," "                                                           ' Switch On For TESTING " Be Careful it Slows Everything Down"
  ''  Print At 1,1, Dec3 BufferArray[J]," "                                                            ' Switch On For TESTING " Be Careful it Slows Everything Down"
    Next J
'-----------------------------------------------------------------------------------------------
' Resolve Sensor Error List:
'=========================================================
 ''devError = DatoSensor[0] & 0x78 >> 3 ' // Check for errors
 ''If devError = $00 Then  RsOut "Data OK!" ';// No device error
 ''If devError = $01 Then  RsOut "VCSEL CONTINUITY TEST FAILURE!"
 ''If devError = $02 Then  RsOut "VCSEL WATCHDOG TEST FAILURE!"
 ''If devError = $03 Then  RsOut "NO VHV VALUE FOUND!"
 ''If devError = $04 Then  RsOut "MSRC NO TARGET!"
 ''If devError = $05 Then  RsOut "SNR CHECK!"
 ''If devError = $06 Then  RsOut "RANGE PHASE CHECK!"
 ''If devError = $07 Then  RsOut "SIGMA THRESHOLD CHECK!"
 ''If devError = $08 Then  RsOut "TCC!"
 ''If devError = $09 Then  RsOut "PHASE CONSISTENCY!"
 ''If devError = $0A Then  RsOut "MIN CLIP!"
 ''If devError = $0B Then  RsOut "RANGE COMPLETE!"
 ''If devError = $0C Then  RsOut "ALGO UNDERFLOW!"
 ''If devError = $0D Then  RsOut "ALGO OVERFLOW!"
 ''If devError = $0E Then  RsOut "RANGE IGNORE THRESHOLD!"
 '''Print At 3,10,"Dist: ",hex2 devError," "

'-----------------------------------------------------------------------------------------------
' Resolve info of sensor VL53L0x:
'===============================================================================================
'If devError = $00 or devError = $06 update Distance
'If devError = $00 Or devError = $06 Then
'endif
   
' Effective SPAD Return Count
    SPAD = DatoSensor[2] + DatoSensor[3]/255

' Signal Rate
    Signal = DatoSensor[6]*256 + DatoSensor[7]

' Ambient Rate
    Ambient = DatoSensor[8]*256 + DatoSensor[9]

' Send Terminal info:

    Print At 1,6,"D: ",Dec Distance,"  "                                                        ' Print Distance in mm
  ' HRSOut "VL: ", Dec3 Distance,"  "                                                         ' PC TESTING
'' Print At 3,33,"Amb= ",Dec Ambient,"mc/s"                                            ' Print At 3,33,"Ambient Rate = ",Dec Ambient,"mc/s"

'' Print At 3,43,"Sig= ",Dec Signal,"mc/s"                                                   ' Print At 3,43,"Signal Rate = ",Dec Signal,"mc/s"

'' Print At 3,23,"SPAD= ",Dec SPAD                                                           ' Print At 3,23,"SPAD= ",Dec SPAD

Return
 
'-------------------------------------------------------------------
' Read VL53L0x Sensor Info
'-------------------------------------------------------------------
 Info_VL53:

'IDENTIFICATION REVISION ID
    HBusIn R_ADDRESS,$C2,[DatoVL]
 ' Print At 3,53,Hex2 DatoVL," "                                                                ' Print At 3,53,"REVISION ID: ",Hex2 DatoVL," "
 ' RsOut "Revision ID: ",Hex2 DatoVL,13,10

'IDENTIFICATION MODEL ID
    HBusIn R_ADDRESS,$C0,[DatoVL]
 ' Print At 3,53,Hex2 DatoVL," "
 ' RsOut "Device ID: ",Hex2 DatoVL,13,10

'PRE RANGE CONFIG VCSEL PERIOD
    HBusIn R_ADDRESS,$50,[DatoVL]
 ' Print At 3,53,Hex2 DatoVL," "                                                                ' Print At 3,53,"Pre Range Config Period: ",Hex2 DatoVL," "
 ' RsOut "Pre Range Config Period: ",Hex2 DatoVL,13,10

'FINAL RANGE CONFIG VCSEL PERIOD
    HBusIn R_ADDRESS,$70,[DatoVL]
 ' Print At 3,53,Hex2 DatoVL," "                                                                ' Print At 3,53,"Final Period: ",Hex2 DatoVL," "
 ' RsOut "Final Period: ",Hex2 DatoVL,13,10

 Return

'-------------------------------------------------------------------

Regards

Craig

charliecoutas

Many thanks Craig, you've put me on the road to success.

Charlie

▲