Sergii Baidachnyi

Blog about technologies

Archive for May 2015

Windows 10: How to use IoT extension for Raspberry Pi 2 (part 1)

leave a comment »

If you have already installed Windows 10 on Raspberry it’s time to discuss how to use pins and I2C there. Of course, if you are going to deploy an application which doesn’t work with GPIO, you don’t have to do anything special – you need to create the same Universal application like for desktop or phone using C# or other languages and deploy it using ARM platform selection directly from Visual Studio. But GPIO is device-specific feature for which it makes no sense to include it to the common library. So, if you are going to use some IoT specific features you need to add IoT Extension to you project.

clip_image002

This extension declares just two contracts: Windows.Devices.DevicesLowLevelContract and Windows.System.SystemManagementContract. It’s easy to find this declarations if you go to the following folder C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsIoT\10.0.10069.0 and check SDKManifest.xaml. SystemManagement doesn’t contain anything special – just classes which help shutdown the device and change time zone. But DevicesLowLevelContract contains many important classes. Let’s looks at the Raspberry and see that we can achieve thanks to these classes.

clip_image004

In case of GPIO you can use the yellow pins to send signals to sensors or receive data from them. On Raspberry, all pins generate 3.3 volts of voltage. Pink pins supports SPI protocol and you can connect up to two devices/sensors there (probably three but I never made this experiment). Finally, blue pins allow to use I2C hub which supports more than hundred devices/sensors. Of course, GND pins are for ground and there is for power pins (two 5V pins and two 3.3V pins).

Let’s start with GPIO. You can find necessary classes (and enumeration types) in Windows.Devices.Gpio namespace and they allow developers to control GPIO pins on the board. The first class there is GpioController which allows to get access to controller and get reference to needed pins. If you are going to use GPIO you need to start with calling of GetDefault method which return reference to current GPIO controller (if exist):

var controller=GpioController.GetDefault();

If you are going to write really universal code you need to check if controller is null. If it is, your device doesn’t have GPIO (desktop, phone etc.) It’s very useful because starting with Windows 10 we have Universal platform and you can run the same binary anywhere.

Once you have access to controller you can try to get reference to pins. OpenPin method allows to get reference to pin lock it exclusively or leave it in shared mode. Of course, this method doesn’t help you to setup the pin and just return reference to GpioPin object. There is the same thing like for GpioController – you need to check if returned reference is not null, because other processes could lock the pin for own purposes.

var pin = controller.OpenPin(0); if (pin == null) { return; }

OpenPin method should get number of the pin and you should use the same numbers like on the image above. Finally, if you got access to the pin you can try to work with it. There are three important methods like SetDriveMode, Read and Write. With the first one you can setup the pin like input or output pin. Read and Write methods allow to send or receive signal there.

So, if you already worked with some micro boards, you will not find anything special but if you are new in IoT you can start with creation of a simple Blinky project, which Microsoft published here.

Of course, more interesting classes are located in Windows.Devices.I2C and Windows.Devices.SPI namespaces. Finally I got my MPU6050 sensor, so next time we will get data from there.

Written by Sergiy Baydachnyy

05/08/2015 at 6:59 AM

Posted in IoT

Tagged with ,

Raspberry Pi 2 and Windows 10: My first experience

leave a comment »

Finally, Microsoft published Windows 10 preview build for Raspberry Pi 2 (and not just for Raspberry). So, if you have Raspberry, you can visit https://dev.windows.com/en-US/iot and download the build and setup instructions.

Of course, it’s easy to prepare an SD card and put it to Raspberry but pay special attention that:

· You need to use microSD card class 10. I missed this requirement and was very upset when found that my Raspberry is not even trying to start. When I checked manual once again I checked my SD and found that it has class 4! So, I changed it and everything started working fine;

· First start requires much time to finish all things. So, you need to be patient;

· You need to connect your board to network using network cable. It’s a preview and many famous WiFi adapters don’t work on Raspberry right now. So, if your application connects to Internet you will need to use network cable all the time but if you want to create a simple LED project you need access to network at least for deploying your project;

If everything is ok you will see Raspberry image and important information like device name and IP address on the screen. So, your device is ready and it’s time to establish connection between your PC and Raspberry. In order to do it you can visit the following page to setup connection using PowerShell. I tried to make it several times and discovered some issues on my PC. Because I am not admin it was very hard to understand what happened there, so I want to share all stoppers I had:

· Set-Item issue – when I ran this command I got an exception with complicated message about private and public networks and some advice to change network from Public to Private. When I checked my network settings (Network and Sharing Center) I found that my network is Private but I have Virtual Ethernet Adapter which was created by Visual Studio installation. I simply disabled it and the exception was gone;

· Enter-PsSession – when I ran this command I got one more exception “The WinRM client cannot process the request. If the authentication scheme is different from Kerberos…” Once I got it I spent much time to understand how to setup WinRM but my knowledge in this area is not enough, so I selected the simplest way: I ran Gpedit.msc and navigated to Local Computer Policy->Computer Configuration->Administrative Templates->Windows Components->Windows Remote Management->WinRM Client. There I enabled Allow unencrypted traffic and Trusted Hosts and, additionally, I enabled all hosts there. And the problem was gone. I hope that you can find a way to configure it in a better way but I simply didn’t have much time to check all combinations because I wanted to start development!;

clip_image002

Once you connect to your Raspberry you can change password, device name, run some configuration cmdlets etc. Pay special attention that Raspberry supports two modes: headed and headless (with GUI and without GUI). You can read more about the modes here.

Right after you establish connection between your PC and Raspberry you can try to develop something. Thanks to Visual Studio it’s very easy to develop, deploy and debug solutions on Raspberry. Raspberry runs Remote Debuger by default so you should not make any additional configuration.

In order to start you need to select the language. You can select between Node.js, Python and standard languages for Universal applications like C#. Of course, I decided to use C# but you can easily install Python or Node.js tools from Connect site. So, in order to start you need to create a simple Universal application, change platform to ARM and select Remote Machine for deploying and debugging.

clip_image004

Finally I develop and deploy my first application for Raspberry:

clip_image006

Written by Sergiy Baydachnyy

05/04/2015 at 8:38 AM