본문 바로가기

코딩 놀이

arduino 와 esp32 bluetooth(5)

ESP32-S 보드는 wifi, BT 두 종류의 통신을 할 수 있습니다. 아래 소스는 부르투스 통신을 해봅니다.

* 컴파일이 끝나고 업로딩 시작될때 오른쪽 버튼을 터치해줍니다.

 
#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!");

}

void loop() {

  if (Serial.available()) {

    SerialBT.write(Serial.read());

  }

  if (SerialBT.available()) {

    Serial.write(SerialBT.read());

  }

  delay(20);


}
 
 
폰에서 페어링된 부르투스 장치들입니다.
ESP32test 장치명이 등록되었습니다.

 시리얼 통신으로 보낸 문자들을 수신문입니다.