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

7.K210 QR code command

K210 QR Code Command

K210 QR Code Command1. Hardware Connection2. Code Analysis3. Main Functions4. K210 Program Burning5. Experimental Phenomena

1. Hardware Connection

K210 Vision ModuleMSPM0G3507
5V5V
GNDGND
TXRX2
RXTX2

Physical Connection

image-removebg-preview

image-20251029164049976

image-20251029164030395

image-20251029164356332

2. Code Analysis

Control Principle

K210 Protocol

Start SymbolLengthRoutine NumberRoutine GroupData AmountxSeparatorySeparatorwSeparatorhSeparatorPayloadSeparatorChecksumEnd Symbol
$XX03BB05XXX,XXX,XXX,XXX,...,XX#

X: X-coordinate of the top-left corner of the detected box (range: 0-240) Y: Y-coordinate of the top-left corner of the detected box (range: 0-320) W: Width of the detected box (range: 0-240) h: Height of the detected box (range: 0-320) payload: Recognized string data

Control Flow Chart

Yes
No
Start
K210 detects target QR code
K210 sends data according to specified protocol
MCU parses data and controls car response
Car stationary

bsp_k210_use.c

xxxxxxxxxx
// 处理K210发来的单字节数据 / Process single-byte data from K210
void recv_k210msg(uint8_t recv_msg) 
{
    // 检测包头'$',开始接收新消息 / Detect header '$' to start receiving new message
    if (recv_msg == '$')
    {
        new_flag = 1;
    }
    
    // 检测包尾'#',结束接收并校验 / Detect tail '#' to end reception and verify
    if(recv_msg == '#' )
    {
        if( buf_len == r_index)  // 数据长度匹配 / Data length matches
        {
            new_flag = 0;
            tou_flag = 0;
            len_flag = 0;
            
            // 校验和计算:减去接收的校验和字节 / Checksum calculation: subtract received checksum byte
            buf_crc -= buf_msg[r_index-1];
            buf_crc %= 256;
            
            if(buf_crc == buf_msg[r_index-1])  // 校验正确 / Checksum verified
            {
                deal_recvmsg();  // 处理接收数据 / Process received data
            }
            else  // 校验失败 / Checksum failed
            {
                r_index = 0;
                buf_crc = 0;
            }
        }
    }
    
    // 正在接收新消息时的处理逻辑 / Processing logic when receiving new message
    if(new_flag == 1 )
    {
        if(recv_msg == '$' && tou_flag == 0)  // 首次接收包头 / Receive header for first time
        {
            tou_flag = 1;
        }
        else
        {
            buf_msg[r_index++] = recv_msg;  // 存储数据并递增索引 / Store data and increment index
            buf_crc += recv_msg;            // 累加校验和 / Accumulate checksum
            
            if(len_flag == 0)  // 未获取长度时,从首字节读取长度 / Read length from first byte if not obtained
            {
                buf_len = buf_msg[0];
                len_flag = 1;
            }
        }
    }
}
​
// 解析接收的完整消息 / Parse received complete message
void deal_recvmsg(void)
{
    uint8_t index,data_i=0;
    uint8_t eg_num = buf_msg[1];//例程编号 / Routine number
    uint8_t number = buf_msg[3];//数据量(包含逗号) / Data count including commas
    uint8_t i_duo = 0;          // 逗号过滤标志 / Comma filter flag
    
    if(r_index!=buf_len)//长度校验 / Length verification
    {
        buf_len = 0;
        return ;
    }
    
    // 提取有效数据(过滤逗号) / Extract valid data (filter commas)
    for(index = 0 ;index<number;index++)
    {
        if(buf_msg[4+index] == 0x2c && i_duo ==0)//遇到逗号且未过滤 / Encounter comma and not filtered
        {
            i_duo = 1;
            continue;
        }
        data[data_i++]=buf_msg[4+index];//存储有效数据 / Store valid data
        i_duo =0;
    }
    
    // 重置接收状态 / Reset receive state
    buf_crc = 0;
    r_index = 0;
    memset(buf_msg,0,sizeof(buf_msg));
    
    deal_data(eg_num);  // 处理解析后的数据 / Process parsed data
}
​

K210 Partial Source Code

