Skip to main content

The VL53L8 8x8 laser ranging sensor

The sensor

A VL53L8 is a continuation of a family of laser ranging sensors from ST. They use Single Photon Avalanche Diodes in an 8x8 array giving a pyramid of distances projected out from the sensor from ranges of 2-400cms. It can also do 4x4 with SW interpolation.

I ordered a sensor (set) from ST. 

511-SATEL-VL53L8

You get two sensors on breakout boards for your $27. This is good because w/o this fancy breakout board, you will be on the hook for generating 1.2 & 1.8v.


Wired up to a modified Bluepill with an STM32L443 as a donor CPU, via some simple Dupont wiring, we can communicate with the sensor via I2C. SPI is also possible but the example code that ST provides that was used to debug the comm was I2C and this made comparing easier.

Ada driver

An Ada driver was crafted for the sensor. This was a translation of ST's API for the VL53L8. It was a job to translate it. There is 90k of FW that needs to get DL'd into the sensor. Numerous blind writes to undocumented proprietary registers. But... the important parts are there. If you follow the sequence and do as they do, the device can be brought up w/o error. Hindsight, perhaps using a hybrid project of C/Ada might work but the data structures between the C impl and the Ada might be a snag. Maybe a wrapper could work though. In the end there is an Ada driver for it but at what cost and what did Ada really bring to the table? If the sensor bringup is just a bunch of blind writes, C is perfectly fine for that. Still, the work is done. We have an Ada driver, lets use it. 

Ada stacksize

I ran into an interesting issue with the sensors FWDL. In Ada's I2C implementation, if you want to write to a 16 bit register on a device it looks as so:

<i2c addr><hi_index><lo_index><data .....>

How Adacores's top level I2C implementation handled that was as so:



Observe, this makes a new array composed of the indices and the data. This is fine for small data writes, which is the norm for most device I2C transactions. The VL53L8 though with its 90+K of FW is a challenge here. ST sends the FW in 32K chunks, so at a minimum, 32K will now go on the stack to produce the new buffer. The solution I came up with was a two array write.


Of course there is a commensurate I2C_Write and Master_Transmit that accept two arrays. The win here is no extra stack usage and my STM32L443 is now using a reasonable stack. During debug, I had less than 32 bytes free I think (all of the 64K was consumed due to the giant stack).

The caller in the driver can then say:


Prev, the index was passed in in this case as 16#0000#.

There are some other cases that are large DL's also. crosstalk, default_config. Those also use the scheme.


I think 16#7fff# is some form of bank select for the part. I wonder if the index of 0 is the offset into that bank. If so, perhaps the FWDL could have been done using the existing Ada code and just send less each time.

Ranging

That's what were here for. What happens when you issue a ranging command.



So what is in results?


Looking at distance_mm ranging on a white cube that is both angled and tipped

angled l->r (l closer to pin1 arrow)
+ tipped (top further from pin1)
0x40, 0x42, 0x3c, 0x3b, 0x36, 0x38, 0x32, 0x2f,        greater right
0x3e, 0x3b, 0x35, 0x33, 0x33, 0x32, 0x2d, 0x2d,
0x3b, 0x39, 0x35, 0x30, 0x2f, 0x2e, 0x2e, 0x2a, | gt top -> less |
0x39, 0x33, 0x31, 0x2e, 0x2b, 0x28, 0x27, 0x28,
0x35, 0x2f, 0x2f, 0x2d, 0x27, 0x27, 0x26, 0x26,
0x2f, 0x2e, 0x28, 0x2a, 0x27, 0x24, 0x24, 0x23,
0x2d, 0x2b, 0x2a, 0x28, 0x24, 0x23, 0x22, 0x23,
0x29, 0x26, 0x25, 0x22, 0x22, 0x22, 0x21, 0x21          less left

Thus (0) is furthest and (63) closest

The accuracy gel's with ST's data that its +/- 2mm. I found that to be quite accurate over the measured area.

So if you rotated that 2D matrix 90 degrees clockwise it would look like what I see from the physical setup.

Code

https://github.com/morbos/STM32/blob/master/L/L443/vl53l8x_l443/src

Comments

Popular posts from this blog

The Air32F103

 Bluepills Its no surprise that Bluepills, such as they were, a smoking sub $2 deal would dry up eventually, taken over by clones, some subtle, some overt. With supply issues still plaguing ST parts for hobbyists, what about these cheap Chinese clone parts? Lets dive into the Air32F103. Air32F103 I bought 5 of these $1.90 boards. They look like this: Some notables vs a stock bluepill: 1) Castellated pins with flat underside for use as a module 2) 3 LEDs R/G/B (vs just the G for a bluepill) 3) Clone of ST's peripherals 4) over clockable to 256Mhz (spec is 216Mhz) (original STM32F103CB is 72Mhz) 5) 32K of ram. But, via secret regs, 97K(!) 6) top and bottom debug pads, top for JLINK, bottom, legacy STLINK SWD 7) USB C vs USB mini 8) BOOT as a button vs jumper 9) 2 12bit DACs (STM32F103CB's don't have that) 10) QSPI (hidden support) 11) Undocumented crypto block from MegaHunt (includes: AES/DES/3DES/SHA/SM[1,3,4,7]) Clocking As mentioned 256Mhz is possible. One Q is how do they...

Ada on a $2 eBay 'Bluepill' board (STM32F103C8T6)

For about $2 a 'bluepill' board can be obtained from eBay. Taking its name from the PCB patina this small board is used in the Arduino community. The SoC itself per ST's early docs on it was 64k flash and 20k data, that said, all STM32F103C8's you buy nowadays are 128k flash. The CPU is a Cortex-M3 which can be run at 72Mhz maximum. There is a good website that shows the schematic and pinout of the bluepill: http://wiki.stm32duino.com/index.php?title=Blue_Pill If you are an Arduino programmer, the link above will take you where you want to go. But suppose you wanted to try programming and using the bluepill a different way? Well that is what this blog entry is about. An Ada port was done via AdaCores Ada_Drivers_Library and the Libre GNAT toolchain to the bluepill. This is preliminary work but it is able to generate working code that the author already is using as of yesterday (a garage parking measurement sensor).  The port of the library is derivative, ...

The STM32MP257F-EV1

 This is the follow on to the STM32MP1 series. This time a dual core Cortex-A35 a Cortex-M33 and a Cortex-M0+. As shipped, they provide a 16G micro SD card with Linux on it. That card is partitioned with a lot of odd small partitions. The important ones are at the end, p10 and p11. Unfortunately p10, the / partition is only 4G so immediately there is a storage crisis when you start populating the usual tools. A quick dd from that card to a 256G card I had lying around and we now have a start of something useful. Next is to run gparted on my RPi5 and first move p11 which is /usr/local to 1MiB from the end. Don't leave that as 0 or the move will fail. Once moved, you can resize p10 to be 200+G. Now we have some useful space. I added a user with sudoers privs. There is no date/time setup when it boots, that needs to get rectified with a ntp callout.  Now... there is no C compiler or binutils. binutils got installed. Lots of apt update -> apt install xyz's. Here is an interesti...