K230 QR code instructions

This tutorial is a comprehensive experiment combining multiple peripherals. You can first understand a single peripheral and then conduct this experiment.

1. Software-Hardware

K230 module: external

Download or simulate the development board

2. Brief principle

1. Hardware schematic

2023103102

2. Physical connection diagram

K230 wiring (Note: The wiring in the figure below is for position reference only. We are equipped with K230 dual-head PH2.0 4Pin all-black wire, with fool-proof design, no need to worry about wiring problems)

PixPin_2025-06-10_19-21-14

Motor wiring

image-20231031094208747

3. Control principle

Program flow chart

Yes
No
Start
K230 detects the target?
K230 sends data according to the specified protocol
MCU analyzes the data and controls the car to give feedback
The car stops

 

Communication protocol:

When k230 recognizes the content of the scanned QR code, it will send a data frame through the serial port, the format is as follows

Start character Length Delimiter Routine number delimiter x delimiter y delimiter w delimiter h delimiter msg end
$ XX , 03 , XXX , XXX , XXX , XXX , ... #

The microcontroller receives the data sent by k230 through the serial port and processes the data. By judging whether the received data content is in the above frame format, we process the data into string data after it meets the data frame format. It should be distinguished from the previous "x, y, w, h" coordinate information, and then compare this string array. If the comparison is a specific QR code instruction content, the corresponding instruction is executed on the car.

For example: "$XX, 03, XXX, XXX, XXX, XXX, goback#"

When the microcontroller receives the above data frame, it will split the data frame with commas, and the data after the commas is the data we need to obtain. After parsing the data frame content, it will compare this content with goback. If it is the corresponding instruction, the car will move backward.

Note: For the analysis part, please refer to the code

3. Main functions

Function: Car_qcode

Function prototypevoid Car_qcode(void)
Function descriptionPerform different actions according to different instructions sent by k230
Input parametersNone
Return valueNone

Function: Motion_Set_Speed

Function prototypevoid Motion_Set_Speed(int16_t speed_m1, int16_t speed_m2, int16_t speed_m3, int16_t speed_m4)
Function descriptionControl the speed of the car
Input parameters 1, 2, 3, 4Speed control: speed=0~1000.
Return valueNone

Function: wheel_State

Function prototypevoid wheel_State(uint8_t state, uint16_t speed)
Function descriptionControl the motion state of the car
Input parameter 1Speed control: speed=0~1000.
Input parameter 2Car status value
Return valueNone

4. Partial code analysis

5. Experimental phenomenon

After successfully downloading the program, take out a specific QR code and place it under the lens of the k230 visual module for recognition. After recognition, the car will make corresponding actions, and after completing the action, the car will stop.

K230 Code Burning

Required tools: K230, SD card, CanMV IDE K230

We find the k230_track_recong.py file in the project folder, then drag it to CanMV IDE K230, and then choose to save the opened script as main.py to CanMV

PixPin_2025-06-10_19-59-03

The following is the QR code used in the tutorial:

image-20231031094208747

goback

image-20231031094208747

Goahead

image-20231031094208747

turnleft

image-20231031094208747

turnright