[STM32 single-chip microcomputer] intelligent classification trash can based on speech recognition, how to use ld3320 speech recognition module, how to use mp3 player module

need

For "recyclables", "hazardous garbage", "kitchen waste" and "other garbage", what should I do if I can't tell which trash bin to throw in?

The intelligent classification of trash cans based on voice recognition can open the corresponding trash cans when keywords are recognized, and there is no trouble of being confused at all.
insert image description here

//Recyclables: plastic bottles, glass bottles, aluminum cans, paper, cardboard, newspapers, paper packaging boxes, metal cans, etc.
//Hazardous waste: waste batteries, waste lamps, waste fluorescent lamps, waste paint, waste pesticides, waste medicines, waste electronic products, etc.
//Kitchen waste: leftovers, fruit peels and cores, vegetable and fruit residues, tea leaves, coffee grounds, etc.
// Other garbage: cigarette butts, disposable paper cups, disposable tableware, dust, disposable diapers, toilet paper, old clothes, ceramic shards, etc.

Hardware: SCM, voice recognition module ld3320, 4 servos (trash can), 4 LED lights, 4 buttons, my1690 and speakers.
Software:
1. The 4 steering gears correspond to recyclables, hazardous waste, kitchen waste, and other garbage. A steering gear of 0 degrees means that the trash can lid is closed, and a steering gear of 90 degrees means that the trash can lid is open. The garbage cans in the video are manual work, and the technical staff can’t do it manually. After the technical side is done with the steering gear, the customer needs to install the steering gear on the trash can lid by himself.
2. Voice broadcast "Welcome to use intelligent voice sorting garbage bin"
after starting up. 3. The wake-up word "throw out garbage". Corresponding steering gear. Here you need to set some common garbage words and corresponding categories.
4. The wake-up word "throw out garbage", after successful wake-up, directly say "recyclables", "hazardous garbage", "kitchen waste" and "other garbage" can also open the corresponding trash bin.
5. If there is no voice command for 20 seconds after waking up, the voice prompts "The operation is complete, if you need to re-operate, please say throw away the trash" to exit the wake-up state.
6. After the corresponding trash can is opened, the corresponding small light should be turned on. After the corresponding trash can is closed, the corresponding small light should go out.
7. Press the corresponding button, and the trash can will open. When the corresponding button is released, the trash can is closed.

speech recognition module

Use STM32 microcontroller.

5V supplies power to this module, and this module has a ttl level of 3.3V.

You need to download the program for this module and use the cold start method.

Recognition effect optimization: For example, "milk", you can add niu nai and liu nai.

insert image description here

MY1690 playback module

Use Baidu Translator or other software to obtain the audio mp3 file of speech synthesis, put the file into the TF card, and name it from 0001 to 9999.

5V power supply, 3.3v ttl output.

The high current of the power amplifier may cause the failure of the single chip microcomputer. At the beginning of the program, the sound of the module can be set to be lower, from 1 to 33 levels.

Corresponding code:

void uart_send(u8 data) {
    
    
	while (USART_GetFlagStatus(USART2, USART_FLAG_TC) != SET); //等待发送结束
  USART_SendData(USART2, data);//向串口2发送数据
    
}

void bofang(void) {
    
    
    uart_send(0x7E);
    uart_send(0x03);
    uart_send(0x11);
    uart_send(0x12);
    uart_send(0xEF);
}

void tingzhi(void) {
    
    
    uart_send(0x7E);
    uart_send(0x03);
    uart_send(0x1e);
    uart_send(0x1d);
    uart_send(0xEF);
}
void set_volume( unsigned char volume )
{
    
    
 unsigned char jiaoyan;
 unsigned char cmd = 0x31;
 
 if(volume<5)
 {
    
    
  volume=5;
 }
 if(volume>30)
 {
    
    
  volume=30;
 }
 jiaoyan = 0x04 ^ cmd;
 jiaoyan = jiaoyan ^ volume;
 
 //uart_send( 0x7E ); 
 
 uart_send( 0x7E );       
 uart_send( 0x04 );       
 uart_send( cmd );        
 uart_send( volume );        
 uart_send( jiaoyan );    
 uart_send( 0xEF );       
}


