In recent years, I've been intrigued by several new range sensor technologies compared to traditional sensors like low-cost IR and ultrasonic sensors that only report a single distance value straight ahead, or expensive lidar sensors that report distance all around. After attending the ST Tech Tour in Thailand, I was particularly impressed with the multizone Time-of-Flight (ToF) sensor. I saw a demonstration of its ability to detect distances in a frontal 8x8 grid area. I checked the specifications for the VL53L8 model and was further impressed by its 45-degree field of view in both horizontal and vertical directions, resulting in a diagonal field of view of 65 degrees. With a detection range of 4 meters, it covers a typical indoor room area, which is perfect for my smart home applications.
I was surprised by the lack of information and usage examples for this sensor group. I asked the STMicro folks and learned that their primary market is smartphones, which practically eliminates the need for marketing. So, I wanted to write a brief introduction to using the VL53L8 sensor for anyone looking for a solution for their project. Even though ST doesn't heavily promote this sensor, there are two development boards available for purchase:
- X-NUCLEO-53L8A1: This is an Arduino shield board, making it easy to use by plugging it directly onto the Arduino header.
- SATEL-VL53L8: This is an add-on board that requires manual wiring. While it's more complex to use, it comes with two boards for a similar price.
When choosing a board, I was a bit confused because the chip on the board is the VL53L8CA, which is not listed on ST's website. There are only the VL53L8CX, which focuses on low-power consumption, and the VL53L8CH, which aims for AI applications. I asked ST and learned that ST may start with a model that has all the features when releasing a new product and then remove features (reduce cost) to match customer usage.
April has a one-week holiday (Songkran) across Thailand, I decided to take a break from work to try out the sensor. Fortunately, STMicroelectronics' eStore was having a free shipping promotion until the end of March, so I ordered an X-NUCLEO-53L8A1 board online. It arrived within a week, and after paying some taxes, I could finally try it out. The sample code for the VL-53L8A1 board was developed for the NUCLEO-F401RE and NUCLEO-L486RG boards, and I happened to have a NUCLEO-F401RE board, so I could start experimenting right away. The output of the sample code sends messages through the serial port to be displayed using the Tera Term program, which emulates a terminal VT100 screen.
I have several ST boards with Arduino headers, and some of them also have wireless communication capabilities. I was curious to see if the sample code could be used with other boards. ST has developed the X-CUBE-TOF1 software suite to extend the STM32CubeMX program, which is used to create projects and starter code for STM32 boards. So, I thought I'd give it a try. The boards I'll be using are the B-L475E-IOT01A, which uses the STM32L475 processor and WiFi and Bluetooth wireless communication, and the NUCLEO-WB55, which uses the STM32WB55RG processor and Bluetooth wireless communication.
The VL53L8CA chip can be connected via I2C (SPI can also be selected by switching a jumper on the board), an external interrupt pin for triggering data reading, and two digital output pins for controlling operation (LPn and PWR). After reviewing the schematic and correlating it with the pin positions on the Arduino shield header of the NUCLEO-F401RE, I found that the relevant pin positions are D14, D15, A2, D10, and D11. These pin positions can be checked on the board to be tested.
The STM32CubeMX program is a GUI tool for creating projects (STM32CubeIDE, Keil MDK-ARM, IAR EWARM) that reduces the hassle of setting up hardware and additional software. After installing X-CUBE-TOF1, you can select to generate code and configure the hardware for connecting the VL53L8 chip from the Middleware and Software Packs section by entering the relevant port. Then, you can generate the code as a project according to your needs.
After installing the setup on the B-L474E-IOT01A board and using the Tera Term program to receive and display data, I was able to successfully operate in both 8x8 mode and signal strength reporting mode. This confirms that the code generated from X-CUBE-TOF1 is functioning correctly.
In my personal opinion, I am generally impressed with the development tools for VL53L8. However, I have a few criticisms for ST's developers: Unnecessarily complex code: For example, the code for reading distance is hidden in the MX_53L8A1_SimpleRanging_Process() function in the app_tof.c file, which is an infinite loop. This makes it difficult to port the code to other hardware. There are two main approaches to address this:
- Move the code from MX_53L8A1_SimpleRanging_Process() into the main loop: This would make the code more straightforward and easier to understand.
- Use FreeRTOS and put the TOF code in a task: This would allow for better task management and synchronization. The TOF code could then communicate with other tasks using IPC mechanisms such as queues.
For those who are not fond of the STM32 development tools, a simpler alternative is to use STM32duino, which is a port of Arduino for STM32 microcontrollers. The advantage of STM32duino is that there are developers who have converted the example code into a VL53L8CX library that works on the STM32duino platform. This makes it easy to experiment with the VL53L8CX sensor using Platform.io on VS Code. You only need to specify the LPn and PWR pins.
One of the main advantages of Platform.io is the ease of using various Arduino libraries. For instance, installing the PubSubClient and ArduinoJSON libraries allows me to write code for reporting values via MQTT in a straightforward manner.
While STM32CubeMX with X-CUBE-TOF1 offers a powerful and versatile approach for VL53L8CX integration, its complexity can be a hurdle. For those seeking a simpler development experience, STM32duino with its pre-built libraries and the user-friendly Platform.io IDE provides a compelling alternative. The ease of incorporating libraries like PubSubClient and ArduinoJSON further streamlines tasks like data reporting.
Comments
Please log in or sign up to comment.