6549| 3
|
[已解决] DFRobot Speech Synthesizer Bee语音合成模块只能在串口0使用的问题 |
如题,新人DFRobot Speech Synthesizer Bee语音合成模块Arduino xbee兼容 MEGA2560的板子加 DFRobot MEGA传感器扩展板V2.3 (兼容Arduino mega) 使用自带的例子,在XBee1口上可以正常发声,但在别的串口则没有反应。把库里的Serial改为Serial2也不行,很疑惑,希望可以帮忙解决这个问题。 改后的库文件: #include <inttypes.h> #include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "Syn6288.h" #include <stdio.h> #include <Arduino.h> uint8_t head[5] = {0xfd,0x00,0x00,0x01,0x00};//合成播放命令 uint8_t sound[5] = {0xfd,0x00,0x00,0x01,0x01};//合成提示音 uint16_t boud[5]={0xFD,0x00,0x03,0x31,0x00}; //设置波特率 /*发送文本合成命令,music为背景音乐设置*/ void Syn6288::play(uint8_t *text,uint8_t TEXTLEN,uint8_t music) { pi=0; delay(100); head[2]=TEXTLEN+3; switch(music) { case 0: head[4]=0x01;break; case 1: head[4]=0x09;break; case 2: head[4]=0x11;break; case 3: head[4]=0x19;break; case 4: head[4]=0x21;break; case 5: head[4]=0x29;break; case 6: head[4]=0x31;break; case 7: head[4]=0x39;break; case 8: head[4]=0x41;break; case 9: head[4]=0x49;break; case 10: head[4]=0x51;break; case 11: head[4]=0x59;break; case 12: head[4]=0x61;break; case 13: head[4]=0x69;break; case 14: head[4]=0x71;break; case 15: head[4]=0x79;break; } for(int i=0;i<5;i++) { pi^=head; Serial2.write(head); delay(2); } for(int j=0;j<TEXTLEN;j++) { pi^=text[j]; Serial2.write(text[j]); delay(2); } Serial2.write(pi); delay(300*TEXTLEN); } void Syn6288::Slaveboudset(uint16_t boudr) //波特率设置 { uint8_t p; p=0; switch(boudr) { case 9600: boud[4]=0x00; break; case 19200: boud[4]=0x01; break; } for(int z=0;z<HEADLEN;z++) { p^=boud[z]; Serial2.write(boud[z]); delay(2); } Serial2.write(p); p=0; for(int z=0;z<HEADLEN;z++) { p^=boud[z]; Serial2.write(boud[z]); delay(2); } Serial2.write(p); delay(200); } 也不知道是不是这样改,希望能帮忙解决这个问题 |
本帖最后由 Youyou 于 2014-2-13 11:20 编辑 你好,目测你的程序里面: for(int i=0;i<5;i++) { pi^=head; Serial2.write(head); delay(2); } 这段有问题,应该是pi^=head;Serial2.write(head);如果用你的语句,head不是数组,会导致不能正确发送命令,导致不能发声。 我用的代码如下,你参考下,COM2口,实测没有问题。 Syn6288.cpp文件: #include <inttypes.h> #include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #include "Syn6288.h" #include <stdio.h> #include <arduino.h> uint8_t head[5] = {0xfd,0x00,0x00,0x01,0x00};//合成播放命令 uint8_t sound[5] = {0xfd,0x00,0x00,0x01,0x01};//合成提示音 uint16_t boud[5]={0xFD,0x00,0x03,0x31,0x00}; //设置波特率 /*发送文本合成命令,music为背景音乐设置*/ void Syn6288::play(uint8_t *text,uint8_t TEXTLEN,uint8_t music) { pi=0; delay(100); head[2]=TEXTLEN+3; switch(music) { case 0: head[4]=0x01;break; case 1: head[4]=0x09;break; case 2: head[4]=0x11;break; case 3: head[4]=0x19;break; case 4: head[4]=0x21;break; case 5: head[4]=0x29;break; case 6: head[4]=0x31;break; case 7: head[4]=0x39;break; case 8: head[4]=0x41;break; case 9: head[4]=0x49;break; case 10: head[4]=0x51;break; case 11: head[4]=0x59;break; case 12: head[4]=0x61;break; case 13: head[4]=0x69;break; case 14: head[4]=0x71;break; case 15: head[4]=0x79;break; } for(int i=0;i<5;i++) { pi^=head; Serial2.write(head); delay(2); } for(int j=0;j<TEXTLEN;j++) { pi^=text[j]; Serial2.write(text[j]); delay(2); } Serial2.write(pi); delay(300*TEXTLEN); } void Syn6288::Slaveboudset(uint16_t boudr) //波特率设置 { uint8_t p; p=0; switch(boudr) { case 9600: boud[4]=0x00; break; case 19200: boud[4]=0x01; break; } for(int z=0;z<HEADLEN;z++) { p^=boud[z]; Serial2.write(boud[z]); delay(2); } Serial2.write(p); p=0; for(int z=0;z<HEADLEN;z++) { p^=boud[z]; Serial2.write(boud[z]); delay(2); } Serial2.write(p); delay(200); } Arduino IDE代码: #include "Syn6288.h" Syn6288 syn; uint8_t text1[]={0xB3,0xC9,0xB6,0xBC,0xBC,0xAB,0xC8,0xA4,0xBF,0xC6,0xBC,0xBC,0xD3,0xD0,0xCF,0xDE,0xB9,0xAB,0xCB,0xBE}; //成都极趣科技有限公司 void setup() { Serial2.begin(9600); syn.Slaveboudset(9600); } void loop() { syn.play(text1,sizeof(text1),1);//播放文本1,选择背景音乐1 } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed