Hello, I've recently purchased an ESP-WROOM-32 to work on a wirelessly controlled robot. I wish to establish a classic bluetooth connection between my Windows 11-configured laptop and the ESP32 board. To do so, I've uploaded the following code onto my board via the PlatformIO plugin on VScode:
#include <Arduino.h>
#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("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(2,OUTPUT);
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
digitalWrite(2,HIGH);
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}
The Serial Monitor responds how it is intended to, i.e when I press the "EN" button on the ESP32, I receive an output "The device started, now you can pair it with bluetooth!".
Now, when I pair this with my Windows 11 laptop, for a brief moment (about 3 seconds), before it automatically drops and displays "Not connected".
How do I fix this bug?