Simple BluetoothSerial to Serial Communication in ESP32.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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