问题描述
在AT模式下,HC-05的响应(通常)是不可打印的字符,与预期不符。
例如当我发送“ AT \ r \ n”时,我取回字节175,165,134,197(十进制)。并非按预期“确定\ r \ n”。
尝试了很多事情。有时角色会发生变化,但每次尝试都可以重复。
我正在尝试从Arduino硬件串行中继到软件串行。 我尝试了几种波特率,几种引脚对,带或不带分压器。
当前代码使用缓冲区,以防万一出现软件串行时序问题。
我已将“ EN”引脚连接到3v3。 HC-05闪烁约1秒钟,然后闪烁约1秒钟(2秒)
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(8,9); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(38400);
}
#define BUFLEN 64
void loop()
{
int n,k,c;
unsigned char buf[BUFLEN];
// use buffer in case there are problems with software serial trying
// to wait for Serial ops while data incoming.
n=0; // read from HC-05
while ((n<BUFLEN) && BTSerial.available())
buf[n++] = BTSerial.read();
for (k=0; k<n; k++)
{
c = (int)(buf[k]);
Serial.print("BT>");
Serial.print(c);
Serial.print('\t');
Serial.write(c);
Serial.print('\t');
Serial.write(c & 0x7f); // strip parity bit?
Serial.print('\t');
Serial.write(c >> 1); // strip parity bit?
Serial.println();
}
// read from Arduino Serial and send to HC-05
n=0;
while (Serial.available()) // Keep reading from Arduino Serial Monitor and send to HC-05
buf[n++] = Serial.read();
for (k=0; k<n; k++)
{
c = (int)buf[k];
Serial.print('<');
Serial.print(c);
Serial.print('\t');
Serial.println((char)c);
}
for (k=0; k<n; k++)
BTSerial.write((int)(buf[k]));
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)