yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
K210 Module📖
0.Camera changes
  • Precautions for camera changes
1.K210-AI-Camera introduction
  • 1.K210 main chip introduction
  • 2.K210 visual recognition module introduction
  • 3.Module pin assignments
  • 4.MicroPython Introduction
  • 5. FAQ analysis
  • 6.Bracket installation
2.Development Environment Setup
  • 1.To install the serial port assistant
  • 2.Install CanMV IDE development software
  • 3.Flashcard factory firmware
  • 4.IDE import routine
  • 5.Call custom py library
  • 6.MicroPython API documentation
3.Basic experimental routines
  • 1.Lighting the RGB light experiment
  • 2.Key features of the experiment
  • 3.Timer experiment
  • 4.PWM breathing light experiment
  • 5.LCD display experiment
  • 6.The touchpad read the coordinates of the experiment
  • 7.The camera shows the experimental
  • 8.Memory card read and write files of the experiment
  • 9.External interface experimental
4.Graphical manipulation routines
  • 1.Draw graphics
  • 2.Button and the click event
  • 3.Slider
  • 4.Chart animation
  • 5.Multi-label layout
5.AI visual experiments routines
  • How to import the model file into memory cardnew
  • 1.Color recognition
  • 2.Barcode recognition
  • 3.QR code recognition
  • 4.Apriltags recognition
  • 5.Face detection
  • 6.Face feature detection
  • 7.Mask detection
  • 8.Face recognition
  • 9.Object detection
  • 10.Self-learning classification
  • 11.Handwritten digit recognition
  • 12. Multiple color recognition
  • 13. Human body detectionnew
  • 14. Yolo hand detectionnew
  • 15. License Plate Recognitionnew
  • 16. Autonomous training modelnew
6.Extended routines (sold separately)
6.1.For STM32 Car
  • 10. stm_ K210 Autonomous Learning Classification
  • 1.automatic driving
  • 2.color follow
  • 3.Handwriting digital operation
  • 4.Color reaction
  • 5.Road sign indicating the operation
  • 6.Following the apriltag
  • 7.QR code instruction
  • 8.PTZ tracking color
  • 9.PTZ tracking face
6.2.1 arduino_k210
  • 1.ard_k210-Color recognition
  • 2.ard_k210-Bar code identification
  • 3.ard_k210-QR code identification
  • 4.ard_ K210-mechanical code identification
  • 5.ard_ K210-Face Detection
  • 6. ard_ K210-facial feature detection
  • 7. ard_ K210-mask detection
  • 8. ard_ K210-facial recognition
  • 9. ard_ K210-object detection
  • 10. ard_ K210 Autonomous Learning Classification
  • 11. ard_ K210 Handwritten Digit Recognition
6.2 K210 as a coprocessor
  • ReadMe
6.2.2 stm32_k210
  • 1.stm_ K210 color recognition
  • 2. stm_ K210 barcode recognition
  • 3. stm_ K210 QR code recognition
  • 4. stm_ K210 mechanical code identification
  • 5. stm_ K210 Face Detection
  • 6.stm_ K210 facial feature detection
  • 7. stm_ K210 mask detection
  • 8. stm_ K210 facial recognition
  • 9. stm_ K210 object detection
  • 11. stm_ K210 Handwritten Digit Recognition
6.2.3 microbit_k210
  • 1.microbit_ K210 color recognition
  • 2.microbit_ K210 barcode recognition
  • 3.microbit_ K210 QR code recognition
  • 4.microbit_ K210 mechanical code identification
  • 5. microbit_ K210 Face Detection
  • 6. microbit_ K210 facial feature detection
  • 7. microbit_ K210 mask detection
  • 8. microbit_ K210 facial recognition
  • 9. microbit_ K210 object detection
  • 10. microbit_ K210 autonomous classification learning
  • 11. microbit_ K210 Handwritten Digit Recognition
6.2.4 pico_k210
  • 1. pico_ K210 color recognition
  • 2. Pico_ K210 barcode recognition
  • 3. Pico_ K210 QR code recognition
  • 4. pico_ K210 machine code recognition
  • 5. pico_ K210 Face Detection
  • 6. pico_ K210 facial feature detection
  • 7. pico_ K210 mask recognition
  • 8. pico_ K210 facial recognition
  • 9. pico_ K210 object detection
  • 10. pico_ K210 Autonomous Learning Classification
  • 11. pico_ K210 Handwritten Digit Recognition
