Windows 8.1 IoT: Windows Remote Arduino and Universal apps

A Windows 8.1 Universal app can be built upon the Remote-Wiring library such that the app can interact with an Arduino device running Firmata. An app similar to the Windows Remote Arduino “Blinky” example, but with feature additions, is developed. It performs GPIO (output AND input) as well as some analog IO. The app runs on a Win 8.1 desktop, phone and RT Surface. The UI has some extra XAML “bells and whistles”.

[1] Set up the Bluetooth communication with the Arduino device.

USB or Bluetooth can be used for the Firmata communications between the Arduino device and the Windows device. For Windows 10 both can be used, whereas for Windows 8.1 only Bluetooth can be used. Therefore, for this version of the app, that will be used. I used a Sparkfun Bluetooth Mate Gold[1] whereas the Sparkfun Bluetooth Mate Silver was used with the “Blinky” example referenced above. The main difference is the range of the Gold is up to 100m whereas that of the Silver is 10m. The default handshaking settings are also different. These both have a TTL level UART interface that can be used both for configuring the operating mode of the Bluetooth device and for interacting with the Arduino serial port.

Figure 1 Sparkfun Bluetooth Mate Gold

Figure 2 Bluetooth Mate Gold Pins, including factory reset

If you need to configure the Bluetooth device, a Sparkfun or Freetronics USB-Serial or Free device can be used to configure the device via a desktop serial terminal. You can also factory reset the device to default settings by connecting the PIO6 (its actually PIO4) pin to high, and toggle three times.

