Sunday, December 4, 2016

Windows 10 IoT

Windows 10 IoT
I am really not too sure how successful Windows 10 will be on IoT devices - a lot of extra bloat just to run the OS, which has a limited GUI on it as well. IoT, in my opinion, should be lightweight. Second to that, although it could just be me, developing in Visual Studio is a pain in the you know what.

However, I thought it would be interesting to keep looking at Win10 IoT on a Raspberry Pi - recall I took a stab at the World's Largest Arduino Maker contest (or whatever it was called), that gave extra credit for running on Win10 IoT and Azure. We'll get into Azure later.

So I recently loaded Win10 IoT back on a Raspberry Pi 2B that I had laying around and took to do the ubiquitous light an LED. And because I am a Python kinda guy, that is what I decided to use.

First, some links to get you started:
https://developer.microsoft.com/en-us/windows/iot/GetStarted.htm
https://www.visualstudio.com/downloads/
https://microsoft.github.io/PTVS/
https://www.visualstudio.com/vs/python/

I am definitely not a big fan of Visual Studio - VSCode is not too terrible, but unfortunately, there is not a module for VSCode to easily push Python code up to a Windows IoT device (there is one for NodeJS, but nothing for Python that I could find...) - so I am stuck with the full Visual Studio running in a Virtual Machine.

Couple of quick notes on Python in Visual Studio - there are not a ton of extra modules in VS - but it does have socket, which is very nice. For interacting with a Raspberry Pi's GPIO pins, you'll need WinGPIO: https://github.com/ms-iot/python/releases/download/v1.0Alpha/pywindevices.zip

Also, even though it says it is using Python 2.7 as an interpreter, some of the syntax is Python 3 - such as the print command -- print("Hello World!") -- and the socket module is a bit interesting, mainly that sending things back to the client, you have to encode for UTF-8 -- conn.send("Thanks for connecting\n".encode('utf-8'))

Obligatory LED Blinky Program:

    import _wingpio as gpio
    ledPin = 21 # Pin 40 on the RPi 2B
    gpio.setup(ledPin, gpio.OUT, gpio.PUD_OFF, initial=gpio.LOW)
    gpio.output(ledPin, gpio.HIGH)
    time.sleep(5)
    gpio.output(ledPin, gpio.LOW)

When configuring the Remote Device - right click on the name of your Solution/Program, select Properties, and then put in the IP for your Win10 Raspberry Pi.

It does take about a minute for the code to get compiled and pushed to the Raspberry Pi - so just be patient. the unfortunate part of that is if you code like I do and randomly leave off parenthesis or a function call - it takes close to a minute for it to fail out as well...

No comments:

Post a Comment