Closing the Windows IoT Core feedback loop using Azure Functions

Windows IoT Core is my preferred solution for the proof of concepts I build. The IoT stack is both easy and powerful and it’s a good choice to build real world solutions on too.

Getting telemetry in the Cloud using Microsoft Azure IoT Hub is easy also. And in my previous blog, I showed that adding live charts for BI only takes a couple of minutes.

There is one other thing that is very typical to IoT Hub. And that is sending commands back to devices. I use Azure Functions for that purpose.

In this blog, I will show you how to make use of this new, cheap and handy feature in Azure.

Update: Azure Functions is still in preview. I fixed some blocking issues in this blog due to current changes in this Azure resource (and this is a good thing).

Continue reading “Closing the Windows IoT Core feedback loop using Azure Functions”

A very simple complex IoT Hub example

The Microsoft Azure service called IoT Hub is now also available in West-Europe for a couple of weeks. To be precise, it’s available as a service in East Asia, East US, North Europe, Southeast Asia, West Europe and West US.

It is good to know that there are basically three flavours available: Free, S1 standard and S2 standard. The free edition only support one, uniquely registered, device which can send eight thousand messages a day. The other versions support messages to six million messages a day. If you want to support more devices/messages, please contact Microsoft 🙂

Note: You can have only one Free IoT Hub in your Azure subscription. And turning a S1 IoT Hub into the free one is not possible.

Keep in mind that messages have a certain size. If the actual size of a single message is bigger than 0.5KB (free version) or 4KB (S1 or S2) it will be counted as multiple messages.

Getting started with IoT Hub is not that hard. You can start with the fine documentation at the Azure website. But that documentation is still limited. Integrating with StreamAnalytics ea. is not described. So here I present a more elaborate example (but keep in mind the MSFT documentation).

Continue reading “A very simple complex IoT Hub example”

Add virtual Arduino ports to your UWP app using Firmata

This is part 4 of a series of blogs about device communication between Arduino, RaspberryPi etc:

  • Part 1: Using I2C to connect two Arduino Nano’s
  • Part 2: Using I2C between Rpi Master and Arduino Slave
  • Part 3: Use Bluetooth between Win 10 UWP and Arduino
  • Part 4: Add virtual Arduino ports to your UWP app using Firmata
  • Part 5: Custom Firmata function called by Windows 10 IoT Core
  • Part 6: Better long running custom Firmata functions
  • Part 7: Custom servo usage in Firmata
  • Part 8: Using NRF24L01+ modules between Arduino’s
  • Part 9: Cheap Arduino mesh using RF24 radio modules

I have shown in my previous post that it’s fairly easy to control an Arduino over Bluetooth.

This was done using a ‘custom’ protocol. I sent an integer value to let a LED blink that number of times on the Arduino.

But designing your own protocol is not always that easy. And I can recommend using industry-wide accepted protocols if available.

One of them is Firmata.

“Firmata is a protocol for communicating with microcontrollers from software on a computer (or smartphone/tablet, etc). The protocol can be implemented in firmware on any microcontroller architecture as well as software on any computer software package”

This sounds promising, doesn’t it?

Using Firmata,  it should be possible to access the ports on the Arduino directly from a UWP app, without extra custom code needed on the Arduino.

Of course, we NEED code on the Arduino, but that’s just a standard sketch, which is available in the examples library inside the Arduino IDE.

I just downloaded the latest version (now 2.5.1) of the Firmata Arduino library from the GIT repository because it was not yet available in the IDE. That’s why it is just in another place in the menu. Select the StandardFirmata sketch:


The Firmata protocol supports a connection between the UWP app and the Arduino using USB, Bluetooth and Wifi. In this example, we will use Bluetooth. There is one caveat, the baud rate used to communicate can vary with the board you use (it’s all about quality). Initially, it’s 57600 baud. I changed it into 9600 baud, just to make sure the communication speed will not be an issue.


Upload the sketch. Plug in your Bluetooth module on port 0 and 1 (cross the RX and DX lines). That’s all we need to do on the Arduino.

Just to check if everything is working, Microsoft already provides a nice app. Download the Windows Remote Arduino Experience for free, just to test your Firmata sketch.

If your Arduino is connected to your PC using USB, first try to talk to it using the USB connection. Here I have selected the Bluetooth module (and I selected the correct baud rate, equal to the rate in the sketch):


Either way, USB or Bluetooth, the outcome should be the same. The (digital) pin layout should be shown:


Now activate output pin 13.  This is the standard available LED op the Arduino board. This LED should be lit. And yes, this also works on my Windows Phone:


Note: I got this message “Pin configuration not received” the first times I tried to connect to my Arduino using Bluetooth:

pin config not received

If you get this message, just check the serial port connection (pin 0 and 1) and the baud rate in the sketch.

So now we will do the same communication in our own UWP app.

Start a new UWP template. Add the Bluetooth capability to the list of capabilities in the Package.appxmanifest.

To communicate to a Firmata device, we also need the NuGet package called “Windows-Remote-Arduino”:


