yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
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

5.K210 road sign indication action

K210 Road Sign Indication Action

K210 Road Sign Indication Action1. Hardware Connection2. Code Analysis3. Main Functions4. K210 Program Burning5. Experimental Phenomena

1. Hardware Connection

K210 Vision ModuleMSPM0G3507
5V5V
GNDGND
TXRX2
RXTX2

Physical Connection Diagram

image-removebg-preview

 

Schematic Diagram

image-20251029164049976

image-20251029164030395

image-20251029164356332

2. Code Analysis

Control Principle

K210 Protocol

Header 1Header 2LengthFunction CodeCar TypeX-axis SpeedX-axis SpeedY-axis SpeedY-axis SpeedZ-axis SpeedZ-axis Speedchecksum
0xFF0xFC0x0A0x12XXLow ByteHigh ByteLow ByteHigh ByteLow ByteHigh ByteXX

Control Flow Chart

Yes
No
Yes
No
Start
K210 sequentially learns 3 types of road signs
Road sign learning completed
Car moves forward
K210 recognizes specified road sign
Car executes specified action

revaction.c

xxxxxxxxxx
//数据分析 / data analysis
void Upper_Data_Parse(uint8_t *data_buf, uint8_t num)
{
    uint8_t func_id = *(data_buf + 3);
    switch (func_id)
    {
    /* 判断功能字:小车速度设置 / Determine function code: car speed setting */
    case FUNC_MOTION:
    {
        uint8_t parm = (uint8_t) *(data_buf + 4);
        int16_t Vx_recv = *(data_buf + 6) << 8 | *(data_buf + 5);
        int16_t Vy_recv = *(data_buf + 8) << 8 | *(data_buf + 7);
        int16_t Vz_recv = *(data_buf + 10) << 8 | *(data_buf + 9);
        uint8_t adjust = parm & 0x80;
​
        if (Vx_recv == 0 && Vy_recv == 0 && Vz_recv == 0)
        {
            Motor_Stop(1);
            g_start_ctrl =0;
        }
        else
        {
            Motion_Car_Control(Vx_recv, Vy_recv, -Vz_recv);
        }
        break;
    }
​
    /* 判断功能字:彩灯控制 / Determine function code: RGB light control */
    case FUNC_RGB:
    {
        u8 red = *(data_buf + 5);
        u8 green = *(data_buf + 6);
        u8 blue = *(data_buf + 7);
        rgb_SetRGB(WS2812_MAX, red, green, blue);
        rgb_SendArray();
        break;
    }
    
    default:
        break;
    }
}

K210 Partial Source Code

xxxxxxxxxx
# 针对2.1.1版本固件的适配:将此处引脚从原数值改为17(根据固件版本调整硬件引脚映射) / Adaptation for firmware version 2.1.1: change pin from original value to 17 (adjust hardware pin mapping according to firmware version)
fm.register(16, fm.fpioa.GPIOHS0)  # 注册引脚16为GPIOHS0(用于连接启动按键) / Register pin 16 as GPIOHS0 (for connecting start button)
                                
