arduino tank meets bluetooth

30
Arduino Tank meets Bluetooth 増田 智明 @moonmile Moonmile Solutions

Upload: moonmile

Post on 17-Jul-2015

416 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Arduino tank meets bluetooth

Arduino Tank meets

Bluetooth増田智明 @moonmile

Moonmile Solutions

Page 2: Arduino tank meets bluetooth

ハルロック(西餅 著)

大学生協で教科書と並べて売られている!

Page 3: Arduino tank meets bluetooth

アジェンダ

無線化とは何か?

Bluetooth の種類

ペリフェラルとセントラル

Bluetooth 2.0 と Bluetooth Low Enrgy の違い

SPP通信とGATT

Bluetooth モジュール

Bluetooth を制御する

Android で制御

Windows ストアアプリで制御

WPF アプリで制御

Page 4: Arduino tank meets bluetooth

何故、無線化するのか?

ロボットを制御するためにPCと直結させる。

移動が制限される

ロボットにPCを乗せる?

最近はmini PCがある。

ロボットを遠隔操作する?

通信速度の制限がある。

通信距離の制限がある。

直結

Wi-Fi/Bluetooth

Page 5: Arduino tank meets bluetooth

無線化の種類

PC/Android Tank

PC/Android Tank

USBケーブル

マスター機器 スレーブ機器

有線のUSBケーブルを外す

無線化して Tank を自由に動かす

赤外線(IR)

ガラケー、TVリモコン

WiFi(無線LAN)

Bluetooth

ラジコン、プロボ

Zigbee 近距離通信に特化

日本では2.4GHz のラジコン帯が自由に使える

Page 6: Arduino tank meets bluetooth

Bluetoothの帯域

2.4GHz体の40チャンネルを使う

たくさんのBT機器があると混線する

電子レンジの近くでは使えない

WiFi 802.11a/b/g と混在

ラジコン RFモジュールと混在

Page 7: Arduino tank meets bluetooth

ペリフェラルとセントラル

ペリフェラル Peripheral

温度センサー等のデバイス

制御機器、Arduino Tank

セントラル Central

PC で制御

Android/iPhone で制御

PC/Android デバイス

セントラル ペリフェラル

Page 8: Arduino tank meets bluetooth

Bleutooth 2.0 と BLE の違い

Bluetooth 2.0 は主に SPP通信(シリアル通信)、HID で使う

ファイル転送は、WiFi と同じように使える。

常時接続で大量データ通信使う。

BLE(Bluetooth Low Energy)は、省電力に特化。通信速度も遅い。

20byte パケットの制限

GATT でセンサーデータの送受信に使う。

ロボット制御で、制御電文に使う。

Page 9: Arduino tank meets bluetooth

Bluetooth の接続制限

BT 2.0 BLE BT/BLE Windows iPhone 5 Android

BT 2.0 ○ × ○ ○ × ○

BT/BLE ○ ○ ○ ○ × ○

Windows ○ ○ ○ ○ ×? ○

iPhone 5 ※1 ○ × ※2 × ○ ×

Android ○ ※3 ※3 ○ ×? ○

※1 iPhone では、SSP通信する場合は MFi が必要※2 BT/BLE 混在のドングルへは接続できない※3 BLE は Android 4.4 以降

Page 10: Arduino tank meets bluetooth

手軽/現実的な接続のために

Windows/Android からは、BT 2.0を利用して SPP通信(シリアル通信)が楽

iPhone を含めると BLE が必須

iBeacon(iPhone の BLE デバイス)は、今後ライセンスが必要

特に Beacon を名乗る必要が無ければ、別の BLE を使えば ok

Page 11: Arduino tank meets bluetooth

SPP通信(Serial Port Profile)

一番楽ちんな通信

Arduino の Serial クラスを使える

Windows で COM ターミナル(Tera term など)を使える。

Windows で RFCOMM クラスが使える

Windows ストア用だが、工夫すればデスクトップアプリでも使える

Raspberry Pi で ttyAMA を使う

Android で BluetoothSocket を使う

5V●TX ●RX ●

GND ●

●Vin

● TX

● RX

● GND

SPI接続は簡単

