【问题标题】:How do I pair an ESP32 and a HC-05 module?如何配对 ESP32 和 HC-05 模块?
【发布时间】:2022-06-16 05:15:36
【问题描述】:

我尝试了很多次,但任何解决方案都不起作用。 我使用 ESP32 作为控制,HC-05 作为 Arduino UNO 的 anthena。 我让 HC-05 可以读取它收到的每个字符串,但我无法将 ESP32 (DevKit v1) 与它链接。这是我的代码。我尝试使用地址或名称,但它们都不起作用,只返回“连接失败”。但我能找到它。

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
String MACadd = "00:19:08:35:31:63"; // HC-05 Address: 19:8:353163 (Given by the HC-05)
uint8_t address[6]  = {0x00, 0x19, 0x08, 0x35, 0x31, 0x63};
String name = "AUTO"; // The name I put, I can find this by my mobile phone
char *pin = "1234"; //<- standard pin would be provided by default
bool connected;

void setup() 
{
  Serial.begin(115200);
  SerialBT.begin("ESP32_Control", true); 
  SerialBT.setPin(pin);
  Serial.println("The device started in master mode, make sure remote BT device is on!"); 
  connected = SerialBT.connect(name);

  if(connected) 
    Serial.println("Connected Succesfully!");
  else
    while(!SerialBT.connected(10000))
      Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app."); 

  if (SerialBT.disconnect()) // disconnect() may take upto 10 secs max
    Serial.println("Disconnected Succesfully!");

  SerialBT.connect(); // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
}

void loop()
{
  if (Serial.available())
    SerialBT.write(Serial.read());

  if (SerialBT.available())
    Serial.write(SerialBT.read());

  delay(20);
}

【问题讨论】:

    标签: arduino-uno esp32 arduino-esp32 hc-05


    【解决方案1】:

    同样的问题,有解决办法吗?

    【讨论】:

    猜你喜欢
    • 2022-01-22
    • 2020-11-09
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 2018-02-19
    相关资源
    最近更新 更多