yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
8-channel Grayscale Tracking Module📖
0. Precautions for use
  • Identifying Defective Solutions
1.About 8-channel tracking module
  • 8-channel grayscale module introduction
2.MCU data reading
  • 1.MSPM0G3507
  • 2.MSPM0G3519new
  • 3.STM32F103C8T6
  • 4.ESP32
  • 5.Arduino
  • 6. Raspberry Pi Pico
3.Car gray line tracking
  • 1. MSPM0 Smart Car
  • 2. STM32 development board for small car
  • 3. ESP32 wheeled car chassis V1
  • 4. Arduino Wheeled Car Chassis V2
  • 5. Raspberry Pi Pico Wheel Car Chassis V2
Download
  • Code
  • 3D Model File
  • Serial Port Assistant
Download ZIP

Welcome to 8-channel Grayscale Tracking Module repository

4.ESP32

Data Reading

Data Reading1. Quick Start2. Hardware Wiring3. Usage Method4. Phenomenon and Results5. Code Explanation

1. Quick Start

This tutorial explains how to use the ESP32-S3 motherboard to read the digital information from an eight-channel grayscale line-following module and print the results via a serial port assistant.

The hardware used in this tutorial is the ESP32-S3 WIFI image transmission module lite and the eight-channel grayscale line-following module sold by Yabo. After connecting the wires according to the wiring diagram below, you can obtain the data by programming the ESP32-S3. Modules other than Yabo's are for reference only.

2. Hardware Wiring

The ESP32-S3's USB port needs to be connected to the computer's USB port using a data cable.

image-20251110120223042

The eight-channel grayscale module sold by Yabo uses XH2.54 to 6-pin DuPont cable for connection:

image-20251108181811636

Eight-channel grayscale line-following moduleESP32-S3
5V5V
GNDGND
AD0RX1(35)
AD1TX1(36)
AD2SCL(37)
OUTSDA(38)

The serial port and IIC identifiers here are merely labels used on the ESP32 module board; the serial port and IIC functions are not actually used.

3. Usage Method

  1. Open the programming tool flash_download_tool, select the ESP32-S3 chip, and then click OK.

image-20251108164349999

  1. Connect the ESP32-S3 to the computer via a data cable, and then select the COM port and baud rate in the software.

image-20251108171708938

  1. In the SPIDownload window, select three ESP32S3 firmware files to be burned. The path is usually in the build folder under the root directory of the code project. The format is a .bin file. Remember to enter the firmware address. Make sure the box to the left of ".bin file" is checked, and both the file name and address are green.

Check "DoNotChgBin". Leave other configurations as default.

image-20251108171512164

The file and address mapping is shown in the table below:

Firmware NameFirmware AddressRemarks
bootloader.bin0x0000Boot file
partition-table.bin0x8000Partition table file
Grayscale_Read.bin0x10000Function file
  1. Click the START button, and the tool will automatically begin flashing the firmware.

Note: If flashing the firmware does not start automatically, please press and hold the IO0 key, then press the EN key, and release them simultaneously to manually enter flashing mode, and then click the START button.

image-20251108171739962

  1. After downloading, a blue FINISH indicator will appear. At this point, power off and restart the microcontroller or press the EN key to restart the program and close the programming tool. Finally, use a serial port assistant to open this port to see the printed information.

image-20251108171820207

4. Phenomenon and Results

After programming, open the serial port assistant. You can see the continuously printed digital values ​​of the eight-channel grayscale tracking module. X1 corresponds to X1 on the module; when the X1 LED is lit, the corresponding value is 1.

image-20251108171858515

5. Code Explanation

x
// Grayscale_Read.c
void app_main(void)
{
    Grayscale_Sensor_Init();    
​
    xTaskCreate(
       Grayscale_ReadData_Task, // Task function
       "GrayscaleReadData", // Task name
       4096, // Stack size (bytes)
       NULL,
       2, // Priority
       NULL
    );
}
​
void Grayscale_ReadData_Task(void *arg) {
    while (1) {
        Grayscale_Sensor_Read_All(g_sensor_data);
        
        for (i = 0; i < GRAYSCALE_SENSOR_CHANNELS; i++)
        {
            printf("[ %s:%d ]", sensor_labels[i], g_sensor_data[i]);
        }
        printf("\n");
        delay_ms(100);
    }
}
  • app_main: The main entry point function for the ESP-IDF project. It first calls Grayscale_Sensor_Init() to initialize the sensor, and then uses xTaskCreate() to create a FreeRTOS task specifically for reading and printing sensor data.
  • Grayscale_ReadData_Task: An infinite loop task. In each loop, it calls Grayscale_Sensor_Read_All() to retrieve the latest sensor data, and then formats and outputs the data to the serial port using printf.
x
// grayscale_sensor.c
void Grayscale_Sensor_Init(void)
{
    gpio_config_t io_conf_output = {
        .pin_bit_mask = (1ULL << 35) | (1ULL << 36) | (1ULL << 37),
        .mode = GPIO_MODE_OUTPUT,
        //...
    };
    gpio_config(&io_conf_output);
    
    gpio_config_t io_conf_input = {
        .pin_bit_mask = (1ULL << 38),
        .mode = GPIO_MODE_INPUT,
        //...
    };
    gpio_config(&io_conf_input);
}
​
void Grayscale_Sensor_Read_All(uint16_t* sensor_values)
{
    uint8_t i;
    for (i = 0; i < GRAYSCALE_SENSOR_CHANNELS; i++)
    {
        _select_channel(i);
        _delay_us(50);
        sensor_values[i] = Read_OUT_value();
    }
}
  • Grayscale_Sensor_Init: Initializes GPIOs using the gpio_config structure and functions provided by ESP-IDF. Configures control pins (GPIO35-37) as outputs and data pins (GPIO38) as inputs.
  • Grayscale_Sensor_Read_All: Iterates through all 8 sensor channels, selects a channel using _select_channel, reads its value, and stores it in an array.
STM32F103C8T6
Arduino

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文