6.2.5 MSPM0G3507_k210
  • 1.MSPM0_K210 color recognition
  • 2.MSPM0_K210 barcode recognition
  • 3.MSPM0_K210 QR code recognition
  • 4.MSPM0_K210 mechanical code recognition
  • 5.MSPM0_K210 face detection
  • 6.MSPM0_K210 facial feature detection
  • 7.MSPM0_K210 mask detection
  • 8.MSPM0_K210 face recognition
  • 9.MSPM0_K210 Object Detection
  • 10.MSPM0_K210 Self-study classification
  • 11.MSPM0_K210 handwritten digit recognition
6.2.6 MSPM0G3519_k210
  • 1. MSPM0_K210 Color Recognitionnew
  • 2. MSPM0_K210 Barcode Recognitionnew
  • 3. MSPM0_K210 QR Code Recognitionnew
  • 4. MSPM0_K210 Mechanical Code Recognitionnew
  • 5. MSPM0_K210 Face Detectionnew
  • 6. MSPM0_K210 Facial Feature Detectionnew
  • 7. MSPM0_K210 Mask Detectionnew
  • 8. MSPM0_K210 Face Recognitionnew
  • 9. MSPM0_K210 Object Detectionnew
  • 10. MSPM0_K210 Self-study Classificationnew
  • 11. MSPM0_K210 Handwritten Digit Recognitionnew
6.3 For 24 channel servo drive board
  • 1. 2DOF PTZ Color Tracking
  • 2. 2DOF Face Tracking
  • 3. 2DOF Fruit sorting
6.4 For autopilot map
  • 1.k210 model training
  • 2.Assembly and wiring of stm32 car
  • 3.Recognize left and right sign
  • 4.Identify and remove speed limit
  • 5.Identify parking spaces and park
  • 6.STM32 car autopilot
6.5.1 For MSPM0G3507_Wheeled Chassis Kit
  • 1.MSPM0-Automatic Driving
  • 2.MSPM0-Color follow
  • 3.MSPM0-Number recognition
  • 4.MSPM0-Color reaction
  • 5.MSPM0-Road signs
  • 6.MSPM0-Machine code following
  • 7.MSPM0-QR code recognition
6.5.2 For MSPM0G3519_Wheeled Chassis Kit
  • 1.MSPM0-Automatic Drivingnew
  • 2.MSPM0-Color follownew
  • 3.MSPM0-Number recognitionnew
  • 4.MSPM0-Color reactionnew
  • 5.MSPM0-Road signsnew
  • 6.MSPM0-Machine code followingnew
  • 7.MSPM0-QR code recognitionnew
6.5.3 For STM32_Wheeled Chassis Kit
  • 1.STM32-Automatic Driving
  • 2.STM32-Color follow
  • 3.STM32-Number recognition
  • 4.STM32-K210-Color Reaction
  • 5.STM32-Road signs
  • 6.STM32-Machine code following
  • 7.STM32-QR code recognition
Download
  • Driver development software
  • AI model
  • Source code
  • Instruction manual
  • Hardware_3DModelFile
  • K210_Chip_Data
Download ZIP

Welcome to K210 Module repository

7.MSPM0-QR code recognition

 

MSPM0 QR code recognition

MSPM0 QR code recognition1. Opening instructions2. Experimental preparationThe relationship between the 4 motor interfaces and the car is as follows:Hardware wiringWiring using MSPM0 robot expansion boardWiring using MSPM0G3507 core board (Yahboom)Wiring pins3. Key code analysis4. Experimental operation5. Experimental phenomenon

1. Opening instructions

Please read the "Motor Introduction and Usage" in the four-way motor driver board information first to understand the motor parameters, wiring method, and power supply voltage you are currently using. To avoid burning the motherboard or motor.

Motor: The case and code take the 520L motor of our store as an example.

2. Experimental preparation

National race chassis V2 four-wheel drive version, 4*L520 motor, 12V lithium battery, K210 vision module, MSPM0 robot expansion board (optional), MSPM0G3507 core board (Yahboom).

