【问题标题】:Arduino Nano + HC-05 : AT+INQ gives corrupted outputArduino Nano + HC-05:AT+INQ 输出损坏
【发布时间】:2015-10-23 06:53:54
【问题描述】:

我正在使用 Arduino Nano + HC-05 蓝牙 + ENC28J60 以太网模块。使用EtherCard.h from JeeLabs.net。我在从蓝牙模块读取时遇到了一些问题。

蓝牙模块设置为 AT 模式(用夹子按住按钮 / 将 5V 电压输入引脚 34。两种方式都尝试过)

这是我的配置:

ROLE=1
CMODE=1
INQM=1,5,23

这里是loop()及其相关函数

static uint32_t timer;

void loop () {
  ether.packetLoop(ether.packetReceive());

  if (millis() >= timer) {
    if (BTScan()) {
      sendRequest(); // Send HTTP POST with `deviceBT` using EtherCard
    }
  }
}

String deviceBT = "";

bool BTScan() {
  bluetooth.listen();

  if (bluetooth.available()) {
    deviceBT = "";

    String readstr = bluetooth.readString();
    readstr.trim();

    if (readstr == PSTR("ERROR:(16)")) {
      Serial.println(F("BLUETOOTH NOT INITIALIZED\nBLUETOOTH INIT:"));
      bluetooth.println(F("AT+INIT"));
      if (bluetooth.find(F("OK"))) Serial.println(F("OK"));
    } else if (readstr.length() > 0) {
      for (int i = 0; i < 2; i++) {
        digitalWrite(LED_PIN, HIGH); delay(100);
        digitalWrite(LED_PIN, LOW);  delay(200);
      }
      if (readstr.indexOf(F("+INQ:")) > -1) {
        Serial.println(F("BLUETOOTH FOUND:"));
        Serial.println(readstr);
        deviceBT = readstr;
        return true;
      }
    }
  }

  Serial.println(F("BLUETOOTH INQUIRE START:"));
  bluetooth.println(F("AT+INQ"));
  timer = millis() + 5000;

  return false;
}

假设我的蓝牙 ID 是 303A:64:9A65CD 程序会通过串口响应。

BLUETOOTH INQUIRE START:
BLUETOOTH FOUND:
OK
+INQ:303A:è4:9A<5CD,2010C,7FFC

// sometimes
BLUETOOTH FOUND:
gK
+INQ:303A:6::9A85F¢,2010C,7FFF

// some other time
BLUETOOTH FOUND:
+INQ:303A:64:9C<5FD,20˜0C,7FFF

蓝牙在没有以太网部分的另一个程序中工作正常,物理安装都是相同的。

我所有的草图都使用 17,664 字节 (57%),全局变量使用 984 字节 (48%)

请帮忙。我的代码有什么问题吗?

【问题讨论】:

    标签: bluetooth arduino at-command


    【解决方案1】:

    我想我找到了一个解决方法,或者这就是解决方案。

    loop() 函数中,我在调用ether.packetLoop() 之后添加了500ms 的一点延迟,它似乎可以工作。

    不确定是否有任何副作用,因为我是这种编程的绝对新手。

    void loop () {
      ether.packetLoop(ether.packetReceive());
    
      delay(500); // Add 500ms delay to the loop
    
      if (millis() >= timer) {
        if (BTScan()) {
          sendRequest(); // Send HTTP POST with `deviceBT` using EtherCard
        }
      }
    }
    

    如果我不是,请纠正我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多