Top Banner
LinkIt 7697物聯網研習 資料區:https://goo.gl/6DRDGA CAVEDU 曾吉弘
113

LinkIt 7697 IoT tutorial

Jan 21, 2018

Download

Devices & Hardware

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LinkIt 7697 IoT tutorial

LinkIt 7697物聯網研習

資料區:https://goo.gl/6DRDGA

CAVEDU 曾吉弘

Page 2: LinkIt 7697 IoT tutorial

硬體介紹

Page 3: LinkIt 7697 IoT tutorial

Product

NameLinkIt 7697

Manufacturer Seeed Studio

Module wrtnode7 (wrtnode.com)

Chipset

MT7697

Cortex-M4 with FPU @

192Mhz

RAM 352 KB

Flash 4 MB

Wi-Fi 802.11 b/g/n (2.4G)

Bluetooth 4.2 LE

Dimension 48x26 mm

Operating Voltage 3v3

Input Voltage 5v (microUSB)

USB2UART CP2102N

Peripheral

Interfaces

GPIO x18

UART x2

I2C x1

SPI x1

PWM x18

EINT x4

ADC x4 (0~2.5V)

IrDA x1

I2S x1

Debug Interfaces SWD x1

LinkIt 7697• 聯發科技最新的物聯網開發板

– Wi-Fi / BLE 雙通訊功能

– 採用主流 Cortex-M4 架構

– 開放的軟體開發環境 (FreeRTOS)

Page 4: LinkIt 7697 IoT tutorial

腳位圖https://labs.mediatek.com/en/download/1ega2lbl

Copyright © MediaTek Inc. All rights reserved.

4

Page 5: LinkIt 7697 IoT tutorial

LinkIt 7697 開發板外觀介紹

Copyright © MediaTek Inc. All

rights reserved.5

WrtNode7無線模組內含:• MediaTek MT7697 SoC

• 快閃記憶體• 天線

重置按鈕(RST)

使用者自定義按鈕(P6)

UART0

傳輸燈號(P0/P1)

供電指示燈

自定義燈(P7) CP2102N UART 轉 USB 晶片

製造廠商:Silicon Labs

Page 6: LinkIt 7697 IoT tutorial

LinkIt 系列開發板比較

6

LinkIt ONE LinkIt Smart 7688/Duo LinkIt 7697

定位all-in-one

IoT Dev Board

Rich IoT Endpoint

/ GatewayLightweight IoT Endpoint

發售年分 2014/7 2015/11 2017/4

微控制器MT2502

(ARM7EJ-S)

MT7688

(MIPS)

MT7697

(ARM Cortex-M4F)

主頻 260Mhz 580Mhz 196Mhz

RAM 4MB 128MB 352K

Flash 16MB 32MB 3612K

Dev Platform Proprietary RTOS*1+ Arduino OpenWrt (Linux) + Arduino FreeRTOS + Arduino

Programming Lang C/C++ C/C++/JS/Python C/C++/JS/Visual

Wi-Fi 802.11 b/g/n 802.11 b/g/n 802.11 b/g/n

BLE BT 2.1/BLE 4.0 - BLE 4.2

Cellular GSM/GPRS*2 - -

GNSS GPS/GLONASS/BeiDou*2 - -

Ethernet - 10/100 PHY -

USB Device Host -

SD Card MicroSD MicroSD -

終端售價 ~2000 NTD ~500 NTD ~500 NTD

*1 沒有開源*2 隨著台灣 2G 關台, GSM/GPRS 和 GNSS 的功能應用性就不高

Page 7: LinkIt 7697 IoT tutorial

腳位圖與 Arduino 對應關係https://labs.mediatek.com/en/download/1ega2lbl

Copyright © MediaTek Inc. All

rights reserved.7

Digital Pin 以絲印上面的數字作為參數,例:digitalWrite(7, HIGH);

Analog Pin 以絲印上面的數字作為參數,或使用 A0 ~ A3

