本例实验采用板载1路继电器:
型号为HF32F/005-ZS3,这是一款支持1路继电器输出的模块,可以控制高压高电流的负载设备,实现智能开关等功能。
本例实验采用板载三位独立按键,可以搭配实现各种相关的功能。
本例实验的SPI彩色液晶1.77寸显示屏(ST7735驱动)
TFT177-SPI,型号为SX177QQVGA,像素128X160TFT,驱动芯片为ST7735S,这是一款支持SPI接口的1.77寸TFT彩屏,可以显示文字、图形、图片等内容,提高用户互动体验度。
电原理图
【花雕动手做】实验二十四:使用按键和语音分别控制继电器的开与关
实验开源代码
#define ASC2_12
#define ST7735_CS_PIN 9
#define ST7735_CS_GPIO_PIN gpio_pin_1
#define ST7735_DC_PIN 1
#define ST7735_DC_GPIO_PIN gpio_pin_1
#define ST7735_RST_PIN 25
#define ST7735_RST_GPIO_PIN gpio_pin_1
#define ST7735_SCK_PIN 3
#define ST7735_SCK_GPIO_PIN gpio_pin_3
#define ST7735_MOSI_PIN 2
#define ST7735_MOSI_GPIO_PIN gpio_pin_2
#define ASC2_32
#define ST7735S_RGB_GBR_ORDER 0
#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/asr_st7735.h"
#include "myLib/asr_event.h"
uint32_t snid;
void pins_attached();
void hardware_init();
SPITFT spi_tft(128, 160);
//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
void pins_attached(){
while (1) {
if((digital_read((18)) == 0)){
digital_write((21),1);
digital_write((28),1);
delay(200);
enter_wakeup(5000);
delay(200);
//{ID:500,keyword:"命令词",ASR:"耍接官",ASRTO:"按键控制继电器打开"}
play_audio(500);
spi_tft.clear((0xFFFF));
spi_tft.set_text_color((0x001F),(0xFFFF));
spi_tft.set_cursor(5,70);
spi_tft.draw_hanzi_24("继电器打开");
}
if((digital_read((4)) == 0)){
digital_write((21),1);
digital_write((28),0);
delay(200);
enter_wakeup(5000);
delay(200);
//{ID:501,keyword:"命令词",ASR:"接耍官",ASRTO:"按键控制继电器关闭"}
play_audio(501);
spi_tft.clear((0xFFFF));
spi_tft.set_text_color((0xF800),(0xFFFF));
spi_tft.set_cursor(5,70);
spi_tft.draw_hanzi_24("继电器关闭");
}
delay(1);
}
vTaskDelete(NULL);
}
void ASR_CODE()
{
//{ID:502,keyword:"命令词",ASR:"反应挺快",ASRTO:"那是必须的"}
if(snid == 502){
}
//{ID:503,keyword:"唤醒词",ASR:"智能管家",ASRTO:"我在"}
if(snid == 503){
digital_write((21),1);
spi_tft.clear((0xFFFF));
}
//{ID:504,keyword:"命令词",ASR:"打开继电器",ASRTO:"语音控制继电器打开"}
if(snid == 504){
digital_write((28),1);
spi_tft.clear((0x001F));
spi_tft.set_text_color((0xFFFF),(0x001F));
spi_tft.set_cursor(0,30);
spi_tft.draw_hanzi_32("语音控制");
delay(1000);
spi_tft.set_cursor(5,70);
spi_tft.draw_hanzi_24("继电器打开");
}
//{ID:505,keyword:"命令词",ASR:"关闭继电器",ASRTO:"语音控制继电器关闭"}
if(snid == 505){
digital_write((28),0);
spi_tft.clear((0xF800));
spi_tft.set_text_color((0xFFFF),(0xF800));
spi_tft.set_cursor(0,30);
spi_tft.draw_hanzi_32("语音控制");
delay(1000);
spi_tft.set_cursor(5,70);
spi_tft.draw_hanzi_24("继电器关闭");
}
}
void hardware_init(){
spi_tft.init();
spi_tft.set_direction(2);
spi_tft.set_text_wrap(true);
spi_tft.set_text_size(32);
spi_tft.set_bg_mode(1);
xTaskCreate(pins_attached,"pins_attached",256,NULL,4,NULL);
vTaskDelete(NULL);
}
void setup()
{
//{speak:小英-温和,vol:10,speed:10,platform:haohaodada,version:V3}
//{playid:10001,voice:欢迎使用人工智能AI语音助手,用智能管家唤醒我}
//{playid:10002,voice:我退下了,用智能管家唤醒我}
digital_write((28),0);
digital_write((21),0);
digital_write((19),1);
set_gpio_input((18));
set_gpio_input((4));
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
训练模型与编译烧录
实验记录视频