void select_song_number(unsigned char cs2) {
    
    
    unsigned char jiaoyan;
    unsigned char cmd = 0x41;
    unsigned char cs1 = 0;

    jiaoyan = 0x05 ^ cmd;
    jiaoyan = jiaoyan ^ cs1;
    jiaoyan = jiaoyan ^ cs2;
	
	//uart_send(0x7E);
	
    uart_send(0x7E);
    uart_send(0x05);
    uart_send(cmd);
    uart_send(cs1);
    uart_send(cs2);
    uart_send(jiaoyan);
    uart_send(0xEF);

}

steering gear

The steering gear is driven by PWM for 20ms, and the high level time of 1ms to 2ms corresponds to different angles.

source code

#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
void motor_contorl(u8 motor, u8 open) {
    
    
    //https://qq742971636.blog.csdn.net/article/details/115017052
    //手册可能写的是高电平是1ms到2ms,其实给0.5ms到2.5ms
    if (motor == 1) {
    
    
        if (open) {
    
    
            TIM_SetCompare1(TIM3, 50);//舵机打开,意味着垃圾桶1打开
            LED1 = 0;//小灯打开
        } else {
    
    
            TIM_SetCompare1(TIM3, 100);//舵机关闭,意味着垃圾桶1关闭
            LED1 = 1;//小灯关闭
        }
    } else if (motor == 2) {
    
    
        if (open) {
    
    
            TIM_SetCompare2(TIM3, 50);//舵机打开,意味着垃圾桶2打开
            LED2 = 0;//小灯打开

        } else {
    
    
            TIM_SetCompare2(TIM3, 100);//舵机关闭,意味着垃圾桶2关闭
            LED2 = 1;//小灯关闭
        }
    } else if (motor == 3) {
    
    
        if (open) {
    
    
            TIM_SetCompare3(TIM3, 50);//舵机打开,意味着垃圾桶3打开
            LED3 = 0;//小灯打开

        } else {
    
    
            TIM_SetCompare3(TIM3, 100);//舵机关闭,意味着垃圾桶3关闭
            LED3 = 1;//小灯关闭
        }
    } else if (motor == 4) {
    
    
        if (open) {
    
    
            TIM_SetCompare4(TIM3, 50);//舵机打开,意味着垃圾桶4打开
            LED4 = 0;//小灯打开
        } else {
    
    
            TIM_SetCompare4(TIM3, 100);//舵机关闭,意味着垃圾桶4关闭
            LED4 = 1;//小灯关闭
        }
    }
}

void uart_send(u8 data) {
    
    
	while (USART_GetFlagStatus(USART2, USART_FLAG_TC) != SET); //等待发送结束
  USART_SendData(USART2, data);//向串口2发送数据
    
}

void bofang(void) {
    
    
    uart_send(0x7E);
    uart_send(0x03);
    uart_send(0x11);
    uart_send(0x12);
    uart_send(0xEF);
}

void tingzhi(void) {
    
    
    uart_send(0x7E);
    uart_send(0x03);
    uart_send(0x1e);
    uart_send(0x1d);
    uart_send(0xEF);
}
void set_volume( unsigned char volume )
{
    
    
 unsigned char jiaoyan;
 unsigned char cmd = 0x31;
 
 if(volume<5)
 {
    
    
  volume=5;
 }
 if(volume>30)
 {
    
    
  volume=30;
 }
 jiaoyan = 0x04 ^ cmd;
 jiaoyan = jiaoyan ^ volume;
 
 //uart_send( 0x7E ); 
 
 uart_send( 0x7E );       
 uart_send( 0x04 );       
 uart_send( cmd );        
 uart_send( volume );        
 uart_send( jiaoyan );    
 uart_send( 0xEF );       
}