The relationship between the 4 motor interfaces and the car is as follows:

M1 -> upper left motor (left front wheel of the car)

M2 -> lower left motor (left rear wheel of the car)

M3 -> upper right motor (right front wheel of the car)

M4 -> lower right motor (right rear wheel of the car)

Hardware wiring

Wiring using MSPM0 robot expansion board

During the installation and wiring process, if the wiring length is not enough, you can move the MSPM0 robot expansion board forward a little and install it, as shown in the following figure.

Note: The wire used for the k210 vision module and the wire used to connect the MSPM0 robot expansion board and the four-way motor driver module are: PH2.0-4pin cable, double-ended all black, reverse (200mm), the direction of the reverse cable holder is shown in the following figure

PixPin_2025-03-28_15-25-56

Wiring using MSPM0G3507 core board (Yahboom)

 

Wiring pins

Four-way motor driver boardMSPM0G3507 core board (Yahboom)
RX2PB6
TX2PB7
GNDGND
5V5V

Take M1 motor as an example below, and other motors are similar

MotorFour-way motor driver board (Motor)
M+M1+
M-M1-
GNDGND
VCC3V3
BH1A
AH1B
K210 vision moduleMSPM0G3507 core board (Yahboom)
5V5V
GNDGND
TXDPA22
RXDPA21

3. Key code analysis

  • revaction.c
​x
// 获取命令标志   Get command flag
uint8_t Get_CMD_Flag(void)
{
    return New_CMD_flag;
}
​
// 清除命令数据和相关标志  Clear command data and related flags
void Clear_CMD_Flag(void)
{
    #if ENABLE_CLEAR_RXBUF
    for (uint8_t i = 0; i < New_CMD_length; i++)
    {
        RxBuffer[i] = 0;
    }
    #endif
    New_CMD_length = 0;
    New_CMD_flag = 0;
}
//数据分析  data analysis
void Upper_Data_Parse(uint8_t *data_buf, uint8_t num)
{
    uint8_t func_id = *(data_buf + 3);
    switch (func_id)
    {
    /* 判断功能字:小车速度设置 Judgment function word: Trolley 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)
        {
            Contrl_Pwm(0,0,0,0);
        }
        else
        {
            Motion_Car_Control(Vx_recv, Vy_recv, Vz_recv, (adjust==0?0:1));
        }
        break;
    }
​
    /* 判断功能字:彩灯控制 Judgment function word: color light control */
    case FUNC_RGB:
    {
        u8 index = *(data_buf + 4);
        u8 red = *(data_buf + 5);
        u8 green = *(data_buf + 6);
        u8 blue = *(data_buf + 7);
//        printf("RED:%d, G:%d, B:%d\r\n",red,green,blue);
        RGB_Set_Color(index, red, green, blue);
        RGB_Update();
        break;
    }
    
    default:
        break;
    }
}
​
​
​
//数据接收并保存   Data received and saved
void Upper_Data_Receive(uint8_t Rx_Temp)
{
    switch (RxFlag)
    {
    case 0:
        if (Rx_Temp == PTO_HEAD)
        {
            RxBuffer[0] = PTO_HEAD;
            RxFlag = 1;
        }
        break;
​
    case 1:
        if (Rx_Temp == PTO_DEVICE_ID)
        {
            RxBuffer[1] = PTO_DEVICE_ID;
            RxFlag = 2;
            RxIndex = 2;
        }
        else
        {
            RxFlag = 0;
            RxBuffer[0] = 0x0;
        }
        break;
​
    case 2:
        New_CMD_length = Rx_Temp + 2;
        if (New_CMD_length >= PTO_MAX_BUF_LEN)
        {
            RxIndex = 0;
            RxFlag = 0;
            RxBuffer[0] = 0;
            RxBuffer[1] = 0;
            New_CMD_length = 0;
            break;
        }
        RxBuffer[RxIndex] = Rx_Temp;
        RxIndex++;
        RxFlag = 3;
        break;
​
    case 3:
        RxBuffer[RxIndex] = Rx_Temp;
        RxIndex++;
        if (RxIndex >= New_CMD_length)
        {
            New_CMD_flag = 1;
            RxIndex = 0;
            RxFlag = 0;
        }
        break;
​
    default:
        break;
    }
}