Page 12: Arduino tank meets bluetooth

GATT(Generic Attribute Profile)

iPhone を含めるときは GATT が必須

データのやり取りが、BT 2.0 より細かく決められている。

その分、手順が増えているけど

Windows では GattDeviceService, GattCharacteristic を使う

Android では BluetoothDevice.connectGatt を使う

iPhone では CBCentralManager を使う

Page 13: Arduino tank meets bluetooth

HID(Serial Port Profile)

Bluetooth接続のキーボード、マウスで使われている

アダプタを買えば、デバイスを「キーボード」として認識できる。

PC/スマートフォンではキーボードと認識されるので、キーコードを送ることで特殊なプログラムを組まなくて済む。

Arduino を使って自作できる。

Page 14: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BLE)

CC2541 SensorTag 開発キット

温度センサー、加速度センサーボタンが2個BLEを扱う実験に使う $25.00

BLEduino

BLEとArduinoの組み合わせ3,500円程度

Page 15: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BLE)

mbed HRM1017

BLEとmbedの組み合わせ5,400円

BLE 開発キット:BVMCN5103-BK KIT

nRF51288 搭載開発キット、デバイス2個とデバッガ付き14,500円

Page 16: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BLE)

HM-10

CC2540 搭載のBLEモジュール$5程度

RedBearLab BLE Sheid

nRF8001 搭載 Arduino 用シールド3,000円程度

Page 17: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BT 2.0)

MyBeacon Fan

iBeacon 専用モジュール1,000円

Page 18: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BT 2.0)

HC-05

Mater/Slave両方可能なBT 2.0モジュール1,400円~$3程度

HC-06

Salve専用のBT2.0モジュール1,000円から$3程度

Page 19: Arduino tank meets bluetooth

Bluetooth モジュールあれこれ(BT 2.0)

HC-09

Slave専用のBT 2.0モジュール$3程度

Page 20: Arduino tank meets bluetooth

BT 2.0 の SPP通信を使う

BT 2.0 のモジュールは手に入りやすいので手始めに使いやすい。

HC-05 でシリアルピンついている

LEGO EV3 等の制御も SPP 通信が使われているので応用が利く。

Androidの古い機種でも動く

中古 SC-06D を買ってしまったので

Xamarin.Android が使える

Page 21: Arduino tank meets bluetooth

Arduino スケッチ

Serial クラスを使う

Serial.available() でデータ長チェック

Serial.read() で1バイトずつ読み込み

コマンド毎にモーターとLEDを制御

Serial.write() で応答を返せる

距離センサーこれで返すと良い。

9600bpsでオープン

データ受信

モーター駆動

Page 22: Arduino tank meets bluetooth

Windows ストアアプリから接続

RFCOMMを有効にする

Page 23: Arduino tank meets bluetooth

Windows ストアアプリから接続

RFCOMMでシリアル接続

接続先を検索

接続

Page 24: Arduino tank meets bluetooth

Windowsストアプリから制御

データ送信

Page 25: Arduino tank meets bluetooth

Android から接続

シリアル接続

BTオープン

接続先を検索

Page 26: Arduino tank meets bluetooth

Android から制御

データ送信

Page 27: Arduino tank meets bluetooth

WPF から接続

WinRTを利用可能にする

Windows.winmd が設定可能

Page 28: Arduino tank meets bluetooth

NetduinoでSPP受信

9600bpsでオープン

データ受信

LED点滅

Page 29: Arduino tank meets bluetooth

参考文献

Arduino – Home

Arduino - open-source tool for electronic projects

Netduino :: home

Mobile App Development & App Creation Software – Xamarin

Bluetooth Low Energyをはじめよう (Make:PROJECTS)

Bluetooth SMART デバイス(LE GATT Profile)と連携するWindows Store Appsの開発 - デバイスとITの架け橋 - Site Home - MSDN Blogs

Bluetooth GATT | Specifications | Bluetooth Development Portal

【連載】Bluetooth LE (2) iOS デバイスで Bluetooth LE 機器を使う (フェンリル | デベロッパーズブログ)

「ハルロック」http://www.moae.jp/comic/harurock/1/1