LoginSignup
14
7

More than 3 years have passed since last update.

【micro:bit 2019】micro:bit で BLE + UART による文字列の送受信(29記事目)

Last updated at Posted at 2019-12-30

この記事は 12/30 に執筆して、後から 「micro:bit Advent Calendar 2019 - Qiita」の 12日目 へと登録した記事です。

今年のアドベントカレンダー用に書いた記事の 29記事目で、micro:bit Advent Calendar に登録した記事としては 10記事目になります。

はじめに

micro:bit で BLE + UART を使うために調査や通信テストを試した話の記事です。

公式の情報を見てみる

デバイスの準備

micro:bit の BLE通信周りの情報をググっていてでてきた、以下のページを見てみます。

●micro:bit Bluetooth Low Energy serial UART : Support
 https://support.microbit.org/support/solutions/articles/19000062330-using-the-micro-bit-bluetooth-low-energy-uart-serial-over-bluetooth-

ページ内を読み進めて行くと、サンプルプログラムへのリンクがありました。
(※「Here is an example program that uses the uart.」と書かれた部分です)

サンプルを参照し、以下のようなプログラムを準備しました。
Microsoft_MakeCode_for_micro_bit_BLE_UART_MC.jpg

そして、さらに下へ進むと、以下のような記載がありました。

This example program can be used with any UART app that follows the Nordic UART protocol, but the example above was tested on Android with Serial Bluetooth Terminal.

上記の micro:bit のプログラムのサンプルは、Nordic UART プロトコルを使ったどんなアプリとも通信できるものの、動作テストは以下の Androidアプリで行った、とのこと。

●Serial Bluetooth Terminal - Google Play のアプリ
 https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal

Serial_Bluetooth_Terminal_-_Google_Play_のアプリ.jpg

こちらを実際に試してみます。

端末を BLE接続

micro:bit は上記のプログラムを書き込んでおくだけで、とりあえず OK です。

そして、上記の Androidアプリがインストールされた端末を準備します。
ここから Androidアプリを以下の手順で操作していきます。
図1-A.png
図1-B.png
上記の手順4)の「※」の部分で位置情報利用の許可を求めるダイアログが表示された場合、許可するようにしてください。詳細は省きますが、これは BLE利用のために必要となります。

上記で、端末が無線接続された状態になりました。

文字列の送受信を試す

以下が、実際に動作させた際の様子です。
最初は、スマホアプリから「ble」という文字列を送信しており、micro:bit側は受信した文字列を LED上に表示しています。
またその後の動作は、micro:bit側で Aボタンを押すと、「BLE UART!」という文字列がスマホアプリへ送信される、というものです。

想定通りの挙動を確認できました。

おわりに

今回、参照したページから 2つほど技術面の詳細情報が書かれたと思われるページへのリンクがあrり、それらは別途、見てみようと思います。

14
7
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
14
7