Windows 10 IoT Serials 3 - Windows 10 IoT Core Ardunio Wiring Mode

    Maker社区和智能硬件的朋友一定知道Arduino,很多3D打印机都是用它做的。为了迎合这一大块市场,微软在基于Intel Galileo的Windows 8.1 IoT中就是使用这种基于Arduino的硬件接口和编程模式。目前,在Windows 10 IoT Core中也提供了这个功能。也就是说,我们使用树莓派,刷Windows 10 IoT Core系统以后,可以让它直接跑Arduinio的应用。虽然有点杀鸡用牛刀的感觉(毕竟树莓派比Arduino UNO贵好多,处理能力什么的也强不知道多少倍),但这毕竟也是微软为树莓派和Arduino社区结合所做的一些贡献。废话少说,下面就直接进入正题。

    首先,我们使用最新的Windows 10 IoT Core OS 10586,Visual Studio 2015 Update 1。大家可以去微软官方下载:

1. 在Windows 10 IoT Core中设置运行Arduino程序的Lighting模式

    运行Windows 10 IoT Core设备,如树莓派2。使用网页管理器登陆设备,如下图所示。

clip_image002

    打开其中的Devices页面,如下图所示。

clip_image004

    在Default Controller Driver中,默认是InBox Driver,将其设置为Direct Memory Mapped Driver,并点击update driver更新,如下图所示。

clip_image006

    之后,设备更换Driver模式,并且重新启动。重新启动以后,进入同一个页面,可以发现其Driver模式已经更换。

2. 新建工程

    如果已经升级到Visual Studio 2015 with Update 1的版本,那么该模板应该是已经有了。如果没有,可以去Windows IoT Core Project Templates extension page下载。

    创建工程时,选择File -> New Project -> Visual C++ -> Windows -> Windows IoT Core -> Arduino Wiring Application for Windows IoT Core,如下图所示。

clip_image008

    在默认的源程序中,就给出了闪烁LED灯的例子,其默认代码如下:

void setup()

{

// put your setup code here, to run once:

pinMode(GPIO_5, OUTPUT); // Configure the pin for OUTPUT so you can turn on the LED.

}

void loop()

{

// put your main code here, to run repeatedly:

digitalWrite(GPIO_5, LOW); // turn the LED off by making the voltage LOW

delay(500); // wait for a half second

digitalWrite(GPIO_5, HIGH); // turn the LED on by making the voltage HIGH

delay(500); // wait for a half second

}

    很显然,这个程序的结构和Arduino开发环境是一致的,在setup中初始化资源,在loop中循环执行任务。

3. 硬件连接

    按照下图方式连接LED灯、电阻和树莓派,注意LED灯长引脚为正极,短引脚为负极。

clip_image009

    有关引脚映射,可以参考这个网页:

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

4. 部署和调试

    选中工程,目标类型选择ARM,右键,选择属性菜单,在Machine Name中输入IP地址,认证类型中选择Universal模式。如下图所示。

clip_image011

    注意,认证类型一定要选择Universal,不然就无法调试。

    然后,就可以看到连接的LED闪烁了。

5. 存在的问题

    目前,从网页管理器启动已经部署的Ardunio应用程序尚存在一些问题。如下图,在网页管理器中选择已经部署的应用程序,点击start的时候,会弹出错误信息。

clip_image013

clip_image015

6. 调试模式的改变

    在Visual Studio 2015 Update 1中,更改了调试认证模式,由原来的None变为了Universal。这点需要开发者朋友注意。大家知道,原来msvsmon.exe这个进程是设备在开机时自启动的。现在,该进行非开机自启动,而是调试程序过程中才会启动。在程序调试结束以后,该进程自动退出。下图是非调试状态下,从网页管理器端看到的正在运行的进程。

clip_image017

    下图是调试程序时,从网页管理器端看到的正在运行的进程。

clip_image019

    参考链接:

l http://ms-iot.github.io/content/en-US/win10/Lightning.htm

l http://ms-iot.github.io/content/en-US/win10/ArduinoWiringProjectGuide.htm

l http://ms-iot.github.io/content/en-US/win10/LightningSetup.htm

l http://ms-iot.github.io/content/en-US/win10/ArduinoWiringPortingGuide.htm

l http://ms-iot.github.io/content/en-US/win10/samples/arduino-wiring/HelloBlinky.htm

posted on 2015-12-08 07:45  施炯  阅读(1948)  评论(1编辑  收藏  举报