Earlier I learned to use the K210 training model for target detection, and then I also learned to use the K210 for serial communication. After learning, I threw the K210 in the box to eat ashes. Because of the school epidemic, the biennial electronic competition It's a pity that I can't participate, and then I want to use it as a mask detection system (you can remind me if you don't wear a mask). it is done. Hahaha, I hope that everyone who wants to do these two projects can do it quickly after reading this blog, come on.
Mask detection system based on K210
K210 Garbage classification
Article directory
foreword
Only by doing projects and participating in competitions can we really learn something, apply theory to practice, cheer together, and make progress together.
1. Prerequisites
1.32 single-chip microcomputer (here I use zet6 minimum system board and c8t6)
2.K210 (any model is acceptable)
3.SYN6288 voice broadcast module
4.Servo
5.Trash can
Keil5 software and Maixpy software
2. Project actual combat
1. Mask detection system
1. Model
I believe that after reading my first blog, the mask detection model has been trained. You can burn it into your K210 according to the offline operation I introduced in the previous article, and then the offline detection can run.
As shown below
2. Send data
If you still don’t know serial communication, you can read my blog, which introduces the serial communication part of K210 in detail. I believe you can mask and un_masks after reading it. The data is sent to the computer.
As shown below
3. SYN6288 voice broadcast module
This is the second important part of this project. The data is received by the microcontroller, and then sent to the voice broadcast module. The voice broadcast module processes the data and broadcasts the corresponding voice. Here, because there are only two tags, I did not process the string, and directly judged by the length of the received characters, so I made it in a short time.
The .c file is as follows
#include "syn6288.h"
#include "usart.h"
#include "string.h"
#include "delay.h"
//Music:Ñ¡Ôñ±³¾°ÒôÀÖ¡£0:ÎÞ±³¾°ÒôÀÖ£¬1~15£ºÑ¡Ôñ±³¾°ÒôÀÖ
void SYN_FrameInfo(u8 Music, u8 *HZdata)
{
/****************ÐèÒª·¢Ë͵ÄÎı¾**********************************/
unsigned char Frame_Info[50];
unsigned char HZ_Length;
unsigned char ecc = 0; //¶¨ÒåУÑé×Ö½Ú
unsigned int i = 0;
HZ_Length = strlen((char*)HZdata); //ÐèÒª·¢ËÍÎı¾µÄ³¤¶È
/*****************Ö¡¹Ì¶¨ÅäÖÃÐÅÏ¢**************************************/
Frame_Info[0] = 0xFD ; //¹¹ÔìÖ¡Í·FD
Frame_Info[1] = 0x00 ; //¹¹ÔìÊý¾ÝÇø³¤¶ÈµÄ¸ß×Ö½Ú
Frame_Info[2] = HZ_Length + 3; //¹¹ÔìÊý¾ÝÇø³¤¶ÈµÄµÍ×Ö½Ú
Frame_Info[3] = 0x01 ; //¹¹ÔìÃüÁî×Ö£ººÏ³É²¥·ÅÃüÁî
Frame_Info[4] = 0x01 | Music << 4 ; //¹¹ÔìÃüÁî²ÎÊý£º±³¾°ÒôÀÖÉ趨
/*******************УÑéÂë¼ÆËã***************************************/
for(i = 0; i < 5; i++) //ÒÀ´Î·¢Ë͹¹ÔìºÃµÄ5¸öÖ¡Í·×Ö½Ú
{
ecc = ecc ^ (Frame_Info[i]); //¶Ô·¢Ë͵Ä×Ö½Ú½øÐÐÒì»òУÑé
}
for(i = 0; i < HZ_Length; i++) //ÒÀ´Î·¢ËÍ´ýºÏ³ÉµÄÎı¾Êý¾Ý
{
ecc = ecc ^ (HZdata[i]); //¶Ô·¢Ë͵Ä×Ö½Ú½øÐÐÒì»òУÑé
}
/*******************·¢ËÍÖ¡ÐÅÏ¢***************************************/
memcpy(&Frame_Info[5], HZdata, HZ_Length);
Frame_Info[5 + HZ_Length] = ecc;
USART3_SendString(Frame_Info, 5 + HZ_Length + 1);
}
/***********************************************************
* Ãû ³Æ£º YS_SYN_Set(u8 *Info_data)
* ¹¦ ÄÜ£º Ö÷º¯Êý ³ÌÐòÈë¿Ú
* Èë¿Ú²ÎÊý£º *Info_data:¹Ì¶¨µÄÅäÖÃÐÅÏ¢±äÁ¿
* ³ö¿Ú²ÎÊý£º
* ˵ Ã÷£º±¾º¯ÊýÓÃÓÚÅäÖã¬Í£Ö¹ºÏ³É¡¢ÔÝÍ£ºÏ³ÉµÈÉèÖà £¬Ä¬Èϲ¨ÌØÂÊ9600bps¡£
* µ÷Ó÷½·¨£ºÍ¨¹ýµ÷ÓÃÒѾ¶¨ÒåµÄÏà¹ØÊý×é½øÐÐÅäÖá£
**********************************************************/
void YS_SYN_Set(u8 *Info_data)
{
u8 Com_Len;
Com_Len = strlen((char*)Info_data);
USART3_SendString(Info_data, Com_Len);
}
I don’t know why pasting from keil5 becomes garbled characters. There is no problem if you paste it to keil5.
The h file is as follows
#ifndef __SYN6288_H
#define __SYN6288_H
#include "sys.h"
void SYN_FrameInfo(u8 Music, u8 *HZdata);
void YS_SYN_Set(u8 *Info_data);
#endif
The main function part is as follows
if(len==6)
{
TIM_SetCompare2(TIM4, 1910);
SYN_FrameInfo(0, "[v7][m1][t5]ÇëÄúÕýÈ·Åå´÷¿ÚÕÖ");
delay_ms(8000);
delay_ms(8000);
delay_ms(8000);
delay_ms(8000);
TIM_SetCompare2(TIM4, 1850);
}
if(len==5)
{
TIM_SetCompare4(TIM4, 1930);
SYN_FrameInfo(0, "[v7][m1][t5]ÄúÒÑÅå´÷¿ÚÕÖ");
delay_ms(8000);
delay_ms(8000);
delay_ms(8000);
delay_ms(2000);
Even if the whole project is completed here, when you really learn K210, you will find that it is really simple.
If you need the complete engineering code and K210 code, you can leave your email below, and I will send it to your email.
I also uploaded the complete 32 code and K210 files to my resources, and you can download them yourself if you need them.
2. Garbage classification system
1. Model
Similarly, if you need to classify garbage, you need to train the model of garbage, and you need different types. Here I will put the marked picture link, and you can train it yourself. (If you don’t, you can see the link on my home page)
Link: https://pan.baidu.com/s/1K6qbEQZ97PcyMWcgTCq1hw
Extraction code:
After qhnx is trained, burn the model into the SD card, let K210 run offline, and check whether the garbage model is correct.
As shown below
2. Serial communication data processing part
It's the serial communication part again, you can read another blog on my homepage, I won't repeat it here. the same as above.
3. SYN6288 voice broadcast module
Same as above, the code is as
follows.c
(here is a very simple 32 timer configuration)
#include "timer.h"
u16 t=0;
void TIM2_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //ʱÖÓʹÄÜ
//¶¨Ê±Æ÷TIM3³õʼ»¯
TIM_TimeBaseStructure.TIM_Period = 999; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ
TIM_TimeBaseStructure.TIM_Prescaler =71; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòÉϼÆÊýģʽ
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE ); //ʹÄÜÖ¸¶¨µÄTIM3ÖжÏ,ÔÊÐí¸üÐÂÖжÏ
//ÖжÏÓÅÏȼ¶NVICÉèÖÃ
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM3ÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÏÈÕ¼ÓÅÏȼ¶0¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //´ÓÓÅÏȼ¶3¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀ±»Ê¹ÄÜ
NVIC_Init(&NVIC_InitStructure); //³õʼ»¯NVIC¼Ä´æÆ÷
TIM_Cmd(TIM2, DISABLE); //ʹÄÜTIMx //ÏȹرÕ
}
//¶¨Ê±Æ÷3ÖжϷþÎñ³ÌÐò
void TIM2_IRQHandler(void) //TIM3ÖжÏ
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) //¼ì²éTIM3¸üÐÂÖжϷ¢ÉúÓë·ñ
{
t++;
TIM_ClearITPendingBit(TIM2, TIM_IT_Update ); //Çå³ýTIMx¸üÐÂÖжϱêÖ¾
}
}
void TIM3_PWM_Init(u16 arr,u16 psc)//¶à·¶æ»ú¿ØÖÆ£¬¶¨Òå¶ÔÓ¦Òý½Å£¬Ê¹ÄÜÏàӦͨµÀ£¬Ö÷º¯ÊýͬÑùÐèҪʹÄÜÏàӦͨµÀ
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ʹÄܶ¨Ê±Æ÷3ʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA , ENABLE); //ʹÄÜGPIOÍâÉèºÍAFIO¸´Óù¦ÄÜÄ£¿éʱÖÓ
//GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer3²¿·ÖÖØÓ³Éä TIM3_CH2->PB5
//ÉèÖøÃÒý½ÅΪ¸´ÓÃÊä³ö¹¦ÄÜ,Êä³öTIM3 CH2µÄPWMÂö³å²¨ÐÎ GPIOB.5
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //ÉèÖÃΪ¸´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
//³õʼ»¯TIM3
TIM_TimeBaseStructure.TIM_Period = arr; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ
TIM_TimeBaseStructure.TIM_Prescaler =psc; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòÉϼÆÊýģʽ
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾ÝTIM_TimeBaseInitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»
//³õʼ»¯TIM3 Channel2 PWMģʽ
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC1Init(TIM3, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC3Init(TIM3, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC4Init(TIM3, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_Cmd(TIM3, ENABLE); //ʹÄÜTIM3
}
void TIM4_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //ʹÄܶ¨Ê±Æ÷3ʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE); //ʹÄÜGPIOÍâÉèºÍAFIO¸´Óù¦ÄÜÄ£¿éʱÖÓ
//GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer3²¿·ÖÖØÓ³Éä TIM3_CH2->PB5
//ÉèÖøÃÒý½ÅΪ¸´ÓÃÊä³ö¹¦ÄÜ,Êä³öTIM3 CH2µÄPWMÂö³å²¨ÐÎ GPIOB.5
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //ÉèÖÃΪ¸´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
//³õʼ»¯TIM3
TIM_TimeBaseStructure.TIM_Period = arr; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ
TIM_TimeBaseStructure.TIM_Prescaler =psc; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòÉϼÆÊýģʽ
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //¸ù¾ÝTIM_TimeBaseInitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»
//³õʼ»¯TIM3 Channel2 PWMģʽ
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC1Init(TIM4, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC2Init(TIM4, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC3Init(TIM4, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //Ñ¡Ôñ¶¨Ê±Æ÷ģʽ:TIMÂö³å¿í¶Èµ÷ÖÆģʽ2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±È½ÏÊä³öʹÄÜ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ:TIMÊä³ö±È½Ï¼«ÐÔ¸ß
TIM_OC4Init(TIM4, &TIM_OCInitStructure); //¸ù¾ÝTÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèTIM3 OC2
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); //ʹÄÜTIM3ÔÚCCR2ÉϵÄԤװÔؼĴæÆ÷
TIM_Cmd(TIM4, ENABLE); //ʹÄÜTIM3
}
.h
#ifndef __TIMER_H
#define __TIMER_H
#include "sys.h"
void TIM2_Int_Init(u16 arr,u16 psc);
void TIM3_Int_Init(u16 arr,u16 psc);
void TIM3_PWM_Init(u16 arr,u16 psc);
void TIM3_Int_Init(u16 arr,u16 psc);
void TIM4_Int_Init(u16 arr,u16 psc);
void TIM4_PWM_Init(u16 arr,u16 psc);
#endif
The main function is a simple PWM wave, so I won't go into details here. At this point, the garbage classification is over. If you need complete project documents, you can leave your email below, and everyone will learn together. I will also talk about uploading project files later, and you can download them yourself if you need them.
Summarize
This article is over here. I have learned the model training and serial communication of K210, and I have done a bit of mask detection system and garbage classification. I have done two small projects and practiced my hands. I feel pretty good, hahaha. I am working on a fruit sorting truck during this time, and I will also write a blog to record it after I finish it, come on.