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

4.K210 color response

K210 Color Response

K210 Color Response1. Hardware Connection2. Code Analysis3. Main Functions4. K210 Method for Extracting Specified Color LAB Thresholds5. K210 Program Burning6. Experimental Phenomena

1. Hardware Connection

K210 Vision ModuleMSPM0G3507
5V5V
GNDGND
TXRX2
RXTX2

Physical Connection

image-removebg-preview

Schematic Diagram

image-20251029164049976

image-20251029164030395

image-20251029164356332

K210 Protocol

Header 1Header 2LengthFunction CodeID(0-14|0xff)R(0-255)G(0-255)B(0-255)checksum
0xFF0xFC0x070x05XX ignored not usedXXXXXXXX

Control Flow Chart

No
Yes
Start
Vision module recognizes color with specified threshold
Car and K210 RGB lights do not respond
MCU parses data and controls car response

 

2. Code Analysis

revaction.c

​x
// 数据分析 / 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
# 各个颜色的阈值以及颜色列表 / Threshold values for each color and color list
#红色 color red
threshold_red = (48, 71, 47, 80, 61, -68)
#绿色 color green
threshold_green = (12, 79, -78, -10, -66, 109)
#蓝色 color blue
threshold_blue = [37, 64, 9, 49, -57, -37]
#黄色 color yellow
threshold_yellow = (98, 78, -66, -6, -36, 121)
#白色 color white
threshold_white = (94, 83, 44, -23, 28, -54)
#紫色 color purple
threshold_purple = [75, 78, 66, 71, -40, -36]
color_list = [threshold_red, threshold_green, threshold_blue, threshold_yellow,threshold_white,threshold_purple]
​
while(True):
    clock.tick()
    img = sensor.snapshot()
    fps = clock.fps()
    index = 0
    led = 0
#遍历各个颜色列表的颜色阈值,如果有找到相近色块,将预设的RGB值发送到小车 / Traverse color thresholds in the color list, if similar color blocks are found, send preset RGB values to the car
    for t in color_list:
        index = index + 1
        for blob in img.find_blobs([t], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
            img.draw_rectangle(blob.rect())
            img.draw_cross(blob.cx(), blob.cy())
            print_color(index)
            led = led + 1
            led_on = 1
    if led == 0:
        if led_on == 1:
            bot.set_colorful_lamps(0xff, 0, 0, 0)
            RGB.set(0, 0, 0)
            led_on = 0
    img.draw_string(0, 0, "%2.1ffps" %(fps), color=(0, 60, 128), scale=2.0)
    lcd.display(img)

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 Method for Extracting Specified Color LAB Thresholds

After connecting to CanMV IDE via microUSB, drag follow_color_k210.py to CanMV IDE to open it. First click the run button to ensure the color to be recognized appears in the frame buffer. Here we use red as an example. Click Tools -> Machine Vision -> Threshold Editor in the menu bar to get the image from the frame buffer.

image-20251029204408672

image-20251029204957872

You can drag the slider positions to adjust the threshold. White pixels are the tracked pixels. Finally, fill the LAB threshold values into our color thresholds.

image-20251029205301117

 

image-20251029205546204

5. K210 Program Burning

After downloading and opening CanMV IDE, we need to first drag the color_rgb.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

6. Experimental Phenomena

After setting the color thresholds and burning the program to K210, place colored objects in front of K210. The car and K210 RGB lights will light up corresponding colors following the object's color.

 

K210 handwritten digit action
K210 road sign indication action

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