• <legend id='LlPfK'><style id='LlPfK'><dir id='LlPfK'><q id='LlPfK'></q></dir></style></legend>
    <tfoot id='LlPfK'></tfoot>

      <bdo id='LlPfK'></bdo><ul id='LlPfK'></ul>

      <i id='LlPfK'><tr id='LlPfK'><dt id='LlPfK'><q id='LlPfK'><span id='LlPfK'><b id='LlPfK'><form id='LlPfK'><ins id='LlPfK'></ins><ul id='LlPfK'></ul><sub id='LlPfK'></sub></form><legend id='LlPfK'></legend><bdo id='LlPfK'><pre id='LlPfK'><center id='LlPfK'></center></pre></bdo></b><th id='LlPfK'></th></span></q></dt></tr></i><div id='LlPfK'><tfoot id='LlPfK'></tfoot><dl id='LlPfK'><fieldset id='LlPfK'></fieldset></dl></div>

    1. <small id='LlPfK'></small><noframes id='LlPfK'>

        Arduino:使用带有蓝牙模块的串口和软件串口

        Arduino: using Serial and Software Serial with bluetooth module(Arduino:使用带有蓝牙模块的串口和软件串口)
        <i id='BqyMW'><tr id='BqyMW'><dt id='BqyMW'><q id='BqyMW'><span id='BqyMW'><b id='BqyMW'><form id='BqyMW'><ins id='BqyMW'></ins><ul id='BqyMW'></ul><sub id='BqyMW'></sub></form><legend id='BqyMW'></legend><bdo id='BqyMW'><pre id='BqyMW'><center id='BqyMW'></center></pre></bdo></b><th id='BqyMW'></th></span></q></dt></tr></i><div id='BqyMW'><tfoot id='BqyMW'></tfoot><dl id='BqyMW'><fieldset id='BqyMW'></fieldset></dl></div>
      1. <small id='BqyMW'></small><noframes id='BqyMW'>

        <tfoot id='BqyMW'></tfoot>

        1. <legend id='BqyMW'><style id='BqyMW'><dir id='BqyMW'><q id='BqyMW'></q></dir></style></legend>

                  <bdo id='BqyMW'></bdo><ul id='BqyMW'></ul>

                    <tbody id='BqyMW'></tbody>
                  本文介绍了Arduino:使用带有蓝牙模块的串口和软件串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的目的是使用 Arduino 建立 PC 和使用 HC-05 蓝牙模块的 Android 设备之间的通信.

                  My purpose is to use Arduino to set up communication between a PC and an Android device using an HC-05 bluetooth module.

                  我使用 PC 和 Arduino(串行监视器)之间的 USB 通信和 SoftwareSerial 连接到 HC-05.

                  I use the USB communication between the PC and the Arduino (Serial Monitor) and a SoftwareSerial to connect to the HC-05.

                  我的问题是从 BT 到 PC 的通信运行良好,但在其他方式下无法按预期工作.从 PC 发送到 BT 时,只有在我关闭 PC 上的串行监视器或重置 Arduino 时,BT 设备才会接收到所有发送的字符.

                  My problem is that the communication works well from BT to the PC, but doesn't work as expected in the other way. When sending from the PC to BT all the characters sent are received by the BT device only when I close the Serial Monitor on the PC or when I reset the Arduino.

                  我已经排除了 BT 模块或 Android 应用程序的问题,因为如果在 Arduino 中实现ECHO"代码(在 Android 中编写并在 Android 中发送)一切正常.

                  I've excluded a problem with the BT Module or the Android application because if in Arduino I implement an "ECHO" code (write in Android and the send in Android) everything works fine.

                  使用下面发布的 Arduino 代码,预期行为是:Arduino 重置-> 发送您好字,串行监视器打开-> 没有任何反应,串行监视器上写入的字符-> BT 上接收到的字符,BT 上写入的字符-> 接收到的字符在串行监视器上,串行监视器关闭-> 没有任何反应.

                  With the Arduino code posted below the expected behaviour is: Arduino reset-> Hello word sent, Serial monitor opened-> nothing happens, character written on serial monitor-> character received on BT, character written on BT-> character received on Serial Monitor, Serial monitor closed-> nothing happens.

                  真正的行为是:Arduino reset-> Hello word sent,串行监视器打开-> BT 上的 2 Hello word 和 PC 上的 1(晚安"),串行监视器上写入的字符-> 无,BT 上写入的字符-> 在串行监视器上收到字符,串行监视器已关闭-> 在串行监视器中收到先前写入的字符 + Hello Word.

                  The real behaviour is: Arduino reset-> Hello word sent, Serial monitor opened-> 2 Hello word on BT and 1 ("goodnight") on PC, character written on serial monitor-> nothing, character written on BT-> character received on Serial Monitor, Serial monitor closed-> previous written character(s) in serial monitor received + Hello Word.

                  我该如何解决这个问题?

                  How can I fix this problem?

                  代码:

                  #include <SoftwareSerial.h>
                  SoftwareSerial mySerial(2, 3); // RX, TX
                  int a=0;
                  char c;
                  char d;
                  void setup() {
                    Serial.begin(9600);
                    Serial.println("Goodnight moon!");
                    mySerial.begin(9600);
                    mySerial.println("Hello, world?");
                  }
                  void loop() {
                    delay(10);
                    if (Serial.available()) {
                      c=Serial.read();
                      delay(10);
                      Serial.write(c);
                    }
                    delay(10);
                    if (mySerial.available()) {
                      d=mySerial.read();
                      delay(10);
                      mySerial.write(d);
                  
                    }
                  }
                  

                  推荐答案

                  此代码适用于我的 Arduino Mini Pro(应该与 UNO 相同)和 HC-05.我将 HC-05 与我的笔记本电脑配对.在与 HC-05 和 Arduino 串行控制台关联的 COM 端口上使用超级终端,我可以双向发送消息.Serial.println 语句按应有的方式显示在超级终端窗口中.

                  This code is working for me on an Arduino Mini Pro (should be the same as UNO) with an HC-05. I have the HC-05 paired with my laptop. Using HyperTerminal on the COM port associated with the HC-05 and the Arduino serial console, I can send messages bidirectionally. The Serial.println statements show up in the Hyperterminal window like they should.

                  #include <SoftwareSerial.h>
                  
                  #define rxPin 8
                  #define txPin 7
                  
                  SoftwareSerial mySerial(rxPin, txPin); // RX, TX
                  char myChar ; 
                  
                  void setup() {
                    Serial.begin(9600);   
                    Serial.println("Goodnight moon!");
                  
                    mySerial.begin(9600);
                    mySerial.println("Hello, world?");
                  }
                  
                  void loop(){
                    while(mySerial.available()){
                      myChar = mySerial.read();
                      Serial.print(myChar);
                    }
                  
                    while(Serial.available()){
                     myChar = Serial.read();
                     mySerial.print(myChar);
                    }
                  }
                  

                  这篇关于Arduino:使用带有蓝牙模块的串口和软件串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  script.sh: line 1: ./gradlew: No such file or directory on Jenkins(script.sh:第 1 行:./gradlew:Jenkins 上没有这样的文件或目录)
                  Access native serial port on Android(在Android上访问本机串口)
                  Android: USB Communication Android lt;-gt; External Device(Android:USB通信Androidlt;-gt;外接设备)
                  Sending commands from a PC to an Android phone - via physical connection (USB, Serial, etc)(从 PC 向 Android 手机发送命令 - 通过物理连接(USB、串行等))
                  Android: RS232 Serial Communication with android device(Android:与安卓设备的RS232串行通信)
                  Use a handheld bluetooth printer with android(使用带有 android 的手持式蓝牙打印机)

                  • <bdo id='gR9eW'></bdo><ul id='gR9eW'></ul>
                    • <legend id='gR9eW'><style id='gR9eW'><dir id='gR9eW'><q id='gR9eW'></q></dir></style></legend>
                          <tbody id='gR9eW'></tbody>

                          <i id='gR9eW'><tr id='gR9eW'><dt id='gR9eW'><q id='gR9eW'><span id='gR9eW'><b id='gR9eW'><form id='gR9eW'><ins id='gR9eW'></ins><ul id='gR9eW'></ul><sub id='gR9eW'></sub></form><legend id='gR9eW'></legend><bdo id='gR9eW'><pre id='gR9eW'><center id='gR9eW'></center></pre></bdo></b><th id='gR9eW'></th></span></q></dt></tr></i><div id='gR9eW'><tfoot id='gR9eW'></tfoot><dl id='gR9eW'><fieldset id='gR9eW'></fieldset></dl></div>

                            <small id='gR9eW'></small><noframes id='gR9eW'>

                          1. <tfoot id='gR9eW'></tfoot>