控制Arduino的利器-Windows Remote Arduino


1. 概述

    相信很多朋友已經在玩 Arduino了,而且一般都是使用官方的Arduino IDE來寫程序控制Arduino硬件。為了能夠實現更加方便的控制,微軟在Windows IoT計划中推出了Windows Remote Arduino。簡單來說,Windows Remote Arduino是一個開源的Windows運行時組件,通過它,我們可以使用藍牙、USB、WiFi或者是以太網這四種連接方式中的任意一種來控制Arduino硬件。因此,在Windows 10這個統一的大平台下,我們可以使用Windows 10系統的PC、平板、手機,甚至是樹莓派等運行IoT Core的設備來控制Arduino硬件。Windows Remote Arduino提供的功能包括:

    (1)GPIO控制(模擬和數字)

            Digital Write

            Digital Read

            Analog Write

            Analog Read

            Setting the pin mode for any pin

            Receive events when values change / are reported.

    (2)I2C接口通信

    (3)Firmata用戶自定義協議

2. 上位機環境准備

    這里將運行Windows的PC、Surface、或者Windows Phone統稱為上位機,我們可以使用以下三種方法中的任意一種來完成上位機的環境設置:

    上述三種方式的難以程度依次升高。其中,第一種適用於簡單的使用場景,用戶無需編寫代碼就可以通過下載的Windows Remote Arduino Experience來完成Arduino設備的控制。第二種適用於編寫自己的UWP應用場景,通過引用Windows Remote Arduino包,在自己編寫的程序中完成Arduino設備的控制。第三種需要手動將Windows Remote Arduino源代碼工程添加到自己的工程中來,這種方式可以獲得的自由度最大,用戶可以根據自己的需求定制Windows Remote Arduino。

    這里,以第一種方法為例,打開微軟商店,直接在PC或者Mobile上安裝Windows Remote Arduino Experience應用,該應用是UWP應用。

image

3. Arduino設置

    Windows Remote Arduino建立在Firmata protocol 基礎之上,因此,我們首先需要在Arduino硬件設備上燒寫對應的代碼。在安裝Arduino IDE的時候,StandardFirmata 是默認安裝的,用戶可以按照以下的步驟進行程序的燒寫:

    1. 通過USB接口連接Arduino設備,這里以Arduino UNO為例。
    2. 啟動Arduino IDE
    3. 通過Tools > BoardTools > Port選擇對應的板類型和端口號。
    4. 通過File > Examples > Firmata > StandardFirmata,打開該工程。
    5. 點擊Upload,將StandardFirmata sketch燒寫到Arduino UNO中。

    如果用戶僅僅希望通過USB來控制Arduino設備的話,到這里已經完成了Arduino的設置工作。如果用戶希望通過藍牙來控制Arduino設備,那么,首先,PC上需要有藍牙模塊,其次,Ardunio上也需要連接一個藍牙模塊,具體可以參考這個文章《hook up a Bluetooth device to the Arduino 》。另外,如果用戶希望通過WiFi來控制Arduino設備,那么,Arduino需要一個WiFi Shield,具體可以參考這個文章《hook up a Wi-Fi device to the Arduino 》。

4. PC操作

    打開Windows Remote Arduino Experience應用程序,連接類型選擇USB,速率選擇57600。如果此時Arduino已經正確連接了PC的USB接口,則會自動顯示Arduino Uno(COM*),用戶只需點擊Connect就可以連接Arduino設備了,如下圖所示,

image

    之后,應用程序界面分別包含了Digital、 Analog、PWM這三個頁面,用戶可以點擊對應的頁面進行遠程控制和數據讀取。以Pin 13為例,默認是Output的Low,通過點擊更改電平,如下圖所示。

image

    觀察Arduino Uno的板載Pin 13連接的LED燈,即可發現其狀態已經點亮,如下圖所示。

image

5. 使用以太網連接

    筆者手頭有W5100的Ethernet Shield,所以嘗試了這種方式。注意,這種方式下,我們需要重新燒寫Arduino的sketch。具體步驟如下:

    1. 登陸Github,下載standard-firmata-networking
    2. 解壓,拷貝lib目錄下的EthernetStream文件夾到本地的Arduino libraries目錄。
    3. 打開standard-firmata-ethernet.ino
    4. 插上W5100 Ethernet Shield,將Arduino Uno通過USB連接到PC。
    5. 點擊Upload燒寫sketch。

    燒寫完成以后,可以將W5100 Ethernet Shield通過網線連接到TPLink上,查看其自動獲得的IP地址,當然,用戶也可以修改standard-firmata-ethernet.ino的代碼,設置其IP地址。

    然后,在PC或者Mobile上打開Windows Remote Arduino Experience應用程序,連接類型選擇Network

,速率選擇57600。IP地址處填寫Arduino獲得的IP地址,端口號默認為5000(也可以通過standard-firmata-ethernet.ino進行修改)。

image

    點擊連接之后,同樣可以按照上面第4節的內容控制Arduino了。

 

參考鏈接:

1. http://ms-iot.github.io/content/en-US/win10/WRA.htm

2. Download the Windows Remote Arduino Experience app from the Microsoft Store

3. Install the NuGet package

4. Manually add the Windows Remote Arduino project files to a new Visual Studio solution

5. hook up a Bluetooth device to the Arduino

6. hook up a Wi-Fi device to the Arduino

7. https://github.com/ms-iot/remote-wiring/

8. https://github.com/ms-iot/remote-wiring/#notes-on-wifi-and-ethernet


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM