yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

1.K210 autonomous driving

K210 Autonomous Driving

K210 Autonomous Driving1. Hardware Connection2. Code Analysis3. Main Functions4. K210 Program Burning5. Experimental Phenomena

1. Hardware Connection

K210 Vision ModuleMSPM0G3507
5V5V
GNDGND
RXTX2
TXRX2

Physical Connection Diagram

image-removebg-preview

Schematic Diagram

image-20251029164049976

image-20251029164030395

image-20251029164356332

K210 Protocol

Experiment RoutineStart SymbolLengthRoutine NumberRoutine GroupData AmountxSeparatorySeparatorwSeparatorhSeparatorChecksumEnd Symbol
Color Recognition$XX01BB04XXX,XXX,XXX,XXX,XX#

Control Flow Chart

Yes
Yes
No
No
Start
K210 threshold learning successful
KEY1 pressed?
MCU parses data and controls car response
Car stationary

 

2. Code Analysis

bsp_k210_use.c

xxxxxxxxxx
// 解析接收的完整消息 / Parse received complete message
void deal_recvmsg(void)
{ ...
    if(r_index!=buf_len)
    {
        buf_len = 0;
        return ;
    }
    
    // 提取有效数据(过滤逗号) / Extract valid data (filter commas)
    for(index = 0 ;index<number;index++)
    {
        if(buf_msg[4+index] == 0x2c && i_duo ==0)
        {
            i_duo = 1;
            continue;
        }
        data[data_i++]=buf_msg[4+index];
    }
    
    // 重置接收状态 / Reset receive state
    buf_crc = 0;
    r_index = 0;
    memset(buf_msg,0,sizeof(buf_msg));
    
    deal_data(eg_num);  
}
​

K210 Partial Source Code

xxxxxxxxxx
# 数据发送函数:将坐标、尺寸、消息封装成协议格式并准备发送 / Data sending function: encapsulates coordinates, dimensions, messages into protocol format and prepares for sending
def send_data(x, y, w, h, msg):
    # 协议帧头(对应ASCII的'$') / Protocol frame header (corresponds to ASCII '$')
    start = 0x24
    # 协议帧尾(对应ASCII的'#') / Protocol frame footer (corresponds to ASCII '#')
    end = 0x23
    # 基础长度(初始值,后续会根据数据长度更新) / Base length (initial value, will be updated based on data length)
    length = 5
    # 例程编号(固定为0x01) / Routine number (fixed as 0x01)
    class_num = 0x01
    # 例程组(固定为0xBB) / Routine group (fixed as 0xBB)
    class_group = 0xBB
    # 数据量(初始值为0,后续统计实际数据个数) / Data amount (initial value 0, will count actual data items later)
    data_num = 0x00
    # 分隔符(对应ASCII的逗号',') / Separator (corresponds to ASCII comma ',')
    fenge = 0x2c
    # 校验和(初始值为0,后续计算) / Checksum (initial value 0, will be calculated later)
    crc = 0
    # 存储数据的列表(用于组装待发送数据) / Data list for storage (used to assemble data to be sent)
    data = []
​
    # 若坐标和尺寸全为0,不添加数据(跳过参数封装) / If coordinates and dimensions are all 0, don't add data (skip parameter encapsulation)
    if x == 0 and y == 0 and w == 0 and h == 0:
        pass
    else:
        # 封装x坐标(小端模式:低位字节在前,高位字节在后) / Encapsulate x coordinate (little-endian: low byte first, high byte second)
        low = x & 0xFF  # 取x的低8位(低位字节) / Get low 8 bits of x (low byte)
        high = x >> 8 & 0xFF  # 取x的高8位(高位字节) / Get high 8 bits of x (high byte)
        data.append(low)
        data.append(fenge)  # 添加分隔符 / Add separator
        data.append(high)
        data.append(fenge)  # 添加分隔符 / Add separator
​
        # 封装y坐标(小端模式) / Encapsulate y coordinate (little-endian)
        low = y & 0xFF
        high = y >> 8 & 0xFF
        data.append(low)
        data.append(fenge)
        data.append(high)
        data.append(fenge)
        ...
    # 若消息不为空,封装消息数据 / If message is not empty, encapsulate message data
    if msg is not None:
        # 遍历消息的每个字符,转换后添加到数据列表 / Iterate through each character of the message, convert and add to data list
        for i in range(len(msg)):
            hec = str_int(msg[i])  # 字符转十进制 / Convert character to decimal
            data.append(hec)
            data.append(fenge)  # 添加分隔符 / Add separator
