0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

BLE Serialを試す。

0
Last updated at Posted at 2026-03-01

はじめに

ワイヤレスで簡単にSerialみたいなことができるライブラリを探した。
使いやすいアプリはなさそうなので作成した。

ハードはM5StickS3

M5StickS3のExamplesのSerialToBTSerialはエラーが出ます。
image.png
ESP32S3はサポート外なのだろうか。。。

使用したArduinoライブラリ

検証

良さそうprintf(文字列)が使える。

ダメなところ

BLE Termが落ちる(あまりダメではないけど)
サンプルが長い(シンプルではない?)

参考(サンプルをシンプルにしてM5Unifiedを加えています)

#include<M5Unified.h>
#include <BleSerial.h>
#include "BleBufferedSerial.h"

BleBufferedSerial SerialBT1;
int serial1Count = 0;

void setup() {
	 M5.begin();
	 M5.Power.setExtOutput(true); // EXT_5V OUTPUT
  
	Serial.begin(115200);
	SerialBT1.begin("TEST_BT");
}

void loop() {
		SerialBT1.printf("Hello Serial1 %d\r\n",serial1Count++);
        SerialBT1.flush();
		delay(5);
}

SerialBT1.flush();をつけないと適当なタイミングで送信されているみたい。(2026/3/08追記)

iOS,iPad アプリ

iOS,iPad用のアプリを公開しました。
https://apps.apple.com/jp/app/easyarduinobleterm/id6759859872

画像

Windows(x64)版、Android版も公開しました。

Web版も公開しました。

Chrome、Edgeで動作します。
https://nw-lab.github.io/EasyArduinoBleTerm/

確認したArduinoのコード

#include <BleSerial.h>

BleSerial ble;

void setup() {
  Serial.begin(115200);
  // アドバタイズ名を設定(アプリのスキャン画面に表示されます)
  ble.begin("MyESP32Device");
}

void loop() {
  static float theta = 0;
  theta += 2 * 3.14 / 360;
  // カンマ区切りでデータを送信(プロッターで表示可能)
  float sensor1 = sin(theta);
  float sensor2 = cos(theta);
  ble.printf("%.3f,%.3f\n", sensor1, sensor2);
  ble.flush();

  // BLEからの受信データをシリアルに転送
  while (ble.available()) {
    Serial.write(ble.read());
  }

  delay(10);  // 100Hz
}

※Serialを使用しているのでPCとつないでシリアルを受信しないと止まった感じになります。!

他に試したライブラリ

Serial_BLE

image.png
https://github.com/senseshift/arduino-ble-serial

検証

BLE Termで動作確認
https://apps.apple.com/jp/app/ble-term/id6748893821
よさそう。

ダメな点

printlnが使えなさそう。
write(1バイトづつ)だけ

参考(ソース Exsmple+m5unified仕様想定)

#include<M5Unified.h>
#include <BLESerial.h>
String device_name = "ESP32-BLE-Slave";

BLESerial SerialBLE;

void setup() {
    M5.begin();
     M5.Power.setExtOutput(true); // EXT_5V OUTPUT
  
    Serial.begin(9600);
    SerialBLE.begin(device_name);
}

void loop() {
    if (Serial.available()) {
        SerialBLE.write(Serial.read());
        SerialBLE.flush();
    }
    if (SerialBLE.available()) {
        Serial.write(SerialBLE.read());
    }
}

HardwareBLESerial

image.png
https://github.com/Uberi/Arduino-HardwareBLESerial

ダメなところ

アバタイズ名は見えるけどconnect失敗する。もともとArduinoBLE用らしい?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?