【问题标题】:ESP32 stops everything when interacting with MIT App inventor 2ESP32 在与 MIT App Inventor 2 交互时停止一切
【发布时间】:2021-05-30 11:44:03
【问题描述】:

现在制作一个通过经典蓝牙与 ESP32 交互的应用。我正在读取霍尔传感器并在其值高于 0 时发送 0,在低于 0 时发送 1。现在,当我在 ai2 中注册该 1 并且因此在应用程序中发生一些事情时,ESP32 发生故障或其他什么。我停止从串行监视器中的传感器获取读数,并且蓝牙连接停止。似乎整个 esp 都停在了原地。我也没有向 ESP32 发送任何数据,只是从中接收数据。 esp代码超级小,但app代码不多。 解决此问题的唯一方法是重置 esp,这在我的用例中并不可行。有什么办法解决这个问题?

    #include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("Sport Spel"); //Bluetooth device name
}

void loop() {
  Serial.println(hallRead());
  if (SerialBT.available) 
  {
    if (hallRead() < 0)
    {
      SerialBT.write('1');
    }
    else
    {
      SerialBT.write('0');
    }
    delay(20);
  }

}

Image 1 of app code

Image 2

3

4

5

6

【问题讨论】:

  • 请不要链接到 StackOverflow 问题中的图片。链接往往会停止工作,这使得问题毫无意义。代码图片也不能搜索,文字可以。而且很多人在阅读图片中的代码时有困难。

标签: android arduino bluetooth esp32


【解决方案1】:

线

  if (SerialBT.available) 

应该是

  if (SerialBT.available())

正如您在问题中所写,您正在测试SerialBT 对象上名为available 的方法的地址是否为真,它总是如此。您想实际调用该方法,因此您需要包含括号才能调用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多