Bluetooth Mate has the same pin out as the Sparkfun FTDI Basic, and so they can be used interchangeably. you cannot directly plug the Bluetooth Mate to an FTDI Basic board (you’ll have to swap TX and RX). That configuration can be used with a desktop serial terminal, with the FTDI device USB connected to the desktop, to configure the Bluetooth device (or to use Bluetooth device for serial communications from the desktop.

The default TTL UART serial settings are:

· Baud rate 115,200

· 8 bits

· No Parity

· 1 stop bit

· Hardware flow control enabled (on Mate Silver this is None)

· Serial Port Profile (SPP): FireFly-WXYZ
where WXYZ is the last 4 digits of the device's BT MAC Address.

The Firmata configuration is for a Baud rate of 57600 which needs to be changed or the Bluetooth device configured for that. For this exercise, we will modify the Firmata configuration, which is the easier approach. The Hardware flow of control also can be handled by configuring the Bluetooth device, but for this exercise is handled by connecting RTS to CTS.

Whist the Bluetooth device can be mounted on a Breadboard and connected to the Arduino device from there, I elected to mount a socket for it on a Prototyping Shield.

A 6 pin Arduino Shield Header was soldered onto the Bluetooth device at the TTL UART pins with the socket facing outwards. The pins were bent 900 downwards so that the device can be plugged vertically into another shield header. The BT socket then can be used to directly connect it to similarly mounted FTDI Basic module if configuration is required. A wire was later soldered to PIO6 (PIO4) on the Bluetooth module, for factory resetting.

An 8 shield header was mounted in the middle of the prototype shield at the bottom. Also add headers at the outside of the shield so that it can plug directly into the Uno.

Figure 4 Arduino Prototype Shield for mounting the Bluetooth module

The Bluetooth module is then inserted facing the GPIO pins, towards the pins 0 and 1 (Rx/Tx)., leaving the yellow location clear. One of those can be used a temporary location for the factory reset wire.

Figure 6 Mounted Bluetooth module on Arduino device

[2] Set up Firmata

Note:The Arduino Uno’s UART Pins 0 and 1 are unavailable when it is being programmed via USB from the Arduino IDE. These same pins are what are connected to the Bluetooth module’s TTL UART interface when it is interfaced for Firmata communications. Therefore, when the Arduino device is to be programmed in this section, the Bluetooth device should not be connected.

2.1 Assuming that you have previously developed for an Arduino (Uno) device, create a new Standard Firmata shield:

2.2 There is one change to be made, the Baud rate. In the IDE, do a search for 57600. Replace it 115200. Save the Sketch, I called it Firmata_115200. Program the Uno and this part is done.

[3] Set up the Universal App Firmata software stack

The software stack consists of three layers:

The Remote-Wiring API implements properties (configuration), methods and event at a conceptually high level for Arduino hardware interaction. For example, GPIO (eg Get and Set Pin, On Pin changed etc). It communicates with the Firmata layer using the Firmata protocol. Firmata communicates down the stack via the serial protocol that is implemented as Bluetooth and USB-Serial transport layers in the Serial layer. The USB option isn’t available for Windows 8.1.

Both contain Windows 8.1 and Windows 10 versions. Whilst both versions’ Windows 10 versions will build, I have found that the second one’s Windows 8.1 won’t build. I used the Visual Studio 2015 RC version:

Microsoft Visual Studio Community 2015 RC

Version 14.0.22823.1 D14REL

Microsoft .NET Framework

Version 4.6.00076

3.1 Download the first version. To do so properly, you need to clone the repository (don’t download the zip):

Install git or GitHub

In the git shell or GitHub Desktop Shell (it’s Powershell), enter the following from a suitable directory:

The latter two folders (win8_1 and win10) are just example apps (including the “blinky” example) which we will ignore for now. Both Maker versions make use of the same sources folder so for Windows 8.1 we need just:

to a suitable folder. I suggest one at the root of the drive, say, c:\wras as I have found that you can get some errors with an ARM build to do with path names being too long. You might want to also copy the .md files for reference. These can be opened in VS.

3.2 Open the solution file in Microsoft.Maker.win8_1

3.3 Set the target to Win32 build the solution.

Six builds are done. One for the Desktop and one for Windows Phone for each of the three layers in the software stack. Note both versions in each layer have a common Shared subproject. Code that is common to both versions can be placed here. This is a useful way to implement event handlers for both versions once as common code. The XAML code is still specific to each target though .. Windows 10 takes this one step further with UWP.

3.4 Do same for the ARM configuration. If you have an x64 machine, then you might like to try that build as well.

[4] Create the HW LED Universal app

For this initial version of the app/s, a software button will turn a hardware LED on and another will turn it off. The LED will be connected to GPIO pin 5.

The “Blinky” documentation says that there are a number of ways to get and use these libraries. Ultimately Nuget will be the way but that is not yet available. You can reference these built versions in a general manner on your development system, The easiest way is to just add the required Universal app to the solution and reference them. We will use that method.

4.1 Add a new C# Windows 8.1 Blank Universal app to the solution. (Need to have installed the Windows 8.1 templates when installing VS):

Give it a suitable name. I called mine wrau: Windows Remote Arduino Universal app
Note that there are two projects (one for the desktop and one for the phone), plus a shared subproject.

The Serial and Bluetooth capabilities are needed in the pacakage manifest:

4.2 Open the package.appmanifest in the text editor (not its GUI) by View Code. The Internet Client capability is included at the bottom. Modify this section to:

[5] Deploying and testing the Universal apps.

In this section we will wire up the hardware LED to the Arduino device and run the app on the desktop, an RT Surface (ie ARM) and a Windows Phone 8.1

Test on your desktop

5.1 Set the Desktop app as the Startup Project

5.2 Set the target to Win32, Windows 8.1 and Local Machine. Rebuild the desktop UA.

5.3 Connect the Arduino Pin 5 to a hardware LED. Provide GND, VCC and a suitable resistor in series.

As mentioned in a previous blog with respect to Windows 10 IoT Raspberry PI 2 GPIO I use a development board for implementing my testing IO such as LEDs, switches etc. If you do not have a similar board you might like to use the “Blinky” hardware configuration but you will need to reverse the polarity of pin setting in button handlers.

5.4 Power up the Arduino device and pair up the Bluetooth module with your desktop (Passkey=1234). .. I’ll assume you know how to do this.

5.5. Run the app.

5.6 It will probably ask you whether it’s OK for the app to connect to the Bluetooth device .. OK

5.7 Test the functionality of the app. Set a breakpoint in the button handler/s and check that you can debug.

5.8 Repeat 4.1 to 4.6 for x64 if you have a 64 bit desktop.

5.9 Turn off Bluetooth on your desktop

Now to test your Windows 8.1 Phone, assuming the phone is configured for development.

5.10 Turn on your phone, go to Settings/Bluetooth and turn it on. Pair with the Bluetooth module (Passkey = 1234).

5.11 Set the Phone UA as the Startup Project

5.12 Set the Target to ARM, Windows Phone 8.1, Device and rebuild

5.11 Connect up the phone via USB Serial to the desktop and deploy the app.

5.12 Test run the app and check the functionality. You are now “wireless” .. Cool J
Set a breakpoint in the button handler/s and check that you can debug.

Now to test the RT Surface if you have one (I’m testing on an RT Surface 2).

5.13 You need to download and install the Visual Studio 2015 Remote Debugger ARM version on the Surface. This needs to be the Visual Studio 2015 version, the 2013 version won’t work. Do so. Configure it t0 use No Authentication and allow debugging

Although installation sets up suitable Firewall rules, I normally turn off the Firewall for development, on the target.

5.14 Determine the IP address of the Surface.

5.15 Set the Target to ARM, Windows 8.1 (Not phone) and Remote Machine. The following dialog will appear..If not then go to the project Properties-Debug tab. Enter the IP address of the target and set no authentication.

5.16 Rebuild the desktop UA

5.17 Deploy and test the app on the Surface.

[6] “Pretty up” the UI

The following will pretty up the UI and add Bluetooth Connect and Disconnect buttons.

6.4 Comment out or remove the following line from MainPageConstructor as its now in the Connect button handler:

bluetooth.begin(115200, SerialConfig.SERIAL_8N1);

6.5 Add the following state management to the OnButton handler

In OnButton_Cllick()

this.OffButton.IsEnabled = true;

this.OnButton.IsEnabled = false;

6.6 And the following to the OffButton handler:

In OffButton_Click

this.OffButton.IsEnabled = false;

this.OnButton.IsEnabled = true;

6.7 Deploy and test the app on all three (4) targets as in section 5

[7] Add a Pushbutton input

In this extension to the Windows 8.1 Universal apps, a pushbutton GPIO input, at Arduino Pin 5, is facilitated and its state is displayed in the UI. The input will initially be sensed by periodically reading the value.
The functionality will then be improved by implementing a handler for the DigitalPinChanged event

7.1 Modify the Grid control in the UI XAML code for both UA as follows: