本文介绍了HM-10和Arduino-发送不带代码结尾的AT命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将HM-10与Arduino Uno或Nano一起使用.我无法弄清楚如何发送AT命令并阅读回复.这些命令可通过串行监视器运行,而不能通过代码运行.
I need to use HM-10 with Arduino Uno or Nano.I'm not able to figure out how to send AT commands and read the reply.The commands work from serial monitor, but not from code.
这是我到目前为止尝试过的:
Here's what I've tried so far:
#include <SoftwareSerial.h>
SoftwareSerial blueToothSerial(0,1); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
Serial.println("Serial began");
blueToothSerial.begin(9600);
delay(2000);
}
void loop()
{
Serial.println("looping...");
blueToothSerial.print("AT+DISC?");
delay(5000);
if (blueToothSerial.available())
{
Serial.println("bluetooth serial available");
Serial.write(blueToothSerial.read());
}
}
但是,我看不到任何回复,我感觉命令没有触发.执行不会进入if(blueToothSerial.available())
However, I'm not able to read any reply, I feel the command is not firing. The execution doesnt go inside if(blueToothSerial.available())
推荐答案
确保在串行监视器选项中设置noth NL& CR.
Make sure you set noth NL&CR in the serial monitor options.
这篇关于HM-10和Arduino-发送不带代码结尾的AT命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!