Page 8: LinkIt 7697 IoT tutorial

Seeed 7697 Grove套件包

• Grove Breakout x1

• Grove - IMU 9DOF x1

• Grove – Temperature & Humidity

Sensor Pro x1

• Grove - Ultrasonic Ranger x1

• Grove - Relay x1

• Grove - OLED Display 0.96" x1

• Grove - Light Sensor x1

• Grove - LED Bar x1

• Grove – Servo x1

• Breadboard 82mm x 53mm x1

• Button x5

• 10K Ohm Rotary Potentiometer x1

• 1K/10k/330 Ohm Resistor x1

• RGB LED x1

• Red LED x5

• Micro USB Cable – 48 cm x1

• Breadboard Jumper Wire x25

Page 9: LinkIt 7697 IoT tutorial

Arduino IDE setup

Page 10: LinkIt 7697 IoT tutorial

Arduino IDE 下載

1. 請下載 Arduino 1.6.4 以後的版本

2. 從 board manager 安裝 7697 套件

3. 下載CP2102N驅動程式

Page 11: LinkIt 7697 IoT tutorial

在Arduino IDE 偏好設定中貼上這個連結

• File / Preferences

• http://download.labs.mediatek.com/package_mtk_linkit_7697_index.json

• 旁邊的按鈕可以加入多個定義檔

Page 12: LinkIt 7697 IoT tutorial

在選單中看到 7697,按 Install

• Tools / Board / Boards Manager

• 目前最新版為 0.7.11 (示意圖如下)

Page 13: LinkIt 7697 IoT tutorial

完成之後就可以看到 7697 了

• 在很下面…

Page 14: LinkIt 7697 IoT tutorial

安裝 driver,請把 7697 接上電腦

• 下載CP2102N驅動程式,並根據您的作業系統版本來安裝 x86/x64版本

• 安裝完畢之後請將7697接上電腦,就可自動抓到它。

Page 15: LinkIt 7697 IoT tutorial

抓到COM port

Page 16: LinkIt 7697 IoT tutorial

如果無法編譯

• 請到以下路徑檢查,是否有 0.7.4 (最新版本) 之資料夾,其他檔案請刪除

• C:\Users\user\AppData\Local\Arduino15\p

ackages\LinkIt\hardware\linkit_rtos

Page 17: LinkIt 7697 IoT tutorial

BlocklyDuino for LinkIt 7697

今天請用google drive上的blockyduino.v2.2.1.rar 來上課喔!

Page 18: LinkIt 7697 IoT tutorial

BlocklyDuino for LinkIt 7697

18

• 視覺化的程式編輯環境

• 不只適用於LinkIt 7697

• 周邊I/O指令已經準備好

• Open source (github)

Page 19: LinkIt 7697 IoT tutorial

BlocklyDuino for LinkIt 7697的優點

19

• 可離線執行(github)

• 能產生對應的Arduino sketch ,便於學習與除錯

• 與Arduino IDE結合,函式庫相容性與擴充性高

• 可快速驗證想法可行性

• Open source

Page 20: LinkIt 7697 IoT tutorial

離線執行

• 根據您所使用的作業系統(Windows 32/64,

MAC, Linux32/64)解壓縮之後,點擊執行檔即可開啟

Page 21: LinkIt 7697 IoT tutorial

21

Arduino Blockly

優點:

• 適合入門,培訓基礎程式能力• 降低門檻,沒有硬梆梆的英文與程式碼

優點:

• 適合進階學生,完成較複雜的功能

• 除錯較為方便

Page 22: LinkIt 7697 IoT tutorial

右上角的設定

22

Page 23: LinkIt 7697 IoT tutorial

如何匯入範例

• 在BlocklyDuino 右上角點選”匯入”

• 把github所下載之 /examples/ 各範例中的.xml 檔貼進去即可

Page 24: LinkIt 7697 IoT tutorial

完成了

