HM-10 和 Arduino - 发送没有以代码结尾的行的 AT 命令 [英] HM-10 and Arduino - Sending AT commands with no line ending from code

查看:31
本文介绍了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())

推荐答案

确保在串行监视器选项中没有设置 NL&CR.

Make sure you set noth NL&CR in the serial monitor options.

这篇关于HM-10 和 Arduino - 发送没有以代码结尾的行的 AT 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