中秋节刚过,大家月饼盒应该还有,不要扔,可以做点小玩意。
机器狗的创意来自B站石桥北的视频,他使用了一块ESP32芯片和打印件加四个舵机实现,应该说是比较复杂的,需要有3D打印机打印外壳,还得会手机编程,有一定的专业度。
我这个简略版核心部件一块ASR芯片+4个舵机,四个舵机就是四条腿,ASR芯片本身带离线对话功能,自己设计一下对话控制舵机就好了。如果要增加趣问性,可以加一块OLED屏幕显示一些操作指令和绘制一些表情,
如上图,asrpro芯片包含六个舵机引脚pwm0到pwm5,我们只使用了四个,剩下两个有兴趣的还可以加上个尾巴和头,或者加上红外,温湿度传感器之类,oled屏将会占去两个,其他引脚就看大家发挥了。
最好是方形的盒子,这样好定位,贴着盒子底部,在盒子两侧一边挖两个方形的洞,如上图,正好可以把舵露出来舵机头为好,口的大小以能卡住固定镙丝的地方为宜。可以先使用纸片沿着舵机屁股裁一块相同大小的纸片,然后用这个纸片在盒子上比划出大小,然后使用美工刀挖出来。易拉罐应该也可以的,不过要使用胶带包一下,防止划破手,如下:
最终如下,:
接线:
PA2,PA3,PA5,PA6初始化为四个舵机,
PA0和PA1初始化为OLED屏。
完整的代码和图:
#define ASC2_12#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/asr_event.h"
#include "myLib/asr_ssd1306.h"
#include "myLib/asr_servo.h"uint32_t snid;
Servo servo_3;
Servo servo_2;
Servo servo_5;
Servo servo_6;
void ASR_CODE();//{speak:程程-标准男童,vol:10,speed:10,platform:haohaodada}
//{playid:10001,voice:汪汪汪,用旺旺唤醒我。}
//{playid:10002,voice:我去玩了,用旺旺唤醒我}SSD1306 ssd1306(128,64,0,1);
/*描述该功能...
*/
void ASR_CODE(){switch (snid) {case 0:ssd1306.clear((0));ssd1306.set_cursor(0,0);ssd1306.draw_hanzi_12("有什么事请吩咐");ssd1306.fill_circle(86,44,10,(1));ssd1306.fill_circle(40,44,10,(1));ssd1306.display();break;case 1:ssd1306.clear((0));ssd1306.set_cursor(0,0);ssd1306.draw_hanzi_12("打开灯光");ssd1306.display();break;case 2:ssd1306.clear((0));ssd1306.set_cursor(0,0);ssd1306.draw_hanzi_12("关闭灯光");ssd1306.display();break;case 3:ssd1306.clear((0));ssd1306.draw_rectangle(44,22,84,42,(1));ssd1306.display();break;case 4:ssd1306.clear((0));ssd1306.draw_circle(64,32,20,(1));ssd1306.display();break;case 5:ssd1306.clear((0));ssd1306.fill_circle(86,44,10,(1));ssd1306.fill_circle(40,44,10,(1));ssd1306.fill_round_rect(76,29,96,59,10,(1));ssd1306.fill_round_rect(30,29,50,59,10,(1));ssd1306.display();servo_3.write(0);servo_2.write(0);servo_5.write(180);servo_6.write(180);break;case 6:ssd1306.clear((0));ssd1306.fill_round_rect(76,39,96,49,5,(1));ssd1306.fill_round_rect(30,39,50,49,5,(1));ssd1306.display();servo_3.write(90);servo_2.write(90);servo_5.write(90);servo_6.write(90);break;case 7:ssd1306.clear((0));ssd1306.draw_line(30,39,45,44,(1));ssd1306.draw_line(30,49,45,44,(1));ssd1306.draw_line(96,39,81,44,(1));ssd1306.draw_line(96,49,81,44,(1));ssd1306.display();servo_3.write(180);servo_2.write(180);servo_5.write(0);servo_6.write(0);break;case 8:vol_set(7);break;case 9:vol_set(3);break;case 10:vol_set(1);break;case 11:servo_2.write(0);servo_3.write(90);servo_5.write(180);servo_6.write(90);ssd1306.clear((0));ssd1306.fill_round_rect(76,29,96,59,10,(1));ssd1306.fill_round_rect(30,29,50,59,10,(1));ssd1306.display();break;case 12:servo_2.write(180);servo_3.write(180);servo_5.write(0);servo_6.write(0);ssd1306.clear((0));ssd1306.fill_round_rect(76,39,96,49,5,(1));ssd1306.fill_round_rect(30,39,50,49,5,(1));ssd1306.display();break;case 13:servo_2.write(90);servo_3.write(90);servo_5.write(90);servo_6.write(90);ssd1306.clear((0));ssd1306.draw_line(30,39,45,44,(1));ssd1306.draw_line(30,49,45,44,(1));ssd1306.draw_line(96,39,81,44,(1));ssd1306.draw_line(96,49,81,44,(1));ssd1306.display();break;case 14:servo_2.write(90);servo_3.write(0);servo_5.write(90);servo_6.write(180);ssd1306.clear((0));ssd1306.draw_line(30,39,50,49,(1));ssd1306.draw_line(30,49,50,39,(1));ssd1306.draw_line(76,39,96,49,(1));ssd1306.draw_line(76,49,96,39,(1));ssd1306.display();break;case 15:servo_2.write(90);servo_3.write(90);servo_5.write(90);servo_6.write(90);break;case 16:servo_2.write(90);servo_3.write(90);servo_5.write(90);servo_6.write(90);break;}}void hardware_init(){vol_set(3);set_wakeup_forever();taskENTER_CRITICAL();ssd1306.begin(0x3c);ssd1306.clear((0));ssd1306.set_cursor(0,0);ssd1306.draw_hanzi_12("欢迎使用旺旺");ssd1306.display();taskEXIT_CRITICAL();vTaskDelete(NULL);
}void setup()
{//{ID:0,keyword:"唤醒词",ASR:"旺旺",ASRTO:"我在"}//{ID:1,keyword:"命令词",ASR:"打开灯光",ASRTO:"好的,马上打开灯光"}//{ID:2,keyword:"命令词",ASR:"关闭灯光",ASRTO:"好的,马上关闭灯光"}//{ID:3,keyword:"命令词",ASR:"正方形",ASRTO:"马上执行"}//{ID:4,keyword:"命令词",ASR:"圆形",ASRTO:"马上执行"}//{ID:5,keyword:"命令词",ASR:"最大角度",ASRTO:"好的"}//{ID:6,keyword:"命令词",ASR:"中等角度",ASRTO:"好的"}//{ID:7,keyword:"命令词",ASR:"最小角度",ASRTO:"好的"}//{ID:8,keyword:"命令词",ASR:"大声一点",ASRTO:"好的"}//{ID:9,keyword:"命令词",ASR:"小声一点",ASRTO:"好的"}//{ID:10,keyword:"命令词",ASR:"最小音量",ASRTO:"好的"}//{ID:11,keyword:"命令词",ASR:"坐下",ASRTO:"我已经坐下了,主人"}//{ID:12,keyword:"命令词",ASR:"卧倒",ASRTO:"我已经 卧倒了,主人"}//{ID:13,keyword:"命令词",ASR:"起立",ASRTO:"我已经站立了,主人"}//{ID:14,keyword:"命令词",ASR:"趴下",ASRTO:"我已经趴下了,主人"}//{ID:15,keyword:"命令词",ASR:"打招呼",ASRTO:"你好"}//{ID:16,keyword:"命令词",ASR:"走路",ASRTO:"好的"}//{ID:17,keyword:"命令词",ASR:"生气",ASRTO:"好的"}setPinFun(3,SECOND_FUNCTION);setPinFun(2,SECOND_FUNCTION);setPinFun(5,SECOND_FUNCTION);setPinFun(6,SECOND_FUNCTION);servo_3.attach(3);servo_2.attach(2);servo_5.attach(5);servo_6.attach(6);
}