繁体   English   中英

ESP32 在与 MIT App Inventor 2 交互时停止一切

[英]ESP32 stops everything when interacting with MIT App inventor 2

现在制作一个通过经典蓝牙与 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);
  }

}

应用程序代码的图像 1

图 2

3

4

5

6

线

  if (SerialBT.available) 

应该

  if (SerialBT.available())

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM