Skip to main content

Raspberry Pi · configuration

TF series LiDAR with Raspberry Pi CAN / UART / TTL / UART: integration and configuration guide

Setup, connection, configuration and code guidance for TF series LiDAR with Raspberry Pi. The original files are available in Materials and downloads. Documented interface: CAN, UART / TTL, UART.

Interfaces
CAN, UART / TTL, UART
Hardware targets
Raspberry Pi, Raspberry Pi Pico
Organized
2026-08-31
Source note
Source material date: 2026-08-31.

Applicable setup

TF series LiDAR · Raspberry Pi · CAN, UART / TTL, UART · Raspberry Pi Pico

Technical instructions and steps

Interfacing TF Series Single Point LiDARs with Raspberry Pi Pico

Written by: Ibrahim (FAE)

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

This article explains how to interface Benewake single point LiDARs with Raspberry Pi Pico microcontroller. The following assumptions are made while writing this article:

1. The end-user has Pico microcontroller and any of the single point LiDARs (Luna,

TFmini-Plus, mini-S, TF02-pro, TF03-UART) in hands 2. The development environment (including Pico SDK) for compiling the C code has already been set 3. All the necessary cables and 5V power supply 4. The LiDAR interface mode is TTL 5. Any editor for writing and modifying the script (VS Code is recommended)

2|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

Pin configuration of Pico Controller:

Full documentation about Pico is available on Raspberry Pi website, but here we will discuss briefly the pinouts for easiness and we will see which pins can be used for UART interfacing. The following image shows the pinout of Pico (to see the details zoom in the picture):

Figure 1: Pinouts

According to the datasheet of Pico, it has two UART ports and these ports can be directed to any of the available pins. Looking at the above image (GP0, GP1), (GP4, GP5), (GP8, GP9), (GP12, GP13), and (GP16, GP17) are suitable for UART communication. In our code we used GPIO-4 and 5. It should be noted that there is only single pin for voltage supply and that is also 3.3V, while the rated voltage for Benewake LiDAR is 5V. If the voltage is not 5V, the accuracy will be affected and error will be more than rated error, in some cases the error is non-linear and it increases with increase in distance. It may reach up to 40cm. So it is advised to use separate 5V supply for LiDAR.

3|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

Schematic diagram:

The connection diagram for interfacing LiDAR to Pico and using a separate power supply is given below:

Figure 2: Connection Diagram

For exact details about LiDAR current rating and your supply capacity, please refer to their respective data-sheets.

Default UART Communication Parameters of TF Series: According to the data-sheet of TF series LiDARs the parameters of UART:

Figure 3: UART Communication

4|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

So the UART communication in code script is established based on this information.

Cable Selection and Connector: All Benewake Single Points LiDARs have either 4-pin or 7pin (for TF03) Molex connector, so the required mating connector is JST 1.25mm. Please refer to the link1. You can choose either 4- pin or 7-pin depending upon the LiDAR that you have. On the controller side if you are using breadboard then you can choose male-DuPont connector or any other suitable connector based on user-end side. One of the sample cable is shown below:

Figure 4: JST 1.25 4P to DuPont cable

Table III: Data format (for mid and small range LiDARs)

1 https://www.aliexpress.com/i/4000580232835.html

5|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

Table IV: Data format (TF03 Series)

C code for Pico Controller: In this section we will discuss the main parts of C code that are used for reading the data from Benewake LiDAR. Adding necessary libraries:

#include<stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "pico/binary_info.h"
#include "hardware/uart.h"
#include "tusb.h" // this header file will handle the problem of losing initial o
utput

Pin initialization for UART port:

Like mentioned above there are two serial ports (port-0 and port-1). I used port-1.

#define BAUDRATE 115200 #define UARTID1 uart1 #define UART1TXPIN 4 // pin-6 #define UART1RXPIN 5 // pin-7 I used structures of C language to handle LiDAR data.

//****************************Structure and Union for handling LiDAR Data********
***

