您的位置:首页 > 产品设计 > UI/UE

控制Arduino的利器-Windows Remote Arduino

2015-12-18 15:01 645 查看

http://www.cnblogs.com/dearsj001/p/WindowsRemoteArduino.html

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统称为上位机,我们可以使用以下三种方法中的任意一种来完成上位机的环境设置:

Download the Windows Remote Arduino Experience app from the Microsoft Store
Install the NuGet package
Manually add the Windows Remote Arduino project files to a new Visual Studio solution.

上述三种方式的难以程度依次升高。其中,第一种适用于简单的使用场景,用户无需编写代码就可以通过下载的Windows Remote Arduino Experience来完成Arduino设备的控制。第二种适用于编写自己的UWP应用场景,通过引用Windows Remote Arduino包,在自己编写的程序中完成Arduino设备的控制。第三种需要手动将Windows Remote Arduino源代码工程添加到自己的工程中来,这种方式可以获得的自由度最大,用户可以根据自己的需求定制Windows
Remote Arduino。
这里,以第一种方法为例,打开微软商店,直接在PC或者Mobile上安装Windows Remote Arduino Experience应用,该应用是UWP应用。



3. Arduino设置

Windows Remote Arduino建立在Firmata protocol 基础之上,因此,我们首先需要在Arduino硬件设备上烧写对应的代码。在安装Arduino IDE的时候,StandardFirmata 是默认安装的,用户可以按照以下的步骤进行程序的烧写:

通过USB接口连接Arduino设备,这里以Arduino UNO为例。
启动Arduino IDE
通过Tools > BoardTools > Port选择对应的板类型和端口号。
通过File > Examples > Firmata > StandardFirmata,打开该工程。
点击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设备了,如下图所示,



之后,应用程序界面分别包含了Digital、 Analog、PWM这三个页面,用户可以点击对应的页面进行远程控制和数据读取。以Pin 13为例,默认是Output的Low,通过点击更改电平,如下图所示。



观察Arduino Uno的板载Pin 13连接的LED灯,即可发现其状态已经点亮,如下图所示。



5. 使用以太网连接

笔者手头有W5100的Ethernet Shield,所以尝试了这种方式。注意,这种方式下,我们需要重新烧写Arduino的sketch。具体步骤如下:

登陆Github,下载standard-firmata-networking
解压,拷贝lib目录下的EthernetStream文件夹到本地的Arduino libraries目录。
打开standard-firmata-ethernet.ino
插上W5100 Ethernet Shield,将Arduino Uno通过USB连接到PC。
点击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进行修改)。



点击连接之后,同样可以按照上面第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

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: