Download - AWS IoTでGo!
![Page 1: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/1.jpg)
AWS IoTでGO!電車でGO!コントローラを使い、arduino Yún + モーターシールドでNゲージを操作2016/2/16
瀧澤 与一 (Mail: [email protected])
アマゾン ウェブ サービス ジャパン株式会社技術本部 エンタープライズソリューション部部長/シニアソリューションアーキテクト
![Page 2: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/2.jpg)
瀧澤与一アマゾンウェブサービスジャパン株式会社
技術本部 エンタープライズソリューション部部長/ソリューションアーキテクト
金融機関をはじめとするエンタープライズ企業向けのAWS導入サポート
趣味:
オーディオ&ビジュアル、スキー、ドライブ、子供と遊ぶ。
About me
2
![Page 3: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/3.jpg)
7歳
なぜか、鉄道好きに
踏切の音を聞いて、路線をあてられるレベル
「10歳になったらね」の約束を破り、Nゲージの道に。
うちのこども
3
![Page 4: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/4.jpg)
Nゲージ ジオラマ・・
4
![Page 5: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/5.jpg)
線路に最大12Vの電圧。
車両は線路に流れる電流を車輪で受け、モーターを駆動。
電圧により、車両の速度が変わる。
±を逆にすれば逆進。
一般的には、専用のコントローラ(パワーパック)で操作。
Nゲージの仕組み
5
![Page 6: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/6.jpg)
arduinoにモータシールドを接続し、線路に流れる電圧をarduino経由で制御可能に。
arduinoをUSBシリアルでRaspberry piを接続し、Raspberry piにWebサーバを構築。
タブレット経由で車両の操作ができるようにした。
最初のトライ
しかし、うちの子供には不評。
ハンドルで操作したいとのこと。
6
![Page 7: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/7.jpg)
「タブレットでのタッチ操作じゃリアリティがないんだよなー」
by うちのこども
7
![Page 8: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/8.jpg)
電車でGO!64コントローラを改造
課題解決:そういうわけで、
8
![Page 9: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/9.jpg)
構成図
Arduino Yún
モーターシールド
AWS IoT
SNSLambda CloudWatch
logs
S3
操作 速度データ
線路への電圧
9
![Page 10: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/10.jpg)
HC148
電車でGO!64コントローラの分解
10
![Page 11: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/11.jpg)
データシート
HC148
11
![Page 12: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/12.jpg)
HC148データシート(続き)
コントローラの位置をA2,A1,A0ピンを使い2進数で出力。→ arduinoに入力
12
![Page 13: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/13.jpg)
Arduino Leonardo(ATmega32u4)をベースとし、無線機能(WiFi)付きのLinuxボードを搭載したArduino。
技適認証あり。https://www.switch-science.com/catalog/2210/
AWS IoTのSDKあり。
Arduino Yún
13
![Page 14: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/14.jpg)
Arduinoのアナログ出力は最大5V。
モーターシールドでは、12Vの外部電源を接続すると、最大5Vの入力に対して、最大12Vの出力をリニアに出力可能。電流も2Aまで。
シールド形状のため、Arduinoにかぶせるように接続可能。
モーターシールド
14
http://akizukidenshi.com/catalog/g/gM-06684/
![Page 15: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/15.jpg)
AWS IoT
デバイスデータに対するいろいろなアクション
セキュアでスケーラブルなデバイスとクラウドの
双方向接続
誰でも簡単にはじめられる
さまざまなデバイスをAWSの各種サービスや他のデバイスにセキュアに接続し、デバイスデータに対する処理やアクションを実行することが可能
15
![Page 16: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/16.jpg)
データフローとAWSサービスのマッピング
収集 処理 分析
保存
S3
Kinesis
DynamoDB
Data Collection
and Storage
AWS Lambda
KCL Apps
Event
Processing
EMR Redshift
MachineLearning
Data
Processing
Data
Analysis
IoT
![Page 17: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/17.jpg)
AWS IoT Overview
17
![Page 18: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/18.jpg)
18
![Page 19: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/19.jpg)
19
![Page 20: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/20.jpg)
20
![Page 22: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/22.jpg)
1. SDKをダウンロードhttps://github.com/aws/aws-iot-device-sdk-Arduino-yun/インストールの詳細は、上記GitHUBのreadmeを参照。
2. AWS IoT CA file(ルート証明書)をダウンロード(here.)
ファイル名を「root-CA.crt」にしておく。
3. AWS IoTでダウンロードした証明書とルート証明書を「AWS-IoT-Arduino-Yun-SDK/AWS-IoT-Python-Runtime/certs」に保管。
4. インストールスクリプトを実行。chmod 755 AWSIoTArduinoYunInstallAll.sh /AWSIoTArduinoYunInstallAll.sh <Board IP> <UserName> <Board Password>
5. 「AWS-IoT-Arduino-Yun-SDK/AWS-IoT-Arduino-Yun-Library」ライブラリを「Documents/Arduino/libraries」にコピー。
Arduino Yúnのセットアップ・証明書コピー
22
![Page 23: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/23.jpg)
AWS IoT SDKの使用。
モーターシールドで使うpinなどを設定。
コード(1/4)
23
![Page 24: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/24.jpg)
電車でGO!コントローラの信号を読み取り、モーターシールドに出力する電圧を決定。
コード(2/4)
24
![Page 25: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/25.jpg)
topic1でモーターシールドへの出力値を送信。
AWS IoTのサンプルコードを流用。
コード(3/4)
25
![Page 26: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/26.jpg)
AWS IoTで「Connect Device」を実行した際に表示されるコードをペーストする。
コード(4/4)
26
aws_iot_confg.h
#ifndef config_usr_h
#define config_usr_h
// Copy and paste your configuration into this file
//===========================================================
====
#define AWS_IOT_MQTT_HOST "A3TCNQTE8Bxxxx.iot.ap-northeast-
1.amazonaws.com"
#define AWS_IOT_MQTT_PORT 8883
#define AWS_IOT_CLIENT_ID "traincontroller"
#define AWS_IOT_MY_THING_NAME "traincontroller"
#define AWS_IOT_ROOT_CA_FILENAME "root-CA.crt"
#define AWS_IOT_CERTIFICATE_FILENAME "5fa69bxxxx-certificate.pem.crt"
#define AWS_IOT_PRIVATE_KEY_FILENAME "5fa69bxxxx-private.pem.key"
//===========================================================
====
// SDK config, DO NOT modify it
#define AWS_IOT_PATH_PREFIX "../certs/"
(略)#endif
![Page 27: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/27.jpg)
構成図
Arduino Yún
モーターシールド
AWS IoT
SNSLambda CloudWatch
logs
S3
操作 速度データ
線路への電圧
ここまで完成
27
![Page 28: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/28.jpg)
rule
AWSIoT
28
![Page 29: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/29.jpg)
Lambda function
29
![Page 30: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/30.jpg)
CloudWatch Logs
30
![Page 31: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/31.jpg)
構成図
Arduino Yún
モーターシールド
AWS IoT
SNSLambda CloudWatch
logs
S3
操作 速度データ
線路への電圧
31
![Page 32: AWS IoTでGo!](https://reader030.vdocuments.pub/reader030/viewer/2022021506/58858c5e1a28ab84668b6195/html5/thumbnails/32.jpg)
うちのこどもには、とても好評!
AWS IoTは簡単。 コーディング最小でデバイスからのデータ送受が可能。
線路のどこを走っているかのセンサーの追加。
コントローラでポイント切替機の制御。
システム側からのNゲージ車両、ポイントの制御。
データの記録と分析。
まとめ・今後
32