Get_CMD_Flag: Get the k210 data flag

Clear_CMD_Flag: Clear command data and related flags

Upper_Data_Parse: Parse the saved k210 data and determine the function of k210

Upper_Data_Receive: Save the received k210 data

  • app_motor.c
xxxxxxxxxx
// 返回当前小车轮子轴间距和的一半  Returns half of the sum of the axle spacings of the current trolley wheels.
static float Motion_Get_APB(void)
{
    return Car_APB;
}
void Set_Motor(int MOTOR_TYPE)
{
    if(MOTOR_TYPE == 1)
    {
        send_motor_type(1);//配置电机类型 Configure motor type
        delay_ms(100);
        send_pulse_phase(30);//配置减速比 查电机手册得出    Configure the reduction ratio. Check the motor manual to find out
        delay_ms(100);
        send_pulse_line(11);//配置磁环线 查电机手册得出 Configure the magnetic ring wire. Check the motor manual to get the result.
        delay_ms(100);
        send_wheel_diameter(67.00);//配置轮子直径,测量得出        Configure the wheel diameter and measure it
        delay_ms(100);
        send_motor_deadzone(1900);//配置电机死区,实验得出 Configure the motor dead zone, and the experiment shows
        delay_ms(100);
    }
    
    ...
        
    else if(MOTOR_TYPE == 5)
    {
        send_motor_type(1);
        delay_ms(100);
        send_pulse_phase(40);
        delay_ms(100);
        send_pulse_line(11);
        delay_ms(100);
        send_wheel_diameter(67.00);
        delay_ms(100);
        send_motor_deadzone(1900);
        delay_ms(100);
    }
}
void Motion_Car_Control(int16_t V_x, int16_t V_y, int16_t V_z, uint8_t adjust)
{
    float robot_APB = Motion_Get_APB();
    speed_lr = 0;
    speed_fb = V_x;
    speed_spin = (V_z / 1000.0f) * robot_APB;
    if (V_x == 0 && V_y == 0 && V_z == 0)
    {
        Contrl_Speed(0,0,0,0);
        return;
    }
​
    speed_L1_setup = speed_fb - speed_spin;
    speed_L2_setup = speed_fb - speed_spin;
    speed_R1_setup = speed_fb  + speed_spin;
    speed_R2_setup = speed_fb  + speed_spin;
        
    if (speed_L1_setup > 1000) speed_L1_setup = 1000;
    if (speed_L1_setup < -1000) speed_L1_setup = -1000;
    if (speed_L2_setup > 1000) speed_L2_setup = 1000;
    if (speed_L2_setup < -1000) speed_L2_setup = -1000;
    if (speed_R1_setup > 1000) speed_R1_setup = 1000;
    if (speed_R1_setup < -1000) speed_R1_setup = -1000;
    if (speed_R2_setup > 1000) speed_R2_setup = 1000;
    if (speed_R2_setup < -1000) speed_R2_setup = -1000;
    
//    printf("%d\t,%d\t,%d\t,%d\r\n",speed_L1_setup,speed_L2_setup,speed_R1_setup,speed_R2_setup);
    
    Contrl_Speed(speed_L1_setup, speed_L2_setup, speed_R1_setup, speed_R2_setup);
        
}
​

Motion_Get_APB: Returns half of the current wheel axle spacing of the car

Set_Motor: Sets the motor type of the four-way motor driver board, and changes the motor type according to your actual situation

Motion_Car_Control: Controls the different motion states of the car

  • app_motor_usart.c
xxxxxxxxxx
//发送电机类型    Transmitter motor type
void send_motor_type(motor_type_t data)
{
    sprintf((char*)send_buff,"$mtype:%d#",data);
    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
    
}
​
//发送电机死区    Send motor dead zone
void send_motor_deadzone(uint16_t data)
{
    sprintf((char*)send_buff,"$deadzone:%d#",data);
    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
}
​
//发送电机磁环脉冲  Send motor magnetic ring pulse
void send_pulse_line(uint16_t data)
{
    sprintf((char*)send_buff,"$mline:%d#",data);
    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
}
​
//发送电机减速比   Transmitting motor reduction ratio
void send_pulse_phase(uint16_t data)
{
    sprintf((char*)send_buff,"$mphase:%d#",data);
    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
}
​
//发送轮子直径    Send wheel diameter
void send_wheel_diameter(float data)
{
    sprintf((char*)send_buff,"$wdiameter:%.3f#",data);
    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
 }