Our main page needs the following controls:

    <Button Name="btnList" 
            Content="List" />
    <Button Name="btnStart"
            FontSize ="20" 
            Content="Start" />
    <Button Name="btnOn"
            Content="Led On" 
            IsEnabled="False" />
    <Button Name="btnOff" 
            Content="Led Off" 
            IsEnabled="False" />

And we need the following code-behind:

public sealed partial class MainPage : Page
    private BluetoothSerial _bluetooth;
    private RemoteDevice _arduino;
    public MainPage()
    private async void btnList_Click(object sender, 
                                       RoutedEventArgs e)
        var a = await BluetoothSerial.
        var b = a.First();
        var c = a.First(x => x.Name == "HC-05");
        var d = b.Name;
    private void btnStart_Click(object sender, 
                                       RoutedEventArgs e)
        _bluetooth = new BluetoothSerial("HC-05");
        _arduino = new RemoteDevice(_bluetooth);
        _bluetooth.ConnectionLost += 
        _bluetooth.ConnectionFailed +=
        _bluetooth.ConnectionEstablished += 
        _bluetooth.begin(0, SerialConfig.SERIAL_8N1);
    private void _bluetooth_ConnectionLost(string message)
        throw new NotImplementedException();
    private void _bluetooth_ConnectionFailed(string message)
        throw new NotImplementedException();
    private void OnConnectionEstablished()
        var action = Dispatcher.RunAsync(
                            new DispatchedHandler(() =>
            btnOn.IsEnabled = true;
            btnOff.IsEnabled = false;
    private void btnOn_Click(object sender, RoutedEventArgs e)
        //turn the LED, connected to pin 13, ON
        _arduino.digitalWrite(13, PinState.HIGH);
        var action = Dispatcher.RunAsync(
                           new DispatchedHandler(() =>
            btnOn.IsEnabled = false;
            btnOff.IsEnabled = true;
    private void btnOff_Click(object sender, RoutedEventArgs e)
        //turn the LED connected to pin 13 OFF
        _arduino.digitalWrite(13, PinState.LOW);
        var action = Dispatcher.RunAsync(
                           new DispatchedHandler(() =>
            btnOn.IsEnabled = true;
            btnOff.IsEnabled = false;

First of all, we have to connect to the Bluetooth module. I added placeholder code for the ConnectionLost en ConnectionFailed events. Just so you can act on these circumstances (in case you get the name of the device wrong).

Note that the baud rate is set to 0 (zero). It just works 🙂

When the Bluetooth connection is up, the On button becomes available. Look at the code, we can write LOW or HIGH to digital ports. So we write to the output port 13. The LED on the board will be lit or unlit:


The Arduino class also supports reading and writing to analog ports. And I2C communication seems to be possible too.

Letting the LED blink several times, as in the previous blog post, is now trivial. It can be programmed just in C#.

The drawback of Firmata is that the real-time behavior of the Arduino is now limited by the speed of the calling UWP and the speed of the communication. And complex communication with exotic modules over several pins with specific timing will be hard or even impossible.

So if you need real-time interaction and still want to use Firmata, take a look at the Ignite presentation Windows IoT, UWP and the Remote Wiring API by Mitch Denny. He adds custom code to the Firmata sketch and executes it by name. Then he listens for the response which is received using an event handler. It acts just like a stored procedure in a database.

Update: The source code of the Windows Remote Arduino Experience app is available at GitHub.

Documenting your IoT projects using Fritzing

I have build several IoT projects for my Gadgeteer and Raspberry Pi projects.

Although , as a software developer, figuring out how everything works with these intriguing components is challenging, the real challenge is documenting.

And with documenting I mean the choice of components, the layout and wiring, the use of GPIO ports, the code, pictures, etc.

Yes, it’s nice to see your projects succeed but it’s even better if you can tear everything down and rebuild it again. And to see it’s still working 🙂

I was looking at Hackster for some information and there they were shown: nice layout schema’s with in the right bottom corner the word ‘Fritzing’.

So I went do the site:

“Fritzing is an open-source hardware initiative that makes electronics accessible as a creative material for anyone. We offer a software tool, a community website and services in the spirit of Processing and Arduino, fostering a creative ecosystem that allows users to document their prototypes, share them with others, teach electronics in a classroom, and layout and manufacture professional pcbs.”

Then I downloaded the Win32 tool and it is pretty easy to use:


What I use is the breadboard function. Just pick the component you have used from the parts list and place them on the breadboard of your choice. Each component has several options, properties. And you can flip and rotate them. And you can simply drag lines which will become wires.

Tip: change the color of the wires. Use red and black for 5V and ground. Your readers like that a lot.


Here I added a Raspberry Pi, a breadboard, a led and a resistor. Se that I can add a header and some comments too.

It’s easy to export this as a picture:


But if you are really proud of this project you can share it on the Fritzing site:


Do not forget to add a picture or video to make the project more attractive (Use a better camera, please):


This proofs your project is really working. That way you take a lot of doubt away from your readers.

So please give it a try. Share your projects here in the comments.