Skip to content

Instantly share code, notes, and snippets.

@elktros
Created March 19, 2021 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/bb7b3bf4d59bbcab6f4c1f9558fd8721 to your computer and use it in GitHub Desktop.
Save elktros/bb7b3bf4d59bbcab6f4c1f9558fd8721 to your computer and use it in GitHub Desktop.
Simple BluetoothSerial to Serial Communication in ESP32.
#include "BluetoothSerial.h"
/* Check if Bluetooth configurations are enabled in the SDK */
/* If not, then you have to recompile the SDK */
#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);
/* If no name is given, default 'ESP32' is applied */
/* If you want to give your own name to ESP32 Bluetooth device, then */
/* specify the name as an argument SerialBT.begin("myESP32Bluetooth"); */
SerialBT.begin();
Serial.println("Bluetooth Started! Ready to pair...");
}
void loop() {
if (Serial.available())
{
SerialBT.write(Serial.read());
}
if (SerialBT.available())
{
Serial.write(SerialBT.read());
}
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment