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

3.STM32F103C8T6

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 STM32F103C8T6 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 STM32F103C8T6 core board and eight-channel grayscale line-following module sold by Yabo. Refer to the wiring diagram below to connect the wires, then program the motherboard to obtain the data. Modules not from Yabo are for reference only.

2. Hardware Wiring

The STM32 motherboard's Type-C port needs to be connected to the computer's USB port.

image-20251110153150468

Eight-channel grayscale tracking moduleSTM32F103C8T6
5V5V
GNDGND
AD0PA0
AD1PA1
AD2PA2
OUTPA3

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

image-20251108181811636

3. Usage Method

  1. Open the FlyMcu programming tool. Select the hex file in the code project. The areas highlighted in red should match the image.

image-20251110153459145

  1. Connect the STM32 to the computer. Click "Search Serial Ports" and select the COM port corresponding to the STM32.

image-20251110153654678

  1. Then click "Start Programming." The program will begin to be burned into the motherboard. Wait for the progress bar on the right to complete, and you will see a message indicating successful burning.

image-20251110153833674

  1. Press the NRST reset button on the motherboard to restart the motherboard and run the program. Then open the serial port assistant to view the printed information.

4. Phenomenon and Results

In 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
// main.c
int main(void)
{   
    bsp_init(); // Initialize onboard peripherals, including the serial port and delay timer.
    Grayscale_Sensor_Init(); // Initialize grayscale sensor GPIO
​
    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(60);
    }
}
  • main: The main entry point of the program. First, bsp_init() is called to initialize all Board Support Package (BSP) hardware, including the serial port and Systick delay. Then, Grayscale_Sensor_Init() is called to initialize the sensor I/O ports. In an infinite loop, the program continuously calls Grayscale_Sensor_Read_All() to acquire sensor data and prints it out using printf.
// grayscale_sensor.c
void Grayscale_Sensor_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
​
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}
​
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();
    }
}
​
static void _select_channel(uint8_t channel)
{
    SENSOR_AD0_WRITE((channel >> 0) & 0x01);  // bit0 -> AD0
    SENSOR_AD1_WRITE((channel >> 1) & 0x01);  // bit1 -> AD1
    SENSOR_AD2_WRITE((channel >> 2) & 0x01);  // bit2 -> AD2
}
  • Grayscale_Sensor_Init: Initializes GPIO using STM32 standard peripheral library functions. First, it enables the clock on GPIOA, then configures PA0-PA2 as push-pull outputs for channel selection, and configures PA3 as a floating input for data reading.
  • 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.
  • _select_channel: Controls the GPIO level using the SENSOR_ADx_WRITE macro to select the corresponding sensor.
MSPM0G3519
ESP32

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/中文