首页 文章

无法从HM10读取消息,写作有效 . (通过蓝牙接收和发送数据)

提问于
浏览
1

我目前正在尝试创建使用蓝牙通信(HM10)的基于Arduino的设备 . 我已经通过SoftwareSerial.h将HM10连接到arduino,我通过USB将Arduino连接到PC,我使用串行监视器在板和PC之间进行通信 .

想法很简单:电路板应该只是简单地从串行连接“A”读取消息,然后通过另一个串行连接“B”传递给HM 10. HM10然后通过蓝牙将消息发送到连接的设备 . 它也应该通过HM10的串行连接“B”接收消息并通过串行连接“A”传递给我的PC

在我的移动设备上,我正在使用MSMBle应用程序通过蓝牙连接到HM10并与之通信 .

将arduino连接到电脑后,打开串口显示器并通过此应用程序将手机连接到HM10我可以通过串口显示器从我的电脑发送ASCII文本到arduino,我的手机确实接收到它,我在手机上看到它 . 但是当我通过蓝牙向HM10发送一些消息时,arduino没有收到它 .

HM10确实接收到它:如果我将HM10直接连接到我的PC,我可以使用串行监视器接收和发送消息 . 因此HM10正在接收消息,并通过串行(TR,TX)传递给Arduino,但Arduino由于某种原因没有读取它 .

我正在使用本教程:enter link description here

这是代码:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8, 9); // RX, TX  
// Connect HM10      Arduino Uno
//     Pin 1/TXD          Pin 7
//     Pin 2/RXD          Pin 8

void setup() {  
  Serial.begin(9600);
  // If the baudrate of the HM-10 module has been updated,
  // you may need to change 9600 by another value
  // Once you have found the correct baudrate,
  // you can update it using AT+BAUDx command 
  // e.g. AT+BAUD0 for 9600 bauds
  mySerial.begin(9600);
  mySerial.print("AT+NAMEnazwak2");
  Serial.print("serial_ok");
}

void loop() {  
  //Serial.print("test");
  char c;
  if (Serial.available()) {

    c = Serial.read();

    mySerial.print(c);
  }
  if (mySerial.available()) {
    c = mySerial.read();
    Serial.print("ok");
    Serial.print(c);    
  }
}

请帮帮我,我做错了什么?

1 回答

  • 0

    这只是一个奇怪的硬件问题 . 在其他板上运行良好

相关问题