boot_gpio = GPIO(GPIO.GPIOHS0, GPIO.IN)  # 初始化GPIOHS0为输入模式,作为启动按键的GPIO对象 / Initialize GPIOHS0 as input mode, as GPIO object for start button
​
# 初始化摄像头参数 / Initialize camera parameters
# Initialize camera parameters
...              
kpu = KPU()  
#初始化KPU(K210的AI加速模块,用于运行深度学习模型) / Initialize KPU (K210's AI acceleration module for running deep learning models)
​
# 从SD卡指定路径加载KPU模型(此处为自学习分类器模型mb-0.25.kmodel) / Load KPU model from specified SD card path (here is self-learning classifier model mb-0.25.kmodel)
kpu.load_kmodel("/sd/KPU/self_learn_classifier/mb-0.25.kmodel")
​
# 初始化状态机:传入状态处理器、事件处理器和状态转移规则,管理系统运行流程 / Initialize state machine: pass state handler, event handler and state transition rules to manage system operation flow
....                      
# 初始化按键相关变量(用于按键计时和状态检测) / Initialize button-related variables (for button timing and state detection)
btn_ticks_prev = time.ticks_ms()  # 记录上一次按键时间戳(毫秒级) / Record previous button timestamp (millisecond level)
​
boot_btn = Button(state_machine)  # 初始化启动按键对象,关联状态机(按键操作触发状态转移) / Initialize start button object, associate with state machine (button operations trigger state transitions)
​
try:
    while True:
        btn_ticks_cur = time.ticks_ms()  # 获取当前时间戳 / Get current timestamp
        # 计算当前与上一次按键的时间差(用于判断按键长按/短按) / Calculate time difference between current and previous button press (for determining long/short press)
        delta = time.ticks_diff(btn_ticks_cur, btn_ticks_prev)
        btn_ticks_prev = btn_ticks_cur  # 更新上一次按键时间戳 / Update previous button timestamp                          
        # 检测启动按键状态:按下(低电平)或释放(高电平) / Detect start button state: pressed (low level) or released (high level)
        if boot_gpio.value() == 0:
            boot_btn.key_down(delta) 
        else:
            boot_btn.key_up(delta)    # 调用按键释放处理函数,传入时间差 / Call button release handler, pass time difference                        
            ....
            # 车辆控制逻辑:根据识别结果调整车辆运动状态 / Vehicle control logic: adjust vehicle motion state based on recognition results
            if car_count == 0:
                if car_state > 0:
                    # 当识别计数为0且车辆非停止状态时,设置车辆为停止(速度0) / When recognition count is 0 and vehicle is not in stop state, set vehicle to stop (speed 0)
                    bot.set_car_motion(car_speed, 0, 0)
                    car_state = 0
            elif car_count < 0:
                car_count = 0  # 防止计数为负,重置为0 / Prevent negative count, reset to 0
                            
        
        # 训练状态:对应3个类别(CLASS_1/2/3)的样本采集逻辑 / Training state: sample collection logic for 3 classes (CLASS_1/2/3)
        elif state_machine.current_state == STATE.TRAIN_CLASS_1 \
                or state_machine.current_state == STATE.TRAIN_CLASS_2 \
                or state_machine.current_state == STATE.TRAIN_CLASS_3:
            loop_capture()  # 执行样本采集逻辑(捕获摄像头画面,保存为训练样本) / Execute sample collection logic (capture camera image, save as training sample)
​
...
​

3. Main Functions

Upper_Data_Parse

Function Prototypevoid Upper_Data_Parse(uint8_t *data_buf, uint8_t num)
Function DescriptionHost computer data parsing function: processes different instructions based on function code (func_id) in data buffer. When function code is FUNC_MOTION, parses speed parameters (Vx_recv, Vy_recv, Vz_recv) and controls car movement (stops motors when speed is 0); when function code is FUNC_RGB, parses RGB color components, sets RGB light color and sends data
Input Parametersdata_buf: pointer to received data buffer num: data length (not used in function)
Return ValueNone

Upper_Data_Receive

Function Prototypevoid Upper_Data_Receive(uint8_t Rx_Temp)
Function DescriptionHost computer data receiving function: receives data in fixed format (with PTO_HEAD as header, PTO_DEVICE_ID as device ID), stores it in RxBuffer, and sets New_CMD_flag when reception is complete
Input ParametersRx_Temp: received single byte data
Return ValueNone

4. K210 Program Burning

After downloading and opening CanMV IDE, we need to first drag the k210_selfL.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, K210 will learn three types of road signs. Use the button on the side closer to the K210 TF card for learning. Collect five samples for each type. After successful collection, the car will move forward. When recognizing the first type of road sign, it will turn right; the second type will turn left; the third type will stop. If using firmware version 2.1.1, the button pin needs to be changed to 17. Please see source code analysis for details

K210 color response
K210 following machine code

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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文