//DistL DistH StrengthL StrengthH TempL TempH Checksum typedef struct{ unsigned short Header;

6|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

unsigned short Dist; unsigned short Strength; }structLidar;

union unionLidar{ unsigned char Byte[9]; structLidar lidar; };

unsigned char lidarCounter=0; union unionLidar Lidar; //Structure and Union for handling LiDAR Data *** Function for processing UART communication:

//****************************Function to read serial data***********
int isLidar(uart_inst_t * uart, union unionLidar * lidar)
{
int loop;
int checksum;
unsigned char serialChar;
while(uart_is_readable(uart))
{
if(lidarCounter > 8)
{
lidarCounter=0;
return 0; // something wrong
}
serialChar = uart_getc(uart); // Read a single character to UART.
lidar->Byte[lidarCounter]= serialChar;

switch(lidarCounter++) { case 0: case 1: if(serialChar !=0x59) lidarCounter=0; break; case 8: // checksum checksum=0;

7|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

lidarCounter=0;
for(loop=0;loop<8;loop++)
checksum+= lidar->Byte[loop];
if((checksum &0xff) == serialChar)
{
//printf("checksum ok\n");
lidar->lidar.Dist = lidar->Byte[2] | lidar->Byte[3] << 8;
lidar->lidar.Strength = lidar->Byte[4] | lidar->Byte[5] << 8;
return 1;
}
//printf("bad checksum %02x != %02x\n",checksum & 0xff, serialChar);
}
}
return 0;
}
//****************************Function to read serial data***********
In the main function I run while loop which will continuously monitor the data flow on serial
port and print it to the screen. The LED of Pico which is connected to Pin-25, will continuously
blinking as data is processed. There are some binary info related code which I didn’t explain, that
is only used for debugging purpose and is not very necessary.

// cdcdinit(); printf("waiting for usb host"); while (!tudcdcconnected()) { printf("."); sleepms(500); } printf("\nusb host detected!\n"); // The above part of code will wait for USB host to get connected, once it is connected, the code flow will move to the next step. While the following code checks if UART port is enabled:

//************************************************************
// In a default system, printf will also output via the default UART
sleep_ms(5000);
ret = uart_is_enabled (uart1);
if(ret == true){
printf("UART-1 is enabled\n");
}
printf("Ready to read data from Benewake LiDAR\n");

8|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

While Loop:

while(true){
gpio_put(LED_PIN, 0);
sleep_ms(100);
gpio_put(LED_PIN, 1);
if(isLidar(UART_ID1,&Lidar))
{
// ok we got valid data
// Here we utilized the Union
printf("Dist:%u Strength:%u \n",\
Lidar.lidar.Dist,\
Lidar.lidar.Strength);
}
}
CMakeLists.txt:

addexecutable(tfseries tf_series.c)

# Pull in our pico_stdlib which pulls in commonly used features, also add hardware uart because we are going to use uart port

targetlinklibraries(tfseries picostdlib hardware_uart)

# enable/diable usb output, and uart output

picoenablestdiousb(tfseries 1) # 1 means enable and 0 means disable

picoenablestdiouart(tfseries 1)

# create map/bin/hex file etc.

picoaddextraoutputs(tfseries)

# add url via picosetprogram_url

exampleautoseturl(tfseries)

9|Page

TF Series Interfacing with Pico Benewake (Beijing) Co. Ltd.

You can either get the code from Technical Support of Benewake or download from GitHub Link2.

2 https://github.com/ibrahimqazi/Benewake-TF-Series-LiDAR-Interfacing-with-Pico

10 | P a g e

Use and verification

The technical content follows the readable source material. Confirm the product hardware revision, flight-stack or software version, and field safety boundary against the original material and current platform documentation.

Materials and downloads

Product inquiry

Talk to a product specialist

Tell us what you need and our team will get back to you.

Product inquiry

Inquiry sent

Your inquiry has been received. We will be in touch soon.