LoginSignup
0
0

More than 1 year has passed since last update.

micro:bitとWindowsをUSB経由でシリアル通信させる

Last updated at Posted at 2019-12-06

Windows側の準備

ドライバの取得

以下のURLから最新のドライバをダウンロードする。
https://os.mbed.com/handbook/Windows-serial-configuration

download.png

ドライバのインストール

ダウンロードしたmbedWinSerial_16466.exeを実行。
install.png

インストールに成功すると「The driver was installed successfully」というメッセージダイアログが表示されるので[Finish]釦を押下して終了します。

COMポートの確認

デバイスマネージャを開いて「ポート(COMとLPT)」のところに「mbed Serial Port(COM4)」のような表示があれば成功です。
※COMポートの番号は環境により変わってきます。
Device.png

接続テスト

ターミナル(今回はTeraTerm)を起動して、以下のような設定をします。
com.png

micro:bit側のスクリプトを作ります。
今回はA釦を押下するとシリアルに"Push A"を書き出し、B釦を押下するとシリアルに"Push B"と書き出すスクリプトとなります。
microbit.png

JavaScriptで見るとこんな感じ。


input.onButtonPressed(Button.A, function () {
    serial.writeLine("Push A")
})
input.onButtonPressed(Button.B, function () {
    serial.writeLine("Push B")
})
serial.redirect(
SerialPin.USB_TX,
SerialPin.USB_RX,
BaudRate.BaudRate115200
)

作成したプログラムをmicro:bitにダウンロードしてどうさせ、A釦かB釦を押下するとPC上のターミナルに"Push A"や"Pushu B"が表示されます。
run.png

おまけ

温度とか明るさ、加速度センサーは簡単に取得できますが、方角(コンパス)を取得しようとするとmaicro:bitの調整が必要になります。
micro:bitのLEDで「Tilt to fill screen」と評されたら、micro:bitを画面の中心にある点が全体を埋め尽くすまでいろんな方向へ傾けてください。
そのあとに、実際のスクリプトが実行されます。

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