xxxxxxxxxx
def send_data(x, y, w, h, msg):
    # 协议固定字段定义 / Protocol fixed field definition
    start = 0x24          # 帧头(对应ASCII字符'$',标识帧的开始) / Frame header (corresponds to ASCII character '$', marks frame start)
    end = 0x23            # 帧尾(对应ASCII字符'#',标识帧的结束) / Frame tail (corresponds to ASCII character '#', marks frame end)
    class_num = 0x03      # 例程编号(固定为0x03,标识当前是二维码识别任务) / Routine number (fixed at 0x03, identifies current QR code recognition task)
    class_group = 0x00    # 例程组(固定为0x00,与接收端约定的功能分类标识) / Routine group (fixed at 0x00, function classification identifier agreed with receiver)
    fenge = 0x2c          # 数据分隔符(对应ASCII字符',',用于区分不同数据段) / Data separator (corresponds to ASCII character ',', used to distinguish different data segments)
    crc = 0               # 校验和(初始为0,用于验证数据传输完整性) / Checksum (initially 0, used for data transmission integrity verification)
    data = []             # 数据列表(存储待封装的坐标、二维码内容等实际数据) / Data list (stores actual data to be encapsulated like coordinates, QR code content)
​
    # 坐标(x,y)和尺寸(w,h)封装(仅当参数不全为0时处理,避免无效数据) / Coordinate (x,y) and dimension (w,h) encapsulation (only process when parameters are not all 0, avoid invalid data)
    if x == 0 and y == 0 and w == 0 and h == 0:
        pass
    else:
        # 封装x坐标(小端模式:低位字节在前,高位字节在后,符合多字节传输规范) / Encapsulate x coordinate (little-endian mode: low byte first, high byte after, conforms to multi-byte transmission specification)
        low = x & 0xFF          # 取x的低8位(通过与0xFF运算保留低位) / Get low 8 bits of x (retain low bits by AND with 0xFF)
        high = (x >> 8) & 0xFF  # 取x的高8位(右移8位后过滤高位) / Get high 8 bits of x (filter high bits after right shift 8)
        data.extend([low, fenge, high, fenge])  # 按「低位,高位,」格式添加到数据列表 / Add to data list in "low,high," format
​
        # 封装y坐标(逻辑与x一致,小端模式+分隔符) / Encapsulate y coordinate (logic same as x, little-endian mode + separator)
        low = y & 0xFF
        high = (y >> 8) & 0xFF
        data.extend([low, fenge, high, fenge])
​
        # 封装w(宽度,逻辑同上) / Encapsulate w (width, logic same as above)
        low = w & 0xFF
        high = (w >> 8) & 0xFF
        data.extend([low, fenge, high, fenge])
​
        # 封装h(高度,逻辑同上) / Encapsulate h (height, logic same as above)
        low = h & 0xFF
        high = (h >> 8) & 0xFF
        data.extend([low, fenge, high, fenge])
​
    # 二维码内容(msg)封装(仅当内容不为空时处理) / QR code content (msg) encapsulation (only process when content is not empty)
    if msg is not None:
        # 遍历内容的每个字符,转十进制后添加到数据列表 / Traverse each character of content, convert to decimal then add to data list
        for i in range(len(msg)):
            hec = str_int(msg[i])  # 调用简化的转十进制函数 / Call simplified decimal conversion function
            data.append(hec)
            data.append(fenge)  # 每个字符后添加分隔符 / Add separator after each character
        print(data)  # 打印数据列表(调试用,查看封装结果) / Print data list (for debugging, view encapsulation result)
​
    # 移除数据列表末尾可能多余的分隔符(避免接收端解析错误) / Remove possible redundant separator at end of data list (avoid receiver parsing error)
    if data and data[-1] == fenge:
        data.pop()  # 删除列表最后一个元素(多余的分隔符) / Delete last element of list (redundant separator)
……

3. Main Functions

BSP_Loop

Function Prototypevoid BSP_Loop(void)
Function DescriptionMain loop function: when K210 recognizes target of category 3, controls car movement (backward, forward, left turn, right turn) based on parsed string command (k210_msg.msg_msg), displays command on OLED, and resets category identifier after execution
Input ParametersNone
Return ValueNone

4. K210 Program Burning

After downloading and opening CanMV IDE, we need to first drag the k210_qrcode.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 helloworld.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, place QR codes in front of K210. When recognizing specified QR codes, the car will execute corresponding actions.

Below are the QR codes used in the tutorial:

image-20231031094208747

goback

image-20231031094208747

goahead

image-20231031094208747

turnleft

image-20231031094208747

turnright

K210 following machine code
K230 vision line 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/中文