ASRPRO语音识别模块
pca9685 iic通信 地址位 ADDR<<1|0 左移一位 #define I2C_WRITE 0
#define I2C_READ 1
否则通信地址错误
asrpro
通过UART与电脑连接,可以进行简单的交互
将STM32作为接口扩展,通过SPI或IIC进行端口扩展
ASRPRO常见问题
烧写:请是否连接
换好一点的USB转TTL 或是用官方的下载器
#define ST7735_CS_PIN 2
#define ST7735_CS_GPIO_PIN gpio_pin_2
#define ST7735_DC_PIN 3
#define ST7735_DC_GPIO_PIN gpio_pin_3
#define ST7735_RST_PIN 1
#define ST7735_RST_GPIO_PIN gpio_pin_1
#define ST7735_SCK_PIN 5
#define ST7735_MOSI_PIN 6
// #define ST7735_SCK_PIN 6
// #define ST7735_MOSI_PIN 5
//#define ST7735_SCK_GPIO_PIN gpio_pin_5
//#define ST7735_MOSI_GPIO_PIN gpio_pin_6
/* 宏定义 --------------------------------------------------------------------*/
#define MOSI ST7735_MOSI_PIN
#define SCK ST7735_SCK_PIN
#define DC ST7735_DC_PIN
#define CS ST7735_CS_PIN
#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/luxiaoban.h"
#include "HardwareSerial.h"
#include "../U8G2/u8g2ASR.h"
int ndelay_interupt = 0;
bool stop_sign = 0;
u8g2_class u8g2c;
void hardware_init();
void emo_class();
void weather_class();
void draw_string(const char *s);
void PlayWeatherAndDate();
void process(); //主处理函数
bool ndelay(int wait);
void drawImage();
void Show_Time();
QueueHandle_t message1=NULL;
QueueHandle_t message2=NULL;
uint32_t rec_1 = 0;
uint32_t rec_2 = 0;
uint32_t var = 0;
unsigned char COMPUTER_CONTROL = 0; //电脑接管
int CUR_X=0;
int CUR_Y = 12;//set curlsor
int draw_color = 1;
int i = 0;
int data_k = 0;
uint32_t snid;
extern "C" uint8_t myfont1[];
char cmd[20];
int cmd_k = 0; //cmd count
int m_cmd = 0;
char buff[1024] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xfe,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,
0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xff,0xfe,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
/*-------------------------------OLED---------*/
void Oled()
{
while(1)
{
if(COMPUTER_CONTROL == 0){
emo_class();
Show_Time();
weather_class();
}
if(xQueueReceive(message1,&rec_1,0)){
ndelay_interupt = 0;
stop_sign = 0;
if(rec_1 == 'e' )
{
Serial.println("MSG emo");
emo_class();
}
else if(rec_1 == 's' )
{
Serial.println("MSG string");
draw_string(cmd);
}
else if(rec_1 == 'w' )
{
Serial.println("MSG weatherData");
PlayWeatherAndDate();
}
else if(rec_1 == 'd')
{
Serial.println("msg display");
drawImage();
}
}//queuemessage end
// delay(1);
}//while end
vTaskDelete(NULL);
}
/*-------------------------------msg_process---------*/
void msg_Process(char * cmd){
if(cmd[1] == 'I') //send imag data
{
Serial.print("recv I");
i = 1024;
}
else if(cmd[1] == 'D') //display imag data
{
Serial.print("recv D");
m_cmd = 'd';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
}
else if(cmd[1] == '5') //show str
{
Serial.print("recv 5");
cmd[cmd_k-2] =0;
m_cmd = 's';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
}
else if(cmd[1] == 'W') //play weather
{
Serial.print("recv 4");
m_cmd = 'w';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//PlayWeatherAndDate();
}
else if(cmd[1] =='E') //play emo
{
Serial.print("recv 3");
m_cmd = 'e';
ndelay_interupt =1;
var = xQueueSend(message1,&m_cmd,0);
//emo_class();
}
else if(cmd[1] == 'T') //show Time
{
}
else
{
Serial.println("no cmd");
}
//command select
if(strcmp(cmd,"weather")==0) //4
{
Serial.println("play weather");
m_cmd = 'w';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//PlayWeatherAndDate();
}
else if(strcmp(cmd,"emo") == 0) //3
{
Serial.println("play emo");
m_cmd = 'e';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//emo_class();
}
//command end
}
/*-------------------------------ASR---------*/
//{speak:娇娇-邻家女声,vol:10,speed:10,platform:haohaodada}
//{playid:10001,voice:天问五幺唤醒我。}
//{playid:10002,voice:记得叫醒我哦}
//{ID:0,keyword:"唤醒词",ASR:"天问五幺",ASRTO:"哎 我在"}
void ASR_CODE()
{
//emo_tst(&u8g2);
//{ID:500,keyword:"唤醒词",ASR:"小鹿同学",ASRTO:"哎 我在呢"}
//{ID:501,keyword:"唤醒词",ASR:"小鹿小鹿",ASRTO:"哎"}
//{ID:506,keyword:"命令词",ASR:"关灯",ASRTO:"好的"}
if(snid == 503){
}
//{ID:505,keyword:"命令词",ASR:"开灯",ASRTO:"好的"}
else if(snid == 505){
//luxiaoban_digital_write(0,0);
Serial.println("开灯");
digitalWrite(4,1);
}
if(snid == 506){
Serial.println("关灯");
digitalWrite(4,0);
//luxiaoban_digital_write(0,1);
}
//{ID:1,keyword:"命令词",ASR:"开机",ASRTO:"好的"}
else if(snid == 1){
Serial.println("开机");
//luxiaoban_digital_write(0,1);
}
//{ID:2,keyword:"命令词",ASR:"关机",ASRTO:"好的"}
else if(snid == 2){
Serial.println("关机");
//luxiaoban_digital_write(0,1);
}
//{ID:3,keyword:"命令词",ASR:"播放音乐",ASRTO:"好的"}
else if(snid == 3){
Serial.println("播放音乐");
}
//{ID:4,keyword:"命令词",ASR:"天气",ASRTO:"好的"}
else if(snid == 4){
Serial.println("weather");
//luxiaoban_digital_write(0,1);
}
//{ID:5,keyword:"命令词",ASR:"时间",ASRTO:"好的"}
else if(snid == 5){
Serial.println("时间");
//luxiaoban_digital_write(0,1);
}
}
char schar;
void process() //serial process
{
while(1)
{
while(Serial.available()> 0 )
{
COMPUTER_CONTROL = 1;
schar = Serial.read();
//Serial.println(schar); //important?
if(i != 0) { //recive data
buff[data_k] = schar;
data_k = data_k + 1;
i = i -1;
cmd_k = 0;
Serial.print("i = ");
Serial.print(i);
}
else{
cmd[cmd_k] = schar;
cmd_k = cmd_k +1;
if(cmd[cmd_k-1] == '\n')
{
cmd[cmd_k-1] = 0;
Serial.println(cmd); //IMPORTANT?
//draw_string(cmd);
//接收协议 M开头 操作码OP 附加信息AD M结尾
//OP = 0 命令 1 数据
//AD OP =1 数据长度
if(cmd[0]== 'M' & cmd[cmd_k-2]=='M' )
{
Serial.println("in xiyi");
Serial.println(cmd[1]);
msg_Process(cmd);
} // end cmd[0]== 'M'
cmd_k = 0;
} //end '\n'
} //end if i !=0
} //end Serial.Avalible
delay(2); // important error no recv
}//end while(1)
vTaskDelete(NULL);
}
//创建线程
void hardware_init(){
message1=xQueueCreate(5,4);
message2=xQueueCreate(5,4);
xTaskCreate(process,"process",256,NULL,4,NULL);
xTaskCreate(Oled,"oled",256,NULL,4,NULL);
vTaskDelete(NULL);
}
void emo_class()
{
ndelay_interupt = 0;
int draw_color = 1;
u8g2c.setFont(myfont1);
u8g2c.setColorIndex(draw_color);
for(int m = 0;m<1;m++)
{ int k = 0;
for(int i = 0;i<30;i++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(34,60,96+k%6);
if(ndelay(100))
return ;
u8g2c.sendBuffer();
k = k+1;
}
}
// vTaskDelete(NULL);
}
void weather_class(void)
{
//天气
ndelay_interupt = 0;
int draw_color = 1;
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_open_iconic_weather_6x_t);
for(int m = 0;m<5;m++)
{ int k = 0;
for(int i = 0 ;i<5;i ++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(30,60,65+k%5);
if(ndelay(100))
return ;
u8g2c.sendBuffer();
k = k+1;
// Serial.print(k);
k = k+1;
}
}
}
void Show_Time()
{
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_tenfatguys_tn);
u8g2c.clearBuffer();
u8g2c.drawStrX2(20,40,"11:20");
if(ndelay(100))
return ;
u8g2c.sendBuffer();
}
void setup()
{
//Serial 0
setPinFun(13,SECOND_FUNCTION);
setPinFun(14,SECOND_FUNCTION);
Serial.begin((9600));
Serial.println("setup");
//u8g2 初始化
// u8g2Init(&u8g2);
u8g2c.u8g2_init();
pinMode(20,output); //pc4
pinMode(4,output); //pa4
setPinFun(4,FIRST_FUNCTION);
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
void PlayWeatherAndDate()
{
unsigned char r = 0;
for(int i = 0;i<100;i ++)
{
r = r % 40;
u8g2c.setColorIndex(draw_color);
u8g2c.clearBuffer();
u8g2c.setFont(u8g2_font_8x13B_tf);
u8g2c.drawStr(40,60, "12月20日");
u8g2c.setFont(u8g2_font_open_iconic_weather_4x_t);
u8g2c.drawGlyph(65,40,65);
u8g2c.drawCircle(30,30,r );
u8g2c.sendBuffer();
if(ndelay(10))
return ;
r = r+1;
}
}
//draw string
void draw_string(const char *s) {
// assign default color value
int draw_color = 1;
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_8x13B_tf);
u8g2c.clearBuffer();
u8g2c.drawStr(0,12, s);
u8g2c.sendBuffer();
if(ndelay(1000))
return ;
}
void interrupt(){
ndelay_interupt = 1;
}
bool ndelay(int wait)
{
int w = wait;
while(w >0)
{
if(ndelay_interupt == 1 )
{
//ndelay_interupt = 0;
stop_sign = 1;
Serial.println("ndelay interrup");
return 1;
}
delay(1);
w= w-1;
}
return 0;
}
void drawImage()
{
u8g2c.drawBitmap(0, 0, 16,64, buff); //right 128/8 X64
u8g2c.sendBuffer();
ndelay(1000);
}
//if(xQueueReceive(message2,&rec_2,0)){
// Serial.println(rec_2);
import serial
import threading
import time
from PIL import Image
import datetime
import json
import requests
img = ''
##with Image.open(r"tst2.png") as im:
## img = im.tobytes()
## im.show()
##print(img)
##img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x03\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
print("image len:",len(img))
def get_data(): ##https://baijiahao.baidu.com/s?id=1769484471382177983&wfr=spider&for=pc
now = datetime.datetime.now()
h = int(now.strftime("%M"))
m = int(now.strftime("%M"))
return [h,m]
def get_weather(): ##https://blog.csdn.net/gschen_cn/article/details/131886954
url = 'http://t.weather.sojson.com/api/weather/city/'
response = requests.get(url+'101280101')
d = response.json()
print( d["data"]["forecast"][0]["type"])
pass
##处理信息
def recv_msg(msg):
if msg == '开机':
print("msg is boot")
pass
if msg == '关机':
print("msg is shutdown")
pass
if msg == '播放音乐':
pass
##print(img)
sr = serial.Serial("COM12",9600,timeout = 0.1)
##sr.baudrate = 9600
##sr.bytesize = 8
##sr.parity = 'N'
##sr.stopbits = 1
time.sleep(3)
sr.set_buffer_size(2,2)
def rec_thread():
while(1):
data = ''
if(sr.inWaiting()>0):
print("receive:<------",end = '')
data = sr.read(sr.inWaiting())
print(str(data))
s1 = str(data.decode("gb2312"))
print(s1)
## if(s1 == '开灯\r\n'):
## print("is boot")
## else:
## print("is kaiden")
recv_msg(s1[0:-2])
time.sleep(0.1)
print("receive end//")
def send_imag():
sr.write("MIM\n".encode("utf-8"))
send_num = 256
k = 0;
for i in range(int(len(img)/send_num)+1):
sr.write(img[k:k+send_num])
print("send---->:",img[k:k+send_num])
k = k + send_num
sr.flush()
print("send -----------512")
time.sleep(0.5)
sr.write("MDM\n".encode("utf-8"))
if __name__ == "__main__":
t1 = threading.Thread(target = rec_thread)
t1.start()
get_weather()
while(1):
pass
## a = input("exit:q")
## if(a == 'q'):
## exit()
#### break;
## sr.write((a+'\n').encode("utf-8"))
print("---------")
使用asrpro自带的asr_softiic.h 和 arduino Adafruit_PWMServoDriver驱动库
修改处
softiic.start(_i2caddr<<1|0); // 写 0 ,读 1 (地址要左移一位
注释requestfrom ; return 0
#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "HardwareSerial.h"
#include "asr_softiic.h"
uint32_t snid;
void hardware_init();
void LED();
void ASR_CODE();
#define PCA9685_SUBADR1 0x2
#define PCA9685_SUBADR2 0x3
#define PCA9685_SUBADR3 0x4
#define PCA9685_MODE1 0x0
#define PCA9685_PRESCALE 0xFE
#define LED0_ON_L 0x6
#define LED0_ON_H 0x7
#define LED0_OFF_L 0x8
#define LED0_OFF_H 0x9
#define ALLLED_ON_L 0xFA
#define ALLLED_ON_H 0xFB
#define ALLLED_OFF_L 0xFC
#define ALLLED_OFF_H 0xFD
class Adafruit_PWMServoDriver {
public:
Adafruit_PWMServoDriver(uint8_t addr = 0x40);
void begin(void);
void reset(void);
void setPWMFreq(float freq);
void setPWM(uint8_t num, uint16_t on, uint16_t off);
void setPin(uint8_t num, uint16_t val, bool invert=false);
private:
uint8_t _i2caddr;
uint8_t read8(uint8_t addr);
void write8(uint8_t addr, uint8_t d);
};
// class MySoftIIC
// {
// public:
// void begin(){softiic.begin(0,1);}
// void stop(){softiic.stop();}
// void write(uint8_t d){softiic.write(d);}
// uint8_t read(bool b ){softiic.read(b);}
// void requestFrom(uint8_t addr,uint8_t d){};
// int start(uint8_t addr){return softiic.start(addr<<1|0);}
// void beginTransmission(uint8_t addr){start(addr);}
// void stop(){softiic.stop();}
// };
// MySoftIIC WIRE;
// Set to true to print some debug messages, or false to disable them.
#define ENABLE_DEBUG_OUTPUT false
Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(uint8_t addr) {
_i2caddr = addr;
}
void Adafruit_PWMServoDriver::begin(void) {
softiic.begin(0,1);
reset();
}
void Adafruit_PWMServoDriver::reset(void) {
write8(PCA9685_MODE1, 0x0);
}
void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
//Serial.print("Attempting to set freq ");
//Serial.println(freq);
freq *= 0.9; // Correct for overshoot in the frequency setting (see issue #11).
float prescaleval = 25000000;
prescaleval /= 4096;
prescaleval /= freq;
prescaleval -= 1;
if (ENABLE_DEBUG_OUTPUT) {
Serial.print("Estimated pre-scale: "); Serial.println(prescaleval);
}
uint8_t prescale = floor(prescaleval + 0.5);
if (ENABLE_DEBUG_OUTPUT) {
Serial.print("Final pre-scale: "); Serial.println(prescale);
}
uint8_t oldmode = read8(PCA9685_MODE1);
uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
write8(PCA9685_MODE1, newmode); // go to sleep
write8(PCA9685_PRESCALE, prescale); // set the prescaler
write8(PCA9685_MODE1, oldmode);
delay(5);
write8(PCA9685_MODE1, oldmode | 0xa1); // This sets the MODE1 register to turn on auto increment.
// This is why the beginTransmission below was not working.
// Serial.print("Mode now 0x"); Serial.println(read8(PCA9685_MODE1), HEX);
}
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
//Serial.print("Setting PWM "); Serial.print(num); Serial.print(": "); Serial.print(on); Serial.print("->"); Serial.println(off);
softiic.start(_i2caddr<<1|0);
softiic.write(LED0_ON_L+4*num);
softiic.write(on);
softiic.write(on>>8);
softiic.write(off);
softiic.write(off>>8);
softiic.stop();
}
// Sets pin without having to deal with on/off tick placement and properly handles
// a zero value as completely off. Optional invert parameter supports inverting
// the pulse for sinking to ground. Val should be a value from 0 to 4095 inclusive.
void Adafruit_PWMServoDriver::setPin(uint8_t num, uint16_t val, bool invert)
{
// Clamp value between 0 and 4095 inclusive.
if(val > 4095)
val = 4095;
if (invert) {
if (val == 0) {
// Special value for signal fully on.
setPWM(num, 4096, 0);
}
else if (val == 4095) {
// Special value for signal fully off.
setPWM(num, 0, 4096);
}
else {
setPWM(num, 0, 4095-val);
}
}
else {
if (val == 4095) {
// Special value for signal fully on.
setPWM(num, 4096, 0);
}
else if (val == 0) {
// Special value for signal fully off.
setPWM(num, 0, 4096);
}
else {
setPWM(num, 0, val);
}
}
}
uint8_t Adafruit_PWMServoDriver::read8(uint8_t addr) {
softiic.start(_i2caddr<<1|0);
softiic.write(addr);
softiic.stop();
//softiic.requestFrom((uint8_t)_i2caddr, (uint8_t)1);
//return softiic.read();
return 0;
}
void Adafruit_PWMServoDriver::write8(uint8_t addr, uint8_t d) {
softiic.start(_i2caddr<<1|0);
softiic.write(addr);
softiic.write(d);
softiic.stop();
}
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//--------------------------------------------------------
///**************************************************************
bool bl = 0;
int i=0;
void LED(){
while (1) {
//扫描设备
for(int i = 1;i<0x7f;i++)
{
// int val = softiic.start(i<<1 | 0);
// softiic.stop();
// Serial.print(i,HEX);
// Serial.print("ox ");
// Serial.println(val,HEX);
pwm.begin();
pwm.setPWMFreq(1600);
pwm.setPin(4,i*46,0);
delay(100);
}
}
vTaskDelete(NULL);
}
//------------------------------------------------
void setup()
{
Serial.begin(9600);
delay(100);
//softiic.begin(0,1);
pinMode(4,output);
setPinFun(4,FIRST_FUNCTION);
digitalWrite(4,0);
//{speak:小蝶-清新女声,vol:10,speed:10,platform:haohaodada}
//{playid:10001,voice:欢迎使用语音助手,用天问五幺唤醒我。}
//{playid:10002,voice:我退下了,用天问五幺唤醒我}
//{ID:0,keyword:"唤醒词",ASR:"天问五幺",ASRTO:"我在"}
//{ID:1,keyword:"命令词",ASR:"打开灯光",ASRTO:"好的,马上打开灯光"}
//{ID:2,keyword:"命令词",ASR:"关闭灯光",ASRTO:"好的,马上关闭灯光"}
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
//--------------------------------------------------------
//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
void hardware_init(){
xTaskCreate(LED,"LED",256,NULL,4,NULL);
vTaskDelete(NULL);
}
/*描述该功能...
*/
void ASR_CODE(){
switch (snid) {
case 1:
//digitalWrite(4,0);
break;
case 2:
//digitalWrite(4,1);
break;
}
}
接线引脚 MOSI PA5 SCK PA6 DC PA3 CS PA2
#define ST7735_CS_PIN 2
#define ST7735_CS_GPIO_PIN gpio_pin_2
#define ST7735_DC_PIN 3
#define ST7735_DC_GPIO_PIN gpio_pin_3
#define ST7735_RST_PIN 1
#define ST7735_RST_GPIO_PIN gpio_pin_1
// #define ST7735_SCK_PIN 5
// #define ST7735_MOSI_PIN 6
#define ST7735_SCK_PIN 6
#define ST7735_MOSI_PIN 5
//#define ST7735_SCK_GPIO_PIN gpio_pin_5
//#define ST7735_MOSI_GPIO_PIN gpio_pin_6
/* 宏定义 --------------------------------------------------------------------*/
#define MOSI ST7735_MOSI_PIN
#define SCK ST7735_SCK_PIN
#define DC ST7735_DC_PIN
#define CS ST7735_CS_PIN
#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/luxiaoban.h"
#include "HardwareSerial.h"
#include "../U8G2/u8g2.h"
void hardware_init();
void emo_class();
void weather_class();
//u8g2_t u8g2;
/my init
void ssd1306_spi_init()
{
pinMode(CS,output);
pinMode(DC,output);
//pinMode(ST7735_RST_PIN,output);
pinMode(SCK,output);
pinMode(MOSI,output);
}
uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
// Re-use library for delays
switch(msg)
{
//ms
case U8X8_MSG_DELAY_MILLI:
delay(1);
break;
//10 us
case U8X8_MSG_DELAY_10MICRO:
delay10us();
break;
//1 ns
case U8X8_MSG_DELAY_NANO:
delay1us();
break;
case U8X8_MSG_DELAY_100NANO:
delay1us();
break;
case U8X8_MSG_GPIO_AND_DELAY_INIT: // called once during init phase of u8g2/u8x8
ssd1306_spi_init();
break; // can be used to setup pins
case U8X8_MSG_GPIO_SPI_CLOCK: // Clock pin: Output level in arg_int
if(arg_int)
digitalWrite(SCK,1);
else
digitalWrite(SCK,0);
break;
case U8X8_MSG_GPIO_SPI_DATA: // MOSI pin: Output level in arg_int
if(arg_int)
digitalWrite(MOSI,1);
else
digitalWrite(MOSI,0);
break;
case U8X8_MSG_GPIO_CS: // CS (chip select) pin: Output level in arg_int
if(arg_int)
digitalWrite(CS,1);
else
digitalWrite(CS,0);
break;
case U8X8_MSG_GPIO_DC: // DC (data/cmd, A0, register select) pin: Output level in arg_int
if(arg_int)
digitalWrite(DC,1);
else
digitalWrite(DC,0);
break;
case U8X8_MSG_GPIO_RESET: // Reset pin: Output level in arg_int
default:
break;
}
return 1;
}
void u8g2Init(u8g2_t *u8g2)
{
u8g2_Setup_ssd1306_128x64_noname_f(u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay);
u8g2_InitDisplay(u8g2);
u8g2_SetPowerSave(u8g2, 0);
u8g2_ClearBuffer(u8g2);
}
class u8g2_class
{
public:
u8g2_t u8g2;
void u8g2_init()
{
u8g2_Setup_ssd1306_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_ClearBuffer(&u8g2);
}
void sendBuffer(void) { u8g2_SendBuffer(&u8g2); }
void clearBuffer(void) { u8g2_ClearBuffer(&u8g2); }
u8g2_uint_t drawGlyph(u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding) { return u8g2_DrawGlyph(&u8g2, x, y, encoding); }
u8g2_uint_t drawGlyphX2(u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding) { return u8g2_DrawGlyphX2(&u8g2, x, y, encoding); }
void setColorIndex(uint8_t color_index) { u8g2_SetDrawColor(&u8g2, color_index); }
void setFont(const uint8_t *font) {u8g2_SetFont(&u8g2, font); }
void setFontMode(uint8_t is_transparent) {u8g2_SetFontMode(&u8g2, is_transparent); }
void setBitmapMode(uint8_t is_transparent)
{ u8g2_SetBitmapMode(&u8g2, is_transparent); }
void drawBitmap(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
{ u8g2_DrawBitmap(&u8g2, x, y, cnt, h, bitmap); }
void drawXBM(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
{ u8g2_DrawXBM(&u8g2, x, y, w, h, bitmap); }
void drawXBMP(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
{ u8g2_DrawXBMP(&u8g2, x, y, w, h, bitmap); }
};
//创建线程
void hardware_init(){
xTaskCreate(emo_class,"emo",256,NULL,4,NULL);
vTaskDelete(NULL);
}
uint32_t snid;
extern "C" uint8_t myfont1[];
u8g2_class u8g2c;
void emo_class()
{
int draw_color = 1;
u8g2c.setFont(myfont1);
u8g2c.setColorIndex(draw_color);
while(1)
{ int k = 0;
for(int i = 0;i<72;i++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(34,60,65+k%71);
u8g2c.sendBuffer();
k = k+1;
delay(100);
}
}
vTaskDelete(NULL);
}
void weather_class(void)
{
//天气
int draw_color = 1;
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_open_iconic_weather_6x_t);
while(true)
{ int k = 0;
for(int i = 0 ;i<5;i ++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(30,60,65+k%5);
u8g2c.sendBuffer();
k = k+1;
delay(100);
// Serial.print(k);
k = k+1;
}
}
}
//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{speak:小美-娇美女声,vol:20,speed:10}
//{playid:10001,voice:鹿唤醒我}
//{playid:10002,voice:我退}
void ASR_CODE()
{
//emo_tst(&u8g2);
//{ID:500,keyword:"唤醒词",ASR:"小鹿同学",ASRTO:"我在呢"}
//{ID:501,keyword:"唤醒词",ASR:"小鹿小鹿",ASRTO:"AI"}
if(snid == 503){
luxiaoban_digital_write(0,0);
}
//{ID:505,keyword:"命令词",ASR:"请开灯",ASRTO:"灯已打开,亮度为最亮"}
if(snid == 505){
luxiaoban_digital_write(0,0);
}
//{ID:506,keyword:"命令词",ASR:"关灯",ASRTO:"灯已关闭"}
if(snid == 506){
luxiaoban_digital_write(0,1);
}
}
void setup()
{
Serial.begin((9600));
//u8g2 初始化
// u8g2Init(&u8g2);
u8g2c.u8g2_init();
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
下载U8G2
安装VS CODE
项目在VSCODE中打开
下载U8G2源码,复制U8G2->CSRC下所有文件到 天问Block\asrpro\asr_pro_sdk\U8G2(新建文件平)
引脚定义 PA
VCC->3.3 GND ->GND
#define MOSI 5
#define SCK 6
#define DC 3
#define CS 2
1将U8G2 CSRC下所有文件复制到asr_pro_sdk\U8G2
//U8G2
source-file: U8G2/u8g2lib.cpp
source-file: U8G2/u8g2_bitmap.c
source-file: U8G2/u8g2_box.c
source-file: U8G2/u8g2_buffer.c
source-file: U8G2/u8g2_button.c
source-file: U8G2/u8g2_circle.c
source-file: U8G2/u8g2_cleardisplay.c
source-file: U8G2/u8g2_d_memory.c
source-file: U8G2/u8g2_d_setup.c
source-file: U8G2/u8g2_font.c
source-file: U8G2/u8g2_fonts.c
source-file: U8G2/u8g2_hvline.c
source-file: U8G2/u8g2_input_value.c
source-file: U8G2/u8g2_intersection.c
source-file: U8G2/u8g2_kerning.c
source-file: U8G2/u8g2_line.c
source-file: U8G2/u8g2_ll_hvline.c
source-file: U8G2/u8g2_message.c
source-file: U8G2/u8g2_polygon.c
source-file: U8G2/u8g2_selection_list.c
source-file: U8G2/u8g2_setup.c
source-file: U8G2/u8x8lib.cpp
source-file: U8G2/u8x8_8x8.c
source-file: U8G2/u8x8_byte.c
source-file: U8G2/u8x8_cad.c
source-file: U8G2/u8x8_capture.c
source-file: U8G2/u8x8_debounce.c
source-file: U8G2/u8x8_display.c
source-file: U8G2/u8x8_d_ssd1306_128x64_noname.c
source-file: U8G2/u8x8_fonts.c
source-file: U8G2/u8x8_gpio.c
source-file: U8G2/u8x8_input_value.c
source-file: U8G2/u8x8_message.c
source-file: U8G2/u8x8_selection_list.c
source-file: U8G2/u8x8_setup.c
source-file: U8G2/u8x8_string.c
source-file: U8G2/u8x8_u16toa.c
source-file: U8G2/u8x8_u8toa.c
//header file path.
include-path: U8G2
完整的source_file.prj文件
天问Block\asrpro\asr_pro_sdk\projects\offline_asr_sample\project_file\source_file.prj
//source files.
//U8G2
source-file: U8G2/u8g2lib.cpp
source-file: U8G2/u8g2_bitmap.c
source-file: U8G2/u8g2_box.c
source-file: U8G2/u8g2_buffer.c
source-file: U8G2/u8g2_button.c
source-file: U8G2/u8g2_circle.c
source-file: U8G2/u8g2_cleardisplay.c
source-file: U8G2/u8g2_d_memory.c
source-file: U8G2/u8g2_d_setup.c
source-file: U8G2/u8g2_font.c
source-file: U8G2/u8g2_fonts.c
source-file: U8G2/u8g2_hvline.c
source-file: U8G2/u8g2_input_value.c
source-file: U8G2/u8g2_intersection.c
source-file: U8G2/u8g2_kerning.c
source-file: U8G2/u8g2_line.c
source-file: U8G2/u8g2_ll_hvline.c
source-file: U8G2/u8g2_message.c
source-file: U8G2/u8g2_polygon.c
source-file: U8G2/u8g2_selection_list.c
source-file: U8G2/u8g2_setup.c
source-file: U8G2/u8x8lib.cpp
source-file: U8G2/u8x8_8x8.c
source-file: U8G2/u8x8_byte.c
source-file: U8G2/u8x8_cad.c
source-file: U8G2/u8x8_capture.c
source-file: U8G2/u8x8_debounce.c
source-file: U8G2/u8x8_display.c
source-file: U8G2/u8x8_d_ssd1306_128x64_noname.c
source-file: U8G2/u8x8_fonts.c
source-file: U8G2/u8x8_gpio.c
source-file: U8G2/u8x8_input_value.c
source-file: U8G2/u8x8_message.c
source-file: U8G2/u8x8_selection_list.c
source-file: U8G2/u8x8_setup.c
source-file: U8G2/u8x8_string.c
source-file: U8G2/u8x8_u16toa.c
source-file: U8G2/u8x8_u8toa.c
source-file: U8G2/myfont1.c
source-file: startup/asrpro_init.c
source-file: startup/asrpro_vtable.S
source-file: startup/asrpro_startup.S
source-file: system/asrpro_it.c
source-file: system/asrpro_system.c
source-file: system/platform_config.c
source-file: system/asrpro_handlers.c
source-file: system/baudrate_calibrate.c
source-file: components/assist/debug_time_consuming.c
source-file: components/freertos/croutine.c
source-file: components/freertos/event_groups.c
source-file: components/freertos/list.c
source-file: components/freertos/queue.c
source-file: components/freertos/stream_buffer.c
source-file: components/freertos/tasks.c
source-file: components/freertos/timers.c
source-file: components/freertos/portable/MemMang/heap_3.c
source-file: components/log/ci_log.c
source-file: components/flash_control/flash_control_src/ci_flash_data_info.c
source-file: components/flash_control/flash_control_src/flash_control_inner_port.c
source-file: components/player/audio_play/audio_play_api.c
source-file: components/player/audio_play/audio_play_decoder.c
source-file: components/player/audio_play/audio_play_process.c
source-file: components/player/audio_play/audio_play_os_port.c
source-file: components/player/audio_play/audio_play_device.c
source-file: components/player/audio_play/get_play_data.c
source-file: components/player/adpcm/adpcmdec.c
source-file: components/player/adpcm/adpcm.c
source-file: components/player/m4a/parse_m4a_atom_containers_port.c
source-file: components/player/m4a/parse_m4a_atom_containers.c
source-file: components/player/flacdec/bitstreamf.c
source-file: components/player/flacdec/flacdecoder.c
source-file: components/player/flacdec/tables.c
source-file: components/player/sonic/sonic.c
source-file: components/status_share/status_share.c
source-file: components/ci_nvdm/ci_nvdata_manage.c
source-file: components/ci_nvdm/ci_nvdata_port.c
source-file: components/cmd_info/command_file_reader.c
source-file: components/cmd_info/command_info.c
source-file: components/cmd_info/prompt_player.c
//source-file: components/audio_in_manage/iis_master_rx.c
//source-file: components/audio_in_manage/iis_slave.c
//source-file: components/audio_in_manage/audio_in_manage.c
source-file: components/audio_in_manage/audio_in_manage_inner.c
source-file: components/asr/asr_malloc_port.c
source-file: components/asr/asr_process_callback_decoder.c
source-file: components/asr/asr_process_callback.c
source-file: components/codec_manager/codec_manager.c
source-file: components/codec_manager/codec_manage_inner_port.c
source-file: components/msg_com/voice_module_uart_protocol_g1.c
source-file: components/msg_com/i2c_protocol_module.c
source-file: components/msg_com/voice_module_uart_protocol.c
source-file: components/led/color_light_control.c
source-file: components/led/led_light_control.c
//source-file: components/example/iic_test.c
source-file: components/audio_pre_rslt_iis_out/asrpro_audio_pre_rslt_out.c
source-file: driver/asrpro_chip_driver/src/asrpro_core_eclic.c
source-file: driver/asrpro_chip_driver/src/asrpro_core_timer.c
source-file: driver/asrpro_chip_driver/src/asrpro_dma.c
source-file: driver/asrpro_chip_driver/src/asrpro_codec.c
source-file: driver/asrpro_chip_driver/src/asrpro_pdm.c
source-file: driver/asrpro_chip_driver/src/asrpro_alc.c
source-file: driver/asrpro_chip_driver/src/asrpro_iisdma.c
source-file: driver/asrpro_chip_driver/src/asrpro_core_misc.c
source-file: driver/asrpro_chip_driver/src/asrpro_iis.c
source-file: driver/asrpro_chip_driver/src/asrpro_adc.c
source-file: driver/asrpro_chip_driver/src/asrpro_gpio.c
source-file: driver/asrpro_chip_driver/src/asrpro_iic.c
source-file: driver/asrpro_chip_driver/src/asrpro_pwm.c
source-file: driver/asrpro_chip_driver/src/asrpro_timer.c
source-file: driver/asrpro_chip_driver/src/asrpro_uart.c
//source-file: driver/asrpro_chip_driver/src/asrpro_inner_codec.c
source-file: driver/asrpro_chip_driver/src/asrpro_lowpower.c
source-file: driver/asrpro_chip_driver/src/asrpro_iwdg.c
source-file: driver/asrpro_chip_driver/src/asrpro_spiflash.c
source-file: driver/asrpro_chip_driver/src/asrpro_dtrflash.c
source-file: driver/boards/board.c
source-file: driver/boards/board_default.c
source-file: utils/dichotomy_find.c
source-file: utils/crc.c
source-file: projects/offline_asr_sample/src/main.c
source-file: projects/offline_asr_sample/src/system_hook.c
source-file: projects/offline_asr_sample/src/system_msg_deal.c
source-file: projects/offline_asr_sample/src/user_msg_deal.c
source-file: projects/offline_asr_sample/src/ci_ssp_config.c
source-file: projects/offline_asr_sample/src/wiring.c
source-file: projects/offline_asr_sample/src/CString/dtostrf.c
source-file: projects/offline_asr_sample/src/CString/itoa.c
source-file: projects/offline_asr_sample/src/CString/HardwareSerial.cpp
source-file: projects/offline_asr_sample/src/CString/Stream.cpp
source-file: projects/offline_asr_sample/src/CString/Print.cpp
source-file: projects/offline_asr_sample/src/CString/WString.cpp
source-file: components/ir_remote_driver/ir_remote_driver.c
source-file: ../asr.cpp
library-file: $(LIBS_PATH)/libasr.a
library-file: $(LIBS_PATH)/libnewlib_port.a
library-file: $(LIBS_PATH)/libfreertos_port.a
library-file: $(LIBS_PATH)/libdsu.a
library-file: $(LIBS_PATH)/libflash_encrypt.a
library-file: $(LIBS_PATH)/libir_data.a
//header file path.
include-path: U8G2
include-path: driver/asrpro_chip_driver/inc
include-path: driver/boards
include-path: driver/third_device_driver/outside_codec
include-path: system
include-path: components/log
include-path: components/assist
include-path: components/freertos/include
include-path: components/freertos/portable/GCC/N307
include-path: components
include-path: components/asr
include-path: components/asr/asr_top
include-path: components/asr/asr_top/asr_top_inc
include-path: components/asr/decoder/decoder_inc
include-path: components/asr/vad_fe
include-path: components/asr/vad_fe/vad_fe_inc
include-path: components/asr/dnn
include-path: components/asr/dnn/dnn_inc
include-path: components/asr/cinn/cinn_inc
include-path: components/asr/npu/npu_inc
include-path: components/asr/nn_and_flash
include-path: components/asr/nn_and_flash/nn_and_flash_inc
include-path: components/fft
include-path: components/msg_com
include-path: components/led
include-path: components/player/audio_play
include-path: components/player/mp3lib/mp3pub
include-path: components/player/aaclib/aacpub
include-path: components/player/flacdec
include-path: components/player/m4a
include-path: components/player/adpcm
include-path: components/status_share
include-path: components/flash_control/flash_control_inc
include-path: components/flash_encrypt
include-path: components/codec_manager
include-path: components/ci_nvdm
include-path: components/cmd_info
include-path: components/sys_monitor
include-path: components/ota
include-path: components/audio_pre_rslt_iis_out
include-path: components/audio_in_manage
include-path: components/assist/SEGGER
include-path: components/assist/SEGGER/config
include-path: components/nuclear_com
include-path: components/audio_pre_rslt_iis_out
include-path: projects/offline_asr_sample/src
include-path: utils
include-path: projects/offline_asr_sample/src
include-path: projects/offline_asr_sample/src/CString
include-path: ../myLib
include-path: components/alg
include-path: components/alg/denoise
include-path: components/alg/beamforming
include-path: components/alg/dereverb
include-path: components/alg/alc_auto_switch
include-path: components/alg/basic_alg
include-path: components/alg/aec
include-path: components/alg/doa
include-path: components/ir_remote_driver
include-path: projects/offline_asr_sample/src/ir_src
U8G2目录位置与内容
天问Block\asrpro\asr_pro_sdk\U8G2
编辑
2 .添加源文件与头文件
asr_pro_sdk\projects\offline_asr_sample\project_file\source_file.prj
3. asr_pro_sdk\projects\offline_asr_sample\project_file\rebuild.bat在集成终端中打开
运行./rebuild
主程序
#define ST7735_CS_PIN 2
#define ST7735_CS_GPIO_PIN gpio_pin_2
#define ST7735_DC_PIN 3
#define ST7735_DC_GPIO_PIN gpio_pin_3
#define ST7735_RST_PIN 1
#define ST7735_RST_GPIO_PIN gpio_pin_1
#define ST7735_SCK_PIN 6
#define ST7735_SCK_GPIO_PIN gpio_pin_5
#define ST7735_MOSI_PIN 5
#define ST7735_MOSI_GPIO_PIN gpio_pin_6
/* 宏定义 --------------------------------------------------------------------*/
#define MOSI ST7735_MOSI_PIN
#define SCK ST7735_SCK_PIN
#define DC ST7735_DC_PIN
#define CS ST7735_CS_PIN
//#ifndef _ST7735_H
//#define _ST7735_H
//#include "twen_gfx.h"
#include "asr.h"
#include "setup.h"
#include "myLib/luxiaoban.h"
#include "../U8G2/u8g2.h"
//void delayMicroseconds(uint32_t us);
volatile uint32_t * _cs_reg = NULL;
volatile uint32_t * _rst_reg = NULL;
volatile uint32_t * _dc_reg = NULL;
volatile uint32_t * _sck_reg = NULL;
volatile uint32_t * _t_reg = NULL;
uint32_t snid;
//SSD1306 回调函数1
u8g2_t u8g2;
extern "C" uint8_t myfont1[]; //��������
void emo_tst(u8g2_t *u8g2)
{
//emo ����
int draw_color = 1;
int k = 0;
for(int i = 0;i<66;i++)
{
k = k+1;
u8g2_SetDrawColor(u8g2,draw_color);
u8g2_ClearBuffer(u8g2);
//u8g2.setFont(u8g2_font_8x13B_tf);
//u8g2_DrawStr(0,10,num(k));
u8g2_SetFont(u8g2,myfont1);
u8g2_DrawGlyph(u8g2,34,60,65+k%71);
//u8g2.drawGlyphX2(0,0,65+k%45);
u8g2_SendBuffer(u8g2);
delay(100);
}
}
void ssd1306_spi_init()
{
pinMode(CS,output);
pinMode(DC,output);
//pinMode(ST7735_RST_PIN,output);
pinMode(SCK,output);
pinMode(MOSI,output);
}
uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
// Re-use library for delays
switch(msg)
{
//ms
case U8X8_MSG_DELAY_MILLI:
delay(1);
break;
//10 us
case U8X8_MSG_DELAY_10MICRO:
delay10us();
break;
//1 ns
case U8X8_MSG_DELAY_NANO:
delay1us();
break;
case U8X8_MSG_DELAY_100NANO:
delay1us();
break;
case U8X8_MSG_GPIO_AND_DELAY_INIT: // called once during init phase of u8g2/u8x8
ssd1306_spi_init();
break; // can be used to setup pins
case U8X8_MSG_GPIO_SPI_CLOCK: // Clock pin: Output level in arg_int
if(arg_int)
digitalWrite(SCK,1);
else
digitalWrite(SCK,0);
break;
case U8X8_MSG_GPIO_SPI_DATA: // MOSI pin: Output level in arg_int
if(arg_int)
digitalWrite(MOSI,1);
else
digitalWrite(MOSI,0);
break;
case U8X8_MSG_GPIO_CS: // CS (chip select) pin: Output level in arg_int
if(arg_int)
digitalWrite(CS,1);
else
digitalWrite(CS,0);
break;
case U8X8_MSG_GPIO_DC: // DC (data/cmd, A0, register select) pin: Output level in arg_int
if(arg_int)
digitalWrite(DC,1);
else
digitalWrite(DC,0);
break;
case U8X8_MSG_GPIO_RESET: // Reset pin: Output level in arg_int
default:
break;
}
return 1;
}
void u8g2Init(u8g2_t *u8g2)
{
u8g2_Setup_ssd1306_128x64_noname_f(u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay);
u8g2_InitDisplay(u8g2);
u8g2_SetPowerSave(u8g2, 0);
u8g2_ClearBuffer(u8g2);
}
void draw(u8g2_t *u8g2)
{
u8g2_ClearBuffer(u8g2);
u8g2_SetFontMode(u8g2, 1);
u8g2_SetFontDirection(u8g2, 0);
u8g2_SetFont(u8g2, u8g2_font_inb24_mf);
u8g2_DrawStr(u8g2, 0, 20, "U");
u8g2_SetFontDirection(u8g2, 1);
u8g2_SetFont(u8g2, u8g2_font_inb30_mn);
u8g2_DrawStr(u8g2, 21,8,"8");
u8g2_SetFontDirection(u8g2, 0);
u8g2_SetFont(u8g2, u8g2_font_inb24_mf);
u8g2_DrawStr(u8g2, 51,30,"g");
u8g2_DrawStr(u8g2, 67,30,"\xb2");
u8g2_DrawHLine(u8g2, 2, 35, 47);
u8g2_DrawHLine(u8g2, 3, 36, 47);
u8g2_DrawVLine(u8g2, 45, 32, 12);
u8g2_DrawVLine(u8g2, 46, 33, 12);
u8g2_SetFont(u8g2, u8g2_font_4x6_tr);
u8g2_DrawStr(u8g2, 1,54,"github.com/olikraus/u8g2");
u8g2_SendBuffer(u8g2);
delay(1000);
}
//u8g2_t u8g2;
//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
//{speak:小美-娇美女声,vol:20,speed:10}
//{playid:10001,voice:鹿唤醒我}
//{playid:10002,voice:我退}
void ASR_CODE()
{
emo_tst(&u8g2);
//{ID:500,keyword:"唤醒词",ASR:"小鹿同学",ASRTO:"我在呢"}
//{ID:501,keyword:"唤醒词",ASR:"小鹿小鹿",ASRTO:"AI"}
//{ID:502,keyword:"唤醒词",ASR:"你好小鹿",ASRTO:"请吩咐"}
//{ID:503,keyword:"命令词",ASR:"开灯",ASRTO:"灯已打开,亮度为最亮"}
if(snid == 503){
luxiaoban_digital_write(0,0);
}
//{ID:504,keyword:"命令词",ASR:"打开灯光",ASRTO:"灯已打开,亮度为最亮"}
if(snid == 504){
luxiaoban_digital_write(0,0);
}
//{ID:505,keyword:"命令词",ASR:"请开灯",ASRTO:"灯已打开,亮度为最亮"}
if(snid == 505){
luxiaoban_digital_write(0,0);
}
//{ID:506,keyword:"命令词",ASR:"关灯",ASRTO:"灯已关闭"}
if(snid == 506){
luxiaoban_digital_write(0,1);
}
//{ID:507,keyword:"命令词",ASR:"关闭灯光",ASRTO:"灯光已关闭"}
if(snid == 507){
luxiaoban_digital_write(0,1);
}
//{ID:508,keyword:"命令词",ASR:"请关灯",ASRTO:"灯已关闭"}
if(snid == 508){
luxiaoban_digital_write(0,1);
}
}
void setup()
{
Serial.begin((9600));
u8g2Init(&u8g2);
draw(&u8g2);
emo_tst(&u8g2);
}
void loop()
{
}
make时生成的文件在 asr_pro_sdk\projects\offline_asr_sample\project_file\build\objs下