ESP32のBluetoothを使う

ESP32にはBluetooth機能がついている。ArduinoIDEでプログラムすることで簡単に使えるので使ってみた。マイコンはここで買える。

まずはヘッダーを読み込み、Bluetooth用の変数を用意

1
2
3
#include "BluetoothSerial.h"
 
BluetoothSerial SerialBT;

あとはsetupにBluetoothを使うことを宣言して

1
2
3
void setup() {
  SerialBT.begin("DeviceName");
}

これで通信ができる。

1
2
3
void loop() {
  SerialBT.println("Hello World!");
}

全文

1
2
3
4
5
6
7
8
9
10
11
#include "BluetoothSerial.h"
 
BluetoothSerial SerialBT;
 
void setup() {
  SerialBT.begin("DeviceName");
}
 
void loop() {
  SerialBT.println("Hello World!");
}

コメント

タイトルとURLをコピーしました