//控制速度  Controlling Speed
void Contrl_Speed(int16_t M1_speed,int16_t M2_speed,int16_t M3_speed,int16_t M4_speed)
{
    sprintf((char*)send_buff,"$spd:%d,%d,%d,%d#",M1_speed,M2_speed,M3_speed,M4_speed);
    UART_Console_write(send_buff, strlen((char*)send_buff));
//    Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
}
​
​
//控制pwm Control PWM
void Contrl_Pwm(int16_t M1_pwm,int16_t M2_pwm,int16_t M3_pwm,int16_t M4_pwm)
{
    sprintf((char*)send_buff,"$pwm:%d,%d,%d,%d#",M1_pwm,M2_pwm,M3_pwm,M4_pwm);
    UART_Console_write(send_buff, strlen((char*)send_buff));
//  Send_Motor_ArrayU8(send_buff, strlen((char*)send_buff));
}
    

Configure motor parameters

Contrl_Speed: Control the speed of 4 motors separately

Contrl_Pwm: Control 4 motors separately through PWM.

  • empty.c
xxxxxxxxxx
#define MOTOR_TYPE 5   //1:520电机 2:310电机 3:测速码盘TT电机 4:TT直流减速电机 5:L型520电机
                       //1:520 motor 2:310 motor 3:speed code disc TT motor 4:TT DC reduction motor 5:L type 520 motor
​
​
int main(void)
{
    USART_Init();
    printf("please wait...\r\n");
​
     //使能DMA通道  Enable DMA Channel
    NVIC_ClearPendingIRQ(UART_1_INST_INT_IRQN);
    DL_DMA_enableChannel(DMA, DMA_CH0_CHAN_ID);
    NVIC_EnableIRQ(UART_1_INST_INT_IRQN);
    
    //开启与K210串口通信的中断    Enable interrupts for communication with the K210 serial port
    NVIC_ClearPendingIRQ(UART_2_INST_INT_IRQN);
    NVIC_EnableIRQ(UART_2_INST_INT_IRQN);
    
    
    //设置电机类型    Set motor type
    Set_Motor(MOTOR_TYPE);
    
    printf("Initialization Succeed\r\n");
​
    while(1)
    {
        if (Get_CMD_Flag())
        {
            Upper_Data_Parse(Get_RxBuffer(), Get_CMD_Length());
            Clear_CMD_Flag();
        }
    }
}
​
​

MOTOR_TYPE: used to set the type of motor used. Modify the corresponding number according to the comments based on the motor you are currently using.

USART_Init: Initialize the serial port for communicating with the four-way motor driver board

Get_CMD_Flag: Start receiving data from k210

Upper_Data_Parse: Parse the received data from k210. And judge the function

Clear_CMD_Flag: Clear the received data and related flags

4. Experimental operation

  1. Burn the program to MSPM0.
  2. Download the car drive library and PID control library in the K210\library directory to the root directory of the memory card in advance.
  3. Open CanMV IDE and download the follow_line.py code into the K210 module.
  4. Connect all the lines of the car.
  5. Put the QR code with specific information in front of the car camera. After the K210 module recognizes the corresponding information, it performs the corresponding operation.

5. Experimental phenomenon

After waiting for the system to initialize, the car will not move when it does not recognize the QR code. When it recognizes the QR code with the character "turn left", it will turn left. When it recognizes the QR code with the character "turn right", it will turn right. The character "spin left" is left rotation, the character "spin right" is right rotation, the character "go ahead" is forward, and the character "fall back" is backward. After recognizing the corresponding character, the function will run and it will stop automatically after a certain period of time. After stopping, the QR code can be recognized again.

go ahead

go ahead

fall back

fall back

turn left

turn left turn right

turn right

spin left

spin left spin right

spin right

MSPM0-Machine code following
MSPM0-Automatic Driving

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