k230 color response

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

** Voice module wiring**

Intelligent voice interaction moduleSTM32
5V5V
GNDGND
TX1PC11
RX1PC10

2025-06-10_18-53-59

K230 wiring** (Note: The wiring in the figure below is for reference only. We are equipped with K230 double-headed PH2.0 4Pin all-black wire with fool-proof design, so you don’t have to worry about wiring problems)

PixPin_2025-06-10_19-15-08

Motor wiring

2023103106

3. Control principle

Yes
No
Start
K230 detects the specified color?
K230 sends data according to the specified protocol
The microcontroller parses the data and controls the car, and lights up the same color as feedback
The car stops
ModuleFunction
k230 visual moduleIdentify color and send data to the microcontroller through the serial port

Communication protocol:

When k230 identifies the color track, it will send a data frame through the serial port. The format is as follows

Experimental routineStart symbolmsgEnd symbol
Color recognition$GREEN, BLUE, RED#

Voice module command word

Command wordFunction typeBroadcast statementBroadcast modeSend protocolReceive protocol
GREEN-DETECTEDCommand wordRecognize greenByAA 55 FF 43 FBAA 55 FF 43 FB
BLUE-DETECTEDCommand wordRecognize blueByAA 55 FF 44 FBAA 55 FF 44 FB
RED-DETECTEDCommand wordRecognize redByAA 55 FF 49 FBAA 55 FF 49 FB

MCU part:

Receive the data sent by k230 through the serial port and process each byte of the data. Extract msg from the data frame content and store it in the array. Then process the array data, and the MCU responds to the recognized color through the processed data.

3. Main functions

Function: Pto_Data_Parse

Function prototypevoid Pto_Data_Parse(uint8_t *data_buf, uint8_t num)
FunctionParse the data information returned by K230
Input parameter 1Array pointer of received data
Input parameter 2Size of received data
Return valueNone

Function Car_Color**

Function prototypevoid Car_color(void)
FunctionCar color response function
Return valueNone

4. Partial code analysis

5. Experimental phenomenon

After successfully downloading the program, place the color block in the detection range. When the color corresponding to the threshold appears in the camera range, the car starts to respond to the specified color. Note: Only red, blue and green can be recognized and responded. And when connecting our AI voice interaction integrated module, there will be voice broadcast when the specified color is detected. Users who have not purchased the voice module do not need to worry. The case can still be implemented without connecting the voice module K230, but there is no voice broadcast function

Voice Module Firmware Burning

K230 Code Burning

Required tools: K230, SD card, CanMV IDE K230

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

PixPin_2025-06-10_19-59-03