A link I found for proton basic
http://www.protonbasic.co.uk/showthread.php/76045-VL53L0X-laser-ranging-sensor
edit
http://www.protonbasic.co.uk/content.php/4621-VL53L0X-laser-ranging-sensor-sample-code-for-PIC16F628A
Code I tried but faulty device I think. I can find it's address and version works but not distance. All 0s but may be I not converted proton basic right.
;in progress VL50L0X range finder
;proton basic to gcb v2
#chip mega328p, 16
#option explicit
#define I2C_MODE Master
#define I2C_DATA PORTC.4
#define I2C_CLOCK PORTC.5
#define I2C_DISABLE_INTERRUPTS ON
'Variables
'Set up hardware serial connection
#define USART_BAUD_RATE 9600
#define USART_DELAY 10 ms
#define USART_BLOCKING
#define VL53L0x_device 0x52
'Variables
Dim tmp As Byte
Dim DatoVL As Byte
Dim DatoSensor(12) As Byte
Dim Distance As Word
Dim devError As Byte
Dim SPAD As long
Dim Signal As Word
Dim Ambient As Word
wait 100 ms
Info_VL53 ;Send info data
wait 1 s
'Loop of program
do
'Sys range start
VL53L0x_sendbyte( 0x00 )
VL53L0x_sendbyte( 0x01 )
;I2COut SDA,SCL,W_ADDRESS,[0x00,0x01]
wait 5 s
'Range status
VL53L0x_sendbyte( 0x14 )
;I2COut SDA,SCL,W_ADDRESS,[0x14]
wait 5 ms
'Read 12 raw data of Sensor:
;I2CIn SDA,SCL,R_ADDRESS,[Str DatoSensor]
for tmp=1 to 12
I2CSTART
I2CSEND( VL53L0x_device )
I2CSTART
I2CSEND( VL53L0x_device + 1)
I2CReceive( DatoSensor(tmp) , NACK )
I2CSTOP
next tmp
' 'Activate for view raw data
For tmp=1 To 12
hserprint str(DatoSensor(tmp))
If tmp<12 Then hserprint ","
Next tmp
crlf
'Resolve sensor error list:
devError = (DatoSensor(1) and 0x78 ) /8 ; // Check for errors
HSerprint "Status: "
select case devError
case 0x00
HSerPrint "Data OK!"
case 0x01
HSerPrint "VCSEL CONTINUITY TEST FAILURE!"
case 0x02
HSerPrint "VCSEL WATCHDOG TEST FAILURE!"
case 0x03
HSerPrint "NO VHV VALUE FOUND!"
case 0x04
HSerPrint "MSRC NO TARGET!"
case 0x05
HSerPrint "SNR CHECK!"
case 0x06
HSerPrint "RANGE PHASE CHECK!"
case 0x07
HSerPrint "SIGMA THRESHOLD CHECK!"
case 0x08
HSerPrint "TCC!"
case 0x09
HSerPrint "PHASE CONSISTENCY!"
case 0x0A
HSerPrint "MIN CLIP!"
case 0x0B
HSerPrint "RANGE COMPLETE!"
case 0x0C
HSerPrint "ALGO UNDERFLOW!"
case 0x0D
HSerPrint "ALGO OVERFLOW!"
case 0x0E
HSerPrint "RANGE IGNORE THRESHOLD!"
end select
crlf
HSerPrint str(devError)
'Resolve info of sensor VL53L0x:
'If devError = 0x00 or devError = 0x06 update Distance
'If devError = 0x00 Or devError = 0x06Then
Distance=DatoSensor(11)*256+DatoSensor(12)
'endif
'Effective SPAD Return Count
SPAD = DatoSensor(3) + DatoSensor(4)/255
'Signal Rate
Signal = DatoSensor(7)*256+DatoSensor(8)
'Ambient Rate
Ambient= DatoSensor(9)*256+DatoSensor(10)
'Send terminal info:
hserprint "Distance: "+str(Distance)+" mm"
crlf
hserprint "Ambient Rate = "+str(Ambient)+"mc/s"
crlf
hserprint "Signal Rate = "+str(Signal)+"mc/s"
crlf
hserprint "SPAD = "+str(SPAD)
crlf
'wait a moment for view info
wait 1 s
loop
'Read sensor info
sub Info_VL53
'IDENTIFICATION REVISION ID
;I2CIn SDA,SCL,R_ADDRESS,0xC2,[DatoVL]
I2CStart
I2CSEND( 0x52 )
I2CSEND( 0xC2 )
I2CStart
I2CSEND( 0x53)
I2CReceive(DatoVL , NACK )
I2CStop
hserprint "Revision ID: "+str(DatoVL)
crlf
'IDENTIFICATION MODEL ID
;I2CIn SDA,SCL,R_ADDRESS,0xC0,[DatoVL]
I2CStart
I2CSEND( 0x52 )
I2CSEND( 0xC0 )
I2CStart
I2CSEND( 0x53)
I2CReceive(DatoVL , NACK )
I2CStop
hserprint "Device ID: "+str(DatoVL)
crlf
'PRE RANGE CONFIG VCSEL PERIOD
;I2CIn SDA,SCL,R_ADDRESS,0x50,[DatoVL]
I2CStart
I2CSEND( 0x52 )
I2CSEND( 0x50 )
I2CStart
I2CSEND( 0x53)
I2CReceive(DatoVL , NACK )
I2CStop
hserprint "Pre Range Config Period: "+str(DatoVL)
crlf
'FINAL RANGE CONFIG VCSEL PERIOD
;I2CIn SDA,SCL,R_ADDRESS,0x70,[DatoVL]
I2CStart
I2CSEND( 0x52 )
I2CSEND( 0xC0 )
I2CStart
I2CSEND( 0x53)
I2CReceive(DatoVL , NACK )
I2CStop
hserprint "Final Period: "+str(DatoVL)
crlf
end sub
sub crlf
HSersend 13
HSersend 10
end sub
sub VL53L0x_sendbyte( in VL53L0x_data )
I2CSTART
I2CSEND( VL53L0x_device )
I2CSEND( VL53L0x_data )
'initiate Stop Condition
I2CSTOP
end sub
sub VL53L0x_readbyte( Out VL53L0x_data )
I2CSTART
I2CSEND( VL53L0x_device )
I2CSTART
I2CSEND( VL53L0x_device + 1)
I2CReceive( VL53L0x_data , NACK )
'initiate Stop Condition
I2CSTOP
end sub