void select_song_number(unsigned char cs2) {
    
    
    unsigned char jiaoyan;
    unsigned char cmd = 0x41;
    unsigned char cs1 = 0;

    jiaoyan = 0x05 ^ cmd;
    jiaoyan = jiaoyan ^ cs1;
    jiaoyan = jiaoyan ^ cs2;
	
	//uart_send(0x7E);
	
    uart_send(0x7E);
    uart_send(0x05);
    uart_send(cmd);
    uart_send(cs1);
    uart_send(cs2);
    uart_send(jiaoyan);
    uart_send(0xEF);

}

u8 sec_auto_close = 0;//自动关闭垃圾桶的计时器
u8 sec_auto_close_flag = 0;//自动关闭垃圾桶的计时器的标志位

u8 no_command_flag = 0;//没有指令的标志位
u8 no_command = 0;//没有指令的计时器

int main(void) {
    
    
    u8 key = 1;

    delay_init();             //延时函数初始化
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);     //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
    uart_init(9600);
    USART2_Init(9600);
	  USART3_Init(9600);
	
    LED_Init();                 //LED端口初始化
    KEY_Init();


    TIM3_PWM_Init(1000, 71 * 20);     //50HZ  20ms<-->1000 1ms<-->50  2ms<-->100
    motor_contorl(1, 0);//关闭垃圾桶舵机1
    motor_contorl(2, 0);//关闭垃圾桶舵机2
    motor_contorl(3, 0);//关闭垃圾桶舵机3
    motor_contorl(4, 0);//关闭垃圾桶舵机4

    TIM4_Int_Init(1000, 71 * 20);//20ms
		
		
		//delay_ms(200);
		set_volume(10);
	
		//delay_ms(200);
    select_song_number(0x01);//播放0001 欢迎使用智能语音分类垃圾箱
		

    while (1) {
    
    
        delay_ms(10);
        key = KEY_Scan(1);//得到键值

        if (key) {
    
    //有按键按下
            if (key == 1) {
    
    
                motor_contorl(1, 1);//打开垃圾桶舵机1
            } else if (key == 2) {
    
    
                motor_contorl(2, 1);//打开垃圾桶舵机2
            } else if (key == 3) {
    
    
                motor_contorl(3, 1);//打开垃圾桶舵机3
            } else if (key == 4) {
    
    
                motor_contorl(4, 1);//打开垃圾桶舵机4
            }
            while (KEY_Scan(1));
            motor_contorl(1, 0);//关闭垃圾桶舵机1
            motor_contorl(2, 0);//关闭垃圾桶舵机2
            motor_contorl(3, 0);//关闭垃圾桶舵机3
            motor_contorl(4, 0);//关闭垃圾桶舵机4
        }


    }
}

//软件:
//1、 4个舵机对应 可回收物、有害垃圾、厨余垃圾、其它垃圾, 舵机为0度表示垃圾桶盖关闭,舵机为90度表示垃圾桶盖打开。视频里的垃圾桶那些东西属于手工活了,技术大老粗做手工不行,技术这边用舵机做了之后,客户需要自己把舵机安装在垃圾桶盖上。
//2、 开机后语音播报“欢迎使用智能语音分类垃圾箱”
//3、唤醒词“扔垃圾”,成功唤醒后,回复语音“请说出所扔垃圾种类或者垃圾名称”,客户说出物品名称,单片机打开对应舵机。  这里需要设定一些常见垃圾词和对应类别(客户补充一下)。
//4、唤醒词“扔垃圾”,成功唤醒后,直接说“可回收物”“有害垃圾”“厨余垃圾”“其它垃圾”也可以打开对应垃圾箱。
//5、唤醒后20秒无语音命令,则语音提示“操作完毕,如需重新操作请说扔垃圾”退出唤醒状态。
//6、对应垃圾桶打开后,对应小灯应打开。对应垃圾桶关闭后,对应小灯应熄灭。
//7、对应按键按下,则垃圾桶打开。对应按键松开,则垃圾桶关闭。

//存放在my1690的sd卡的歌曲如下
//0001 欢迎使用智能语音分类垃圾箱
//0002 请说出所扔垃圾种类或者垃圾名称
//0003 操作完毕,如需重新操作请说扔垃圾