Page 25: LinkIt 7697 IoT tutorial

LESSON 1 : BLINK

25

Page 26: LinkIt 7697 IoT tutorial

LED閃爍

26

點選Arduino

可轉換為Arduino Sketch

按存檔,即可同步存入IDE

1.Linkit 7697 上有一個內建的LED 燈,上面寫著 USR 三個字。2.Linkit 7697的內建 LED 燈和 PIN 7 在板子內部的線路並聯的

Page 27: LinkIt 7697 IoT tutorial

LESSON 2 : 電位計控制LED

27

Page 28: LinkIt 7697 IoT tutorial

線路示意圖

28

範例在雲端:code/Blocky/example/lightsensor

Page 29: LinkIt 7697 IoT tutorial

Demo (實際示例)

29

利用A0腳位的數值變化,控制D7 LED是否亮滅。

Page 30: LinkIt 7697 IoT tutorial

30

Arduino Sketch

Page 31: LinkIt 7697 IoT tutorial

LESSON 3 : SERVO

31

Page 32: LinkIt 7697 IoT tutorial

用7697 控制Servo

32

範例在example/servosweep

Page 33: LinkIt 7697 IoT tutorial

您將在本例子使用的Block

33

•如果 < 事件 > 執行 < 事件>

•< 資料 > 大於 < 資料>

•< 數字>

•賦值 < 資料型態 > < 變數 > 到 < 資料>

•加入Setup()

•延遲 < 資料>

•寫入 Pin < 腳位 > 角度 < 資料>

Page 34: LinkIt 7697 IoT tutorial

Demo (實際示例)

34

Servo 會在一開機轉回原點,之後在每秒都會多轉 15 度直至轉滿 180 度,接著再次回到原點不斷重複。

Page 35: LinkIt 7697 IoT tutorial

Arduino Sketch

35

Page 36: LinkIt 7697 IoT tutorial

Examples/LWiFi/WiFiWebClient

Page 37: LinkIt 7697 IoT tutorial

MediaTek Cloud SandBox

https://mcs.mediatek.com

Page 38: LinkIt 7697 IoT tutorial

MediaTek Cloud Sandbox

(MCS)

Page 39: LinkIt 7697 IoT tutorial

MCS主要功能

• 雲端平台,執行程式

• 例:Google App Engine、Amazon Web

Services、Microsoft Azure

• 提供網頁介面,讓你「點按滑鼠」就能建立雲端程式

• 提供API程式存取介面

• 提供網頁介面,觀看與控制各種資料

Page 40: LinkIt 7697 IoT tutorial

MCS其他功能

• 通知(Notification),當某資料符合特定條件時,寄送電子郵件

• 使用者權限(User Privilege),設定開發成員的存取修改權限

• FOTA(Firmware Over The Air),版本控管,韌體經由無線傳輸自動更新

Page 41: LinkIt 7697 IoT tutorial

目標

• 到MCS註冊帳號

• 建立網頁應用程式(web application)

• 透過MCS REST API進行溝通

• LinkIt 家族開發板、手機、瀏覽器

Page 42: LinkIt 7697 IoT tutorial

範例

• 從雲端控制板子內建的LED

• LED:想像成家裡的燈

• 為什麼從雲端?不能直接連線嗎?

Page 43: LinkIt 7697 IoT tutorial
Page 44: LinkIt 7697 IoT tutorial

MCS重要觀念與名詞

• Prototype,裝置原型,具備各種 data

channel

• Data Channel,帶有時間資訊的資料串

• Data Channel Id:對應的資料接口

• Datapoint:每筆上傳的資料

• Test Device,想像為實際執行後的程式

• DeviceId、DeviceKey:用這個來鎖定裝置

• 例:LED控制器、溫濕度感測站

Page 45: LinkIt 7697 IoT tutorial
Page 46: LinkIt 7697 IoT tutorial

MCS Android app

• Google Play 下載

Page 47: LinkIt 7697 IoT tutorial

