LoginSignup
12
10

More than 5 years have passed since last update.

ESP32+micropythonでBLEを動かしてみた

Posted at

MicroPython Advent Calender 18日目です。

今日はESP32+micropythonでBLEを試してみました。

ESP8266とESP32の大きな違いはBLE機能が搭載していることです。
micropythonでも動かしてみたいものですが、残念ながら公式で配布されている
ファームはBLEに対応していません。

今月号のInterfaceでBLEを動作させる記事が書かれていますがビルドが必要となり
そこそこ大変です。

気軽にできないかと模索してみてPycom(Wipy)のファームを書き込んだESP32-devkit
でBLEの動作が確認できました。
Pycom(Wipy)のファームの書き込み方法は14日目の記事をご確認ください。

ファームを書いたらPycomのドキュメントにあったsampleを動かしてみました。

from network import Bluetooth

bluetooth = Bluetooth()
bluetooth.set_advertisement(name='ESP32', service_uuid=b'1234567890123456')

def conn_cb (bt_o):
    events = bt_o.events()   # this method returns the flags and clears the internal registry
    if events & Bluetooth.CLIENT_CONNECTED:
        print("Client connected")
    elif events & Bluetooth.CLIENT_DISCONNECTED:
        print("Client disconnected")

def main():
    bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
    bluetooth.advertise(True)

このコードを転送して実行すると、、、

iphoneでESP32が出てきました。

IMG_0801.PNG

ESP32をタッチすると接続しに行くので、CLIENT_CONNECTEDが検出されました。
画面を戻るとCLIENT_DISCONNECTEDになりました。

2017-12-18_00h16_14.png

非常に簡単な動作確認ではありますが、Pycom(Wipy)のファームであればBLEが
動作するようです!

次は文字のやりとりに挑戦です。

12
10
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
12
10