//如果收到语音模块发过来的指令,每个指令需要对应操作
//指令1  0x00  成功唤醒
//指令2  0x02  识别到"可回收物"
//指令3  0x03  识别到"有害垃圾"
//指令4  0x04  识别到"厨余垃圾"
//指令5  0x05  识别到"其它垃圾"
//指令6  0x06  识别到"塑料瓶"
//指令7  0x07  识别到"电池"
//指令8  0x08  识别到"剩菜剩饭"
//指令9  0x09  识别到"烟头"


//ld3320
void USART1_IRQHandler(void)                    //串口1中断服务程序
{
    
    
    u8 Res;

    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)  //接收中断(接收到的数据必须是0x0d 0x0a结尾)
    {
    
    
        Res = USART_ReceiveData(USART1);    //读取接收到的数据

        if (Res == 0x00) {
    
    
            //select_song_number(0x01);//播放0001 欢迎使用智能语音分类垃圾箱

            no_command_flag = 1;//20秒无语音命令标志位   是唤醒状态!!!!!!!!!!!
            no_command = 20;//20秒自动关闭标志位

            select_song_number(0x02);//播放0002 请说出所扔垃圾种类或者垃圾名称

        }
        if (no_command_flag == 1)//是唤醒状态
        {
    
    
            if (Res == 0x02) {
    
    
                motor_contorl(1, 1);//打开垃圾桶舵机1
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x03) {
    
    
                motor_contorl(2, 1);//打开垃圾桶舵机2
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x04) {
    
    
                motor_contorl(3, 1);//打开垃圾桶舵机3
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x05) {
    
    
                motor_contorl(4, 1);//打开垃圾桶舵机4
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x06) {
    
    
                motor_contorl(1, 1);//打开垃圾桶舵机1
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x07) {
    
    
                motor_contorl(2, 1);//打开垃圾桶舵机2
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x08) {
    
    
                motor_contorl(3, 1);//打开垃圾桶舵机3
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            } else if (Res == 0x09) {
    
    
                motor_contorl(4, 1);//打开垃圾桶舵机4
                sec_auto_close_flag = 1;//开启20秒自动关闭
                sec_auto_close = 20;//20秒自动关闭

                no_command_flag = 0;//有指令则无需再计时回答
            }
        }
    }

}

//my1690
void USART2_IRQHandler(void) {
    
    
    u8 res;
    if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) /* 接收到数据 */
    {
    
    
        res = USART_ReceiveData(USART2);


    }
}

//定时器4中断服务程序
void TIM4_IRQHandler(void)   //TIM4中断
{
    
    
    static u8 cnt = 0;
    if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
    {
    
    
        TIM_ClearITPendingBit(TIM4, TIM_IT_Update);  //清除TIMx的中断待处理位:TIM 中断源
        cnt++;
        if (cnt == 50)//1秒
        {
    
    
            cnt = 0;
            if (sec_auto_close_flag)//开启20秒自动关闭
            {
    
    
                if (sec_auto_close) {
    
    
                    sec_auto_close--;//20秒自动关闭计时
                } else {
    
    
                    sec_auto_close_flag = 0;//关闭20秒自动关闭

                    motor_contorl(1, 0);//关闭垃圾桶舵机1
                    motor_contorl(2, 0);//关闭垃圾桶舵机2
                    motor_contorl(3, 0);//关闭垃圾桶舵机3
                    motor_contorl(4, 0);//关闭垃圾桶舵机4

                }
            }


            if (no_command_flag)//开启20秒自动关闭
            {
    
    
                if (no_command) {
    
    
                    no_command--;//20秒自动关闭计时
                } else {
    
    
                    no_command_flag = 0;//关闭20秒自动关闭

                    select_song_number(0x03);//播放0003 没有听到您的指令.  操作完毕,如需重新操作请说扔垃圾

                }
            }

        }
    }
}



All projects:
insert image description here
Download: https://github.com/xddun/blog_code_search

Guess you like

Origin blog.csdn.net/x1131230123/article/details/131043983