記事一覧

M5Stack Bluetooth Low Energy (BLE) Test

M5Stack Bluetooth Low Energy (BLE) Test



Hello everyone! I’m RoboTakao.

I also wanted to control the robot with wireless, so this time I tried the Bluetooth Low Energy (BLE) test with M5Stack.

BLE has various terms and it is necessary to understand the concept, but this time it is operation confirmation with sample sketch.

If you have installed the library of M5Stack with Arduino IDE you can open BLE related sample sketch from ESP32 BLE Arduino.

Let's use a sample sketch called BLE_server for experiment.

File -> Sketch example -> ESP32 BLE Arduino -> BLE_server

M5Stack_BLE01.png

Compile and write it.

As you start sketching and look at the serial monitor you can see that it is moving.

M5Stack_BLE02.png

For example here you will check the application called LightBlue on your smartphone.

You can check the peripheral called MyESP32.

M5Stack_BLE03.png

Click to connect.

Characteristic was also confirmed.

M5Stack_BLE04.png



Sample sketch


/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
Ported to Arduino ESP32 by Evandro Copercini
*/

#include
#include
#include

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");

BLEDevice::init("MyESP32");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);

pCharacteristic->setValue("Hello World says Neil");
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}


1) M5Stack Arduino IDE initial setting (macOS)
2) M5Stack I tried Arduino IDE sample sketches
3) M5Stack I treid Avatar(Arduino IDE)
4) M5Stack LED Blink
5) M5Stack Servo operating
6) M5Stack X 16ch Servo Driver PCA9685

スポンサードリンク

コメント

コメントの投稿

非公開コメント

プロフィール

RoboTakao

Author:RoboTakao
みなさんご訪問ありがとうございます。ロボット作りたいけどお小遣いそんなにないし、簡単でローコストでロボットを作るための私のプロジェクトを紹介します。

ウェブサイトもありますのでそちらもよろしくお願いします。
http://robotakao.jp/

スポンサーリンク