MCS Dashboard(儀表板)

Page 48: LinkIt 7697 IoT tutorial

MCS 重要選項• Console:主控台

• Development:建立Prototype、新增修改Data

channel、查詢Data channel Id

• Test Devices:查詢DeviceId、DeviceKey

• Resources:教學文件、參考資料

• Resources:常見問題、論壇、回饋

Page 49: LinkIt 7697 IoT tutorial

範例:控制LED並檢視狀態

程式:mcsled.js

Page 50: LinkIt 7697 IoT tutorial

流程

1. 建立Prototype

2. 依照所需功能,新增Data channel,記下Data channel Id

3. 建立Test device,記下DeviceId與DeviceKey

Page 51: LinkIt 7697 IoT tutorial

建立Prototype

• Prototype name:LED

Manager (或自定)

• Prototype version:1.0

• Hardware platform:LinkIt

Smart 7688 (MT7688)

• Industry:自定

• Application:自定

Page 52: LinkIt 7697 IoT tutorial
Page 53: LinkIt 7697 IoT tutorial

Data channel 資料頻道

• Controller型:可控制腳位

• Display型:接收腳位/周邊裝置回傳的資料

Page 54: LinkIt 7697 IoT tutorial

分享與觸發

• 您可以把建好的 test device 與別人共享

• 也可以自行設定觸發條件,讓 MCS 寄信給您

Page 55: LinkIt 7697 IoT tutorial

目前有哪些類型?

Controller

• ON/OFF• Category• Integer• Float• Hex• String• GPS• GPIO• PWM• Analog• GamePad

Display

• ON/OFF• Category• Integer• Float• Hex• String• GPS• GPIO• PWM• Image Display• Video Stream

Page 56: LinkIt 7697 IoT tutorial

ON/OFF

• 控制高低電位。LED、繼電器等

• 顯示裝置的電位高低狀態

Page 57: LinkIt 7697 IoT tutorial

Category

• 讓系統可在2~5個狀態之間切換

Page 58: LinkIt 7697 IoT tutorial

Integer / Float / Hex

• 傳整數/浮點數/16進位值給裝置

• 顯示裝置的數值參數。各種感測器

Page 59: LinkIt 7697 IoT tutorial

String

• 傳送字串給裝置 / 顯示裝置回傳的字串

Page 60: LinkIt 7697 IoT tutorial

GPS (Google Map~)

• 傳送經度、緯度、標高給裝置

• 顯示裝置的GPS座標

Page 61: LinkIt 7697 IoT tutorial

日期區間搜尋

Page 62: LinkIt 7697 IoT tutorial

GPIO

• 控制/顯示裝置的 GPIO 腳位高低電位

Page 63: LinkIt 7697 IoT tutorial

PWM

• 控制/顯示裝置的PWM腳位,可指定範圍

Page 64: LinkIt 7697 IoT tutorial

Analog (只有Controller)

• 以滑桿方式送出指定範圍之內的數值

Page 65: LinkIt 7697 IoT tutorial

GamePad (只有Controller)

• 這…很直覺吧 MCS教學請點我

Page 66: LinkIt 7697 IoT tutorial

MCS 控制 LED 閃爍

Arduino IDE 範例路徑:File/examples/MCS/LED_Control

BlocklyDuino: MCS Blink

Page 67: LinkIt 7697 IoT tutorial

MCS 新增on/off

控制器/顯示器各一個

Id: LED_Control

Page 68: LinkIt 7697 IoT tutorial

完成如下圖

Page 69: LinkIt 7697 IoT tutorial

更新Device Id/Key: #6,7,10

• #define _SSID "Maker_3F_A1"

• #define _KEY "25584819"

• MCSDevice mcs("DT95rNZa",

"QZg3IJdbXXC4uSgr");

Page 70: LinkIt 7697 IoT tutorial

Arduino程式說明: #16 17

