LoginSignup
4
5

More than 5 years have passed since last update.

[メモ]RedBearLab:BLE NanoでmbedとArduinoで、Lチカ

Last updated at Posted at 2016-02-04

BLE Nano http://redbearlab.com/blenano-new

環境

  • Windows7 64bit
  • BLE Nano (V1.5)
  • MK20 USB Board

準備

  1. mbed.orgにアカウントを作っておく。
  2. まずは、はんだづけ。 http://redbearlab.com/getting-started-nrf51822/
    USBボードのほうが、ピンおおい。BLENanoを挿すとき注意。アンテナがUSBプラグの反対。アンテナ側に寄せる。USBボードのUSBプラグ側のピンがあまる。
  3. Windowsは、mbed Windows serial port driver をインストールする。
    https://developer.mbed.org/handbook/Windows-serial-configuration#1-download-the-mbed-windows-serial-port
    "Download latest driver"から入手、インストール(mbedWinSerial_16466.exe, 2016年2月4日時点)
  4. USBボードをPCにさすと、USBマスストレージドライブとして、MBEDというドライブが現れる。あと、COMポートが増えている。
  5. MBEDドライブ内のmbed.htmをブラウザで開いて、"RedBearLab BLE Nano"を使用するプラットフォームとして登録する
    => "Platform 'RedBearLab BLE Nano' is now added to your account!"ってメッセージが出る
  6. MBEDというところに、プログラムのファイル(HEX形式)をコピーすると、フラッシュに焼いてくれて、実行される模様。
    USBボードのボタンは、RESETボタン。

mbedでLチカ

  1. https://developer.mbed.org/ => 右上の "Compiler"
  2. 右上のほうのプラットフォーム選択で、"RedBearLab BLE Nano"を選ぶ。
  3. インポート -- インポートのメニュー
    a. mbed_blinkyを[検索]。作成者Team mbedのをクリックして、[インポート]ボタンを押す
    b. Import Programで、Import as Program。Update all libraries to the latest revisionにチェックを入れて、[Import]をおす。
  4. main.cpp に、printf("Hello BLE Nano!\r\n");を追加してみる。

    main.cpp
    #include "mbed.h"
    
    DigitalOut myled(LED1);
    
    int main(){
        printf("Hello BLE Nano!\r\n");
        while(1) {
            myled = 1;
            wait(0.2);
            myled = 0;
            wait(0.2);
        }
    }
    
  5. [コンパイル]を押す

  6. HEX ファイルをダウンロードして、"MBED"ドライブにコピーする (直接、MBEDドライブにダウンロードしてもいけた)

  7. LEDがちかちかする。LEDは、ウラにあるよ。

  8. Terminal起動
    (Teratermで、ALT+N、Serialで、COMxx: mbed Serial Port を選んで、[OK], ALT+S,Eで、9600bps-8bit-Parity:none-1bit-FLowCtl:none)

  9. USBボードのボタンを押す。
    =>BLE Nanoが再起動して、TerminalにHello BLE Nano!画表示される

ArduinoでLチカ

  • BLE Nanoにbootloaderを焼く。

    https://github.com/RedBearLab/nRF51822-Arduinoから、[Download ZIP]で取得して、bootloader/bootloader.hexを、MBEDドライブに放り込む

  • Arduino IDE側(1.6.7使用)

    1. File > Preferences > Additional Board Manager URLsに以下を追加
      https://redbearlab.github.io/arduino/package_redbearlab_index.json
    2. Tools > Boards:~~~ > Boards Manager
    3. Boards Managerで、nRF51822を検索
      > RedBearLab nRF51822 Boards (32-bits ARM Cortex-M0) by RedBearLab
      を選択してインストール
    4. Tools > Boards:~~~ > BLE Nano(V1.5 32KB)を選択
    5. Tools > Ports から、USBボード挿して現れたポートを選択
  • Lチカサンプル

    1. Arduino IDE > File > Examples > 01.Basics > Blink
    2. Upload(CTRL+U)すると、ビルドして、アップロードされて、プログラムが実行される。(1秒ごとに点灯消灯くりかえし)
    3. delay(500);にかえて様子を見てみる。

疑問点?

  • アップロードごとに全ビルドされて、時間がかかる
  • リセットすると、プログラムは保存されない?
4
5
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
4
5