phil99
 Guru
 Joined: 11/02/2018 Location: AustraliaPosts: 2457 |
Posted: 11:52am 23 Feb 2025 |
Copy link to clipboard |
 Print this post |
|
The module appears to be based on the VL53L1X chip. Gave the data sheet a quick glance and it appears similar to the VL53L0X that I have, so if you compare the data sheets of both you may be able to adapt this MMBasic program for a PicoMite to your unit. At a minimum you will need to change the address to &H52
'VL53L0X laser distance using System I2C on I2C channel 1 'change all I2C to I2C2 if System I2C is on channel 2
Dim Integer dist Const VLaddr=&H29 'VL53L0X I2C address ' Do VL53L0X Print dist Pause 2000 Loop
Sub VL53L0X Local Integer dst(1) I2C write VLaddr,0,2,0,1 'trigger VL53L0X measurement Pause 75 'allow time to perform measurement I2C write VLaddr,1,1,30 'prepare to read I2C read VLaddr,0,2,dst() 'get the data dist = (dst(0)<<8) + dst(1) - 20 'assemble the bytes and subtract the offset. End Sub
Edit. You might need to increase the size of array dst(1), but I am not certain. Eg if there are 3 bytes of data use dst(2) and dist = (dst(0)<<16) + (dst(1)<<8) + dst(2) '+ offset if needed Edited 2025-02-23 22:12 by phil99 |
stanleyella
 Guru
 Joined: 25/06/2022 Location: United KingdomPosts: 2417 |
Posted: 03:16pm 23 Feb 2025 |
Copy link to clipboard |
 Print this post |
|
I found this that worked.
OPTION DEFAULT NONE 'VL53LOX laser distance measurement. Const I2Caddr=&H29 'VL53LOX device address Dim d$ Dim integer dst(1) 'I2C open 100,1000 'Comment out for System I2C I2C write I2Caddr,0,2,&H89,&H1 Font 2 Pause 200 CLS text 0,0, "Integer"+ "String" Do get.dist.str Pause 200 get.dist.int text 0,0, str$(dist.i%, dist.s%) Pause 200 Loop
Sub get.dist.str 'Get distance using a string I2C write I2Caddr,0,2,0,1 I2C write I2Caddr,1,1,&H1E I2C read I2Caddr,0,2,d$ 'read 2 character string dist.s% = Str2bin(uint16,d$,BIG) 'convert string to integer Text MM.HRes/2,MM.VRes/3," "+Str$(dist.s%)+"mm ",cm End Sub
Sub get.dist.int 'Get distance using integers I2C write I2Caddr,0,2,0,1 I2C write I2Caddr,1,1,&H1E I2C read I2Caddr,0,2,dst() 'read 2 bytes dist.i% = (dst(0)<<8) + dst(1) 'combine 2 bytes Text MM.HRes/2,MM.VRes*2/3," "+Str$(dist.i%)+"mm ",cm End Sub |
phil99
 Guru
 Joined: 11/02/2018 Location: AustraliaPosts: 2457 |
Posted: 08:07pm 24 Feb 2025 |
Copy link to clipboard |
 Print this post |
|
The address given in the datasheet is &H52 but it incorporates the R/W bit as the LSB. MMBasic uses a 7 bit address and separate R/W bit so:-
hex$(&H52 >> 1) = &H29 - Same as VL53L0X.
If you are using a recent beta firmware you can use LIST SYSTEM I2C to show everything on the SYSTEM I2C bus. eg> LIST SYSTEM I2C HEX 0 1 2 3 4 5 6 7 8 9 A B C D E F 00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > Edited 2025-02-25 08:56 by phil99 |