• MCSControllerOnOff led(“LED_Control");

– 在此填入控制用的Channel id

• MCSDisplayOnOff remote(“LED");

– 在此填入顯示用的Channel id

紅字可修改,在此代表定義一個名為led的MCS OnOff 控制器與名為remote的MCS

OnOff 顯示器

以上圖來說分別是LED_Control與LED

Page 71: LinkIt 7697 IoT tutorial

連接channel id 與 mcs: #41 42

• mcs.addChannel(led);

• mcs.addChannel(remote);

Page 72: LinkIt 7697 IoT tutorial

持續嘗試連上MCS : #43~47

• while(!mcs.connected())

• {

• Serial.println("MCS.connect()...");

• mcs.connect();

• }

Page 73: LinkIt 7697 IoT tutorial

讀取來自MCS的數值: #51~55

• while(!led.valid()) //如果控制器有變化

• {

• Serial.println("read LED value from MCS...");

• led.value(); //取得MCS數值

• }

• Serial.print("done, LED value = ");

• Serial.println(led.value()); //顯示出來

Page 74: LinkIt 7697 IoT tutorial

根據MCS數值控制LED: #58

• digitalWrite(LED_PIN,

led.value() ? HIGH : LOW);

led.value() 如為1,則上述判斷結果為 HIGH

反之為 LOW,這樣即可控制LED

Page 75: LinkIt 7697 IoT tutorial

更新資料上MCS: #74~78

• if(!remote.set(led.value()))

• {

• Serial.print("Failed to update remote");

• Serial.println(remote.value());

• }

使用remote.set() 把數值更新到指定channel

如果更新資料失敗則顯示錯誤訊息

Page 76: LinkIt 7697 IoT tutorial

Serial monitor畫面

Page 77: LinkIt 7697 IoT tutorial

改用BlockyDuino玩玩看

Page 78: LinkIt 7697 IoT tutorial

78

BlocklyDuino 的MCS相關指令

Page 79: LinkIt 7697 IoT tutorial

MCS 雲端控制輕鬆上手

79

請匯入 /code/Blockly/MCS_simple.xml

Page 80: LinkIt 7697 IoT tutorial

如.ino修改對應參數即可

Page 81: LinkIt 7697 IoT tutorial

執行吧!

• 執行時可看到 MCS test device 名稱左邊亮起綠燈,代表裝置已與 MCS 連通

• 拿起Android裝置打開 MCS app 來玩吧

Page 82: LinkIt 7697 IoT tutorial

MCS範例2:上傳A0資料

雲端/code/Arduino/mcs_post.ino

Page 83: LinkIt 7697 IoT tutorial

MCS端

• 請新增 Integer顯示頻道,id “Temp”

• 一樣要建立 test device

Page 84: LinkIt 7697 IoT tutorial

程式解說,不要填錯#4~8

• char _lwifi_ssid[] = “OOOO";

• char _lwifi_pass[] = “XXXX";

• MCSDevice mcs(“****", “%%%%");

• MCSDisplayInteger Temp("Temp");

Page 85: LinkIt 7697 IoT tutorial

程式解說

Page 86: LinkIt 7697 IoT tutorial

執行畫面

• Channel右上角 -> Show History data

Page 87: LinkIt 7697 IoT tutorial

如何新增觸發條件?

電子郵件、手機推播、webhook

Page 88: LinkIt 7697 IoT tutorial

1. 原型:編輯觸發條件與動作

Page 89: LinkIt 7697 IoT tutorial

2. 編輯觸發條件

請注意只支援整數/浮點數之顯示器

Page 90: LinkIt 7697 IoT tutorial

3. 選擇觸發動作

Page 91: LinkIt 7697 IoT tutorial

設定觸發條件完成

還可加入更多動作

Page 92: LinkIt 7697 IoT tutorial

開啟推播權限

Page 93: LinkIt 7697 IoT tutorial

右上角 / 個人頁面

1. 手機列表 -> 打開您想要接收推播的手機

Page 94: LinkIt 7697 IoT tutorial

test device

“觸發條件與動作”--> 管理您的觸發動作來開啟手機推播通知

Page 95: LinkIt 7697 IoT tutorial

手機MCS app

手機app端左側 setting -> push notification (應該都會自動啟動,再檢查一下)

Page 96: LinkIt 7697 IoT tutorial

手機MCS app

手機app端,在測試裝置右上角檢查 Trigger & Action 是否開啟

[數值超標] 為我們所定義的觸發條件名稱

Page 97: LinkIt 7697 IoT tutorial

挑戰:上傳溫度溼度到MCS

路徑:

Page 98: LinkIt 7697 IoT tutorial

7697 BLE

範例:

手機:BLE_LED_7697.aia

BlocklyDuino: LBLEperipheral.xml

Arduino: Simpleperipheral.ino

Page 99: LinkIt 7697 IoT tutorial

App Inventor介紹

• 圖形化Android開發環境

• App Inventor中文學習網 -教學

• MIT App Inventor -開發

• CAVEDU為 MIT App Inventor 之物聯網教學推廣夥伴

Page 100: LinkIt 7697 IoT tutorial

請先上傳simpleperipheral到7697

Serial.print("Device Address = [");

Serial.print(LBLE.getDeviceAddress());

Serial.println("]");

Page 101: LinkIt 7697 IoT tutorial

7697 作為BLE裝置名稱可自訂

advertisement.configAsC

onnectableDevice("CAVE

DU");

#43

可透過手機的藍牙介面來掃描

Page 102: LinkIt 7697 IoT tutorial

Designer頁面

Page 103: LinkIt 7697 IoT tutorial

Blocks

• Addr 要改為您手邊7697的 BLE addr

Page 104: LinkIt 7697 IoT tutorial

按鈕來連線與斷線

Page 105: LinkIt 7697 IoT tutorial

BLE本身的連線斷線事件

Page 106: LinkIt 7697 IoT tutorial

ON/OFF 送出整數 1,0

Page 107: LinkIt 7697 IoT tutorial

您可以此為架構來擴充

• 加入更多I/O

• 手機端改為其他的觸發方式:例如Google

語音辨識/ 手機方位感測器等

Page 108: LinkIt 7697 IoT tutorial

Arduino程式說明

Simpleperipheral.ino

Page 109: LinkIt 7697 IoT tutorial

設定UUID: #16,17

• LBLEService ledService("19B10010-

E8F2-537E-4F6C-D104768A1214");

• LBLECharacteristicInt

switchCharacteristic("19B10011-E8F2-

537E-4F6C-D104768A1214",

LBLE_READ | LBLE_WRITE);

• 需與 App Inventor 端一致

Page 110: LinkIt 7697 IoT tutorial

Arduino程式說明:#29~36

• LBLE.begin();

• Serial.print(LBLE.getDeviceAddress());

顯示 7697 的 BLE addr,重要!!

Page 111: LinkIt 7697 IoT tutorial

讀取收到的值控制LED:#65~73

• if (switchCharacteristic.isWritten()) {• const char value =

switchCharacteristic.getValue();• switch (value) {• case 1:• digitalWrite(LED_BUILTIN, HIGH);• break;• case 0:• digitalWrite(LED_BUILTIN, LOW);• break;

Page 112: LinkIt 7697 IoT tutorial

操作

• 請先上傳7697程式,並開啟 serial monitor

• 檢查一下 App Inventor 中有沒有修改 7697

的 BLE addr

• 先點選 [Connect] 按鈕,如看到[connected]字樣代表連線成功

• 點選 [ON] [OFF] 按鈕即可控制LED亮滅

• 點選 [Disconnect] 按鈕(同Connect) 斷線

Page 113: LinkIt 7697 IoT tutorial

參考資料

• MCS 台灣使用者討論 FB 社團

• MCS github

• 機器人王國商城