Welcome to TinyF Laser Ranging Module repository
esp32
TinyF and ESP32S3 serial communication
TinyF and ESP32S3 serial communication0.Introduction to TinyF1.Experimental Preparation2.Experimental wiring3. Main code explanation4.Experimental phenomenon5.Some important parameters of TinyF
0.Introduction to TinyF
- The TinyF laser ranging module is based on a D-TOF single-point laser sensor, an onboard MCU, and a housing. It features built-in sunlight rejection and anti-cover contamination algorithms, enabling accurate and rapid distance measurement. Even in extremely bright ambient light (100-190K Lux), it can accurately measure even the smallest objects, unaffected by variations in reflectivity, achieving precise ranging of 2m to 4m.
1.Experimental Preparation
- TinyF Laser Distance Measurement Module
- ESP32 S3 Series This tutorial uses the ESP32-WIFI Image Transmission + Communication Board.
2.Experimental wiring
| ESP32 | TinyF |
|---|---|
| TX1 | RX |
| RX1 | TX |
| GND | GND |
| 5V | 5V |
Wiring diagram

3. Main code explanation
xvoid parse_distance_data(char *line) { // 去除开始空白字符 Remove leading whitespace characters char *p = line; while (*p && (*p == ' ' )) p++; char *end = p + strlen(p) - 1; while (end > p && *end == '\n') end--; *(end+1) = '\0'; // 查找逗号位置 Find comma position char *comma = strchr(p, ','); if (comma == NULL) { return; } // 提取距离部分 Extract distance part *comma = '\0'; // 分割字符串 char *distance_str = p; char *confidence_str = comma + 1; // 去除置信度字符串前导空格 Remove leading whitespace characters from confidence string while (*confidence_str && (*confidence_str == ' ' )) confidence_str++; // 验证数据有效性 Validate data validity if (strlen(distance_str) == 0 || strlen(confidence_str) == 0) { return; } // 转换为整数 Convert to integer uint32_t distance = atoi(distance_str); uint32_t confidence = atoi(confidence_str); // 输出结果 Output results char result_buf[100]; int len = snprintf(result_buf, sizeof(result_buf), "Distance: %ldmm,Confidence: %ld\r\n", distance, confidence); uart_write_bytes(UART_NUM_0, result_buf, len); // 短暂延迟降低CPU使用率(非阻塞) Short delay to reduce CPU usage (non-blocking) vTaskDelay(pdMS_TO_TICKS(1));}The above program is used to parse data from the TinyF laser ranging module. Only when the protocol is met can the data be correctly parsed.
4.Experimental phenomenon
1.Use the bin file generated by the routine to open the ESP32S3 burning tool, configure it according to the figure below, and click the [START] button to download the bin file to the ESP32S3 development board.
2.Connect the wires according to the wiring diagram.
3.The serial port assistant is set to the interface as shown in the figure
4.After power on, the serial assistant will print the distance information
5.Some important parameters of TinyF
Related parameter description
| name | value |
|---|---|
| Baud rate | 115200 |
| Effective minimum distance (theoretical value) | 20,unit:mm |
| Effective maximum distance (theoretical value) | 4000,unit:mm |
| Confidence | 0~62,The larger the value, the higher the distance reliability. |
Data format
Data frame structure: 
Example: 
| Field | Number of bytes | Example(Hex) | ASCII characters |
|---|---|---|---|
| Frame header (fixed value) | 1 | 20 | space |
| Distance value(distance) | 1~5 | 33 32 37 | 327 |
| Delimiter (fixed value) | 2 | 2C 20 | ,space |
| Confidence(confidence) | 1~2 | 36 31 | 61 |
| Frame tail (fixed value) | 1 | 0A | \n |