​
    # 更新数据量(数据列表的元素个数) / Update data amount (number of elements in data list)
    data_num = len(data)
    # 更新总长度(基础长度 + 数据长度) / Update total length (base length + data length)
    length += len(data)
​
    # 组装核心数据(长度、例程编号、例程组、数据量 + 实际数据) / Assemble core data (length, routine number, routine group, data amount + actual data)
    send_merr = [length, class_num, class_group, data_num]
    for i in range(data_num):
        send_merr.append(data[i])
​
    # 计算校验和(对核心数据的所有字节求和,再对256取模) / Calculate checksum (sum all bytes of core data, then modulo 256)
    for i in range(len(send_merr)):
        crc += send_merr[i]
    crc = crc % 256
​
    # 组装完整协议帧:添加帧头、校验和、帧尾 / Assemble complete protocol frame: add frame header, checksum, frame footer
    ...
# 定义中心采样方框(50x50像素,位于QVGA画面中心) / Define center sampling box (50x50 pixels, located at center of QVGA screen)
BOX = 50
r = [(320//2)-(BOX//2), (240//2)-(BOX//2), BOX, BOX]
...
​
    # 组装完整协议帧(帧头 + 核心数据 + 校验和 + 帧尾) / Assemble complete protocol frame (frame header + core data + checksum + frame footer)
    send_merr.insert(0, start)      
    send_merr.append(crc)       
                               
    send_merr.append(end)            
    ……
    img = sensor.snapshot()
    # 获取采样区域的颜色直方图(统计该区域内颜色分布,用于计算阈值) / Get color histogram of sampling area (counts color distribution in this area for threshold calculation)
    hist = img.get_histogram(roi=sample_roi)
    # 获取直方图1%分位值(对应颜色下限,过滤极暗/极淡的噪声像素) / Get 1% percentile of histogram (corresponds to color lower limit, filters extremely dark/light noise pixels)
    lo = hist.get_percentile(0.01)
    # 获取直方图70%分位值(对应颜色上限,覆盖目标物体的主要颜色范围) / Get 70% percentile of histogram (corresponds to color upper limit, covers main color range of target object)
    hi = hist.get_percentile(0.7)
​
    ……

3. Main Functions

APP_K210X_Line_PID

Function Prototypevoid APP_K210X_Line_PID(void)
Function DescriptionLine following PID control function based on K210 camera feedback: calculates position deviation of black line in camera view (based on screen center 160, combined with offset and target area parameters), calls APP_K210X_PID_Calc to get steering control amount, controls car movement through Motion_Ctrl (straight line speed is K210X_SPEED)
Input ParametersNone
Return ValueNone

BSP_Loop

Function Prototypevoid BSP_Loop(void)
Function DescriptionMain loop function: detects short press events to switch g_key_flag state. When g_key_flag is 0, stops motors and resets motor PID; when 1, executes APP_K210X_Line_PID for camera line following control
Input ParametersNone
Return ValueNone

4. K210 Program Burning

After downloading and opening CanMV IDE, we need to first drag the follow_line.py file from the k210 source code provided in this course to CanMV IDE to open it, then connect the IDE, here using helloworld.py as example

image-20251029180540342

After successful IDE connection, the phenomenon is as follows

image-20251029181342135

Here we use follow_line.py as an example, open the top menu bar Tools -> Save currently open script as (main.py) to CanMV Cam

image-20251029205906069

image-20251029181630720

Both Yes/No can be selected here. When the following status appears, the write is successful.

image-20251029181701230

5. Experimental Phenomena

After burning the program, turn on the power switch, wait for system initialization to complete, the LCD displays the camera image, and there is a white box in the center of the screen. Please place the color to be recognized in the white box, wait for the white box to turn green to start color collection. After collection is complete, the green box disappears and the program starts running. After color learning is successful, press KEY1 on the development board, the car will start line following. Note that learning must be successful before pressing KEY1, otherwise you need to adjust the histogram percentile values according to the environment.

Autonomous driving car
K210 color tracking

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