Sergiy Baydachnyy

Blog about technologies

Archive for the ‘IoT’ Category

Microsoft Canada at Vancouver Mini Maker Faire

leave a comment »

Last weekend I got a chance to participate in Vancouver Mini Maker Faire event. I still don’t understand why it’s called “Mini” because the exhibition filled all the space at PNE Forum including outdoor exposition. And, of course, we had our own booth there as well. So, what was Microsoft doing there?

image

Half of our exposition demonstrated ability of Visual Studio to support IoT projects for different boards like Arduino, Netduino, Raspberry Pi 2 etc. I have developed two rovers based on EZ-B controller and based on Arduino. In case of EZ-Robot I used UniversalBot project for developing Windows 10 applications. For Arduino I used the instructions which you can find on windowsondevices.com but you can use Visual Studio to develop and deploy Arduino applications directly using Visual Micro plug-in. Additionally I have developed the drone based on Netduino board, so I used .NET Micro Framework and C# to develop all stabilization algorithms there.

image

The second part of our exposition was around Kinect and 3D printing. Thanks to 3D printing support in Windows you can develop your own applications very quickly without thinking about how to cut the model in slices or generate G-code. Additionally, you can use existing 3D printing software like 3D Builder to create own models and print it.

image

Additionally, 3D Builder supports Kinect devices to 3D scan of existing objects.

Of course, we used Kinect not just for 3D scanning but for entertainment as well. All attendees have a chance to dance in our Xbox One area where we used Kinect as well and installed Just Dance Kinect ready game.

I hope that everybody had some fun visiting out booth as well as all other expositions there.

Advertisements

Written by Sergiy Baydachnyy

06/19/2015 at 11:51 PM

Posted in IoT

Tagged with

Raspberry PI 2 and analog input

leave a comment »

Compare to Arduino, Raspberry PI 2 doesn’t have analog pins and even PWM pins. If you check IoT extension for Universal Windows Platform you will discover three sets of classes: I2C, SPI and GPIO. The last one allows to use Raspberry GPIO for sending/receiving high or low voltage only. So, if you want to create a drone or cool robot based on Raspberry Pi 2 and powered by Windows 10, you need to answer the following questions:

· How to read analog signals;

· How to emulate PWM (pulse width modulation);

· How to read digital signals from various digital sensors (if these signals are not LOW or HIGH);

In this post I am going to answer the first question.

Because GPIO of Raspberry doesn’t have any PWM features we need to use external convertors which help us to transform analog signal to digital. I would recommend to use convertors from Microchip Technology and there is the great selection of different chips: MCP3002, MCP3008, MCP3208 etc. I bought MCP3008 because it supports up to 8 channels and represent analog data in 10 bits format. Because Arduino and Netduino use the same format (from 0 to 1024) I am used to using 10 bits.

clip_image001

MCP3008 works based on SPI bus, so we should use SPI bus on Raspberry. In order to do it I connected CLK leg of the chip to pin SPI0 CSLK (19), D(out) leg to SPI0 MISO pin (21), D(in) leg to SPI0 MOSI (23) and CS/SHDN to SPI0 CS0 (24). V(dd) and V(ref) legs I connected to power and DGND to the ground.

clip_image003

I have analog photoresistor sensor only. So, I used just channel 0 and connect signal leg of the sensor to CH0.

clip_image005

Below you can find my code which you can copy and paste to MainPage.xaml.cs of your Universal application. I didn’t make any interface and just used Debug class to print sensor’s data to Output window:

byte[] readBuffer = new byte[3]; byte[] writeBuffer = new byte[3] { 0x06, 0x00, 0x00 }; private SpiDevice spi; private DispatcherTimer timer; private void Timer_Tick(object sender, object e) { spi.TransferFullDuplex(writeBuffer, readBuffer); int result = readBuffer[1] & 0x07; result <<= 8; result += readBuffer[2]; result >>= 1; Debug.WriteLine(result.ToString()); } protected async override void OnNavigatedTo(NavigationEventArgs e) { await StartSPI(); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(500); this.timer.Tick += Timer_Tick; this.timer.Start(); base.OnNavigatedTo(e); } private async Task StartSPI() { try { var settings = new SpiConnectionSettings(0); settings.ClockFrequency = 5000000; settings.Mode = SpiMode.Mode0; string spiAqs = SpiDevice.GetDeviceSelector("SPI0"); var deviceInfo = await DeviceInformation.FindAllAsync(spiAqs); spi = await SpiDevice.FromIdAsync(deviceInfo[0].Id, settings); } catch (Exception ex) { throw new Exception("SPI Initialization Failed", ex); } }

Written by Sergiy Baydachnyy

06/10/2015 at 9:18 AM

Posted in IoT, Windows 10

Tagged with

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

with one comment

In the previous post we discussed how to add extensions to Universal projects and made a short overview to GPIO classes. Today I am going to continue the overview of the IoT extension and we will discuss I2C hub and classes there.

Last week I received MPU6050 sensor which provides data from gyroscope and accelerometer and is very useful for people who would like to build own drones and helicopters. You can find many different boards in the market including just 6050 chip. In my case I bought this one from http://robotshop.ca.

clip_image002

This sensor doesn’t require soldering and it contains 5V to 3.3V convertor (6050 chip uses 3.3V), which allows to use power from ESC or other boards with 5V power pins.

MPU 6050 uses I2C hub to communicate. So, to get the sensor ready to work you need to connect 5V and GND pins on Raspberry to VCC and GND on the sensor. Additionally you need to connect SDA and SCL pins there. This sensor doesn’t have any leds and it’s not easy to understand if everything is OK. So, the simplest way to check if it works is to start developing something.

All needed classes you can find in Windows.Devices.I2c namespace and the first one is I2cDevice. Each device, which you connect using I2C hub, should be associated with object of I2cDevice class and thanks to this object developers can communicate to device. The most common methods there are Read and Write which are working with array of bytes in order to receive or send data. But in many cases you need to send data to device to ask something and read response from there. In order to avoid calling of two methods, I2CDevice class supports WriteRead method. This method has two parameters as arrays of bytes. The first array contains data which you are going to send to device and the second one – buffer for data from device.

Thanks to I2cDevice, it’s easy to communicate with devices but in order to get reference to the I2cDevice object you need to accomplish several tasks.

First of all you need to get reference to I2C device on the board (not your sensor but existing I2C pins). Microsoft uses the same approach as for all other devices like Bluetooth, WiFi etc. You need to use friendly name to create query string for the device and try to find the device on the board. GetdeviceSelector method of I2cDevice class allows to create the query string and you should use I2C1 friendly name there. In order to find information about the existing device you should use FindAllAsync method of DeviceInformation class. This method returns information about available I2C device and you can use this information in order to create I2cDevice object. Next step you need to create connection string for your sensor. It’s easy to do using I2cConnectionString class passing address of the sensor to the constructor of the class. Once you have information about I2C on your board and connection string for external device/sensor you can create I2cDevice object using FromIdAsync method.

So, for my MPU 6050 I created the following code:

class MPU6050 { //I2C address private const byte MPUAddress = 0xD2>>1; private I2cDevice mpu5060device; public async Task BeginAsync() { string advanced_query_syntax = I2cDevice.GetDeviceSelector("I2C1"); DeviceInformationCollection device_information_collection = await DeviceInformation.FindAllAsync(advanced_query_syntax); string deviceId = device_information_collection[0].Id; I2cConnectionSettings mpu_connection = new I2cConnectionSettings(MPUAddress); mpu_connection.BusSpeed = I2cBusSpeed.FastMode; mpu_connection.SharingMode = I2cSharingMode.Shared; mpu5060device = await I2cDevice.FromIdAsync(deviceId, mpu_connection); mpuInit(); } }

mpuInit method there is sending initial values to the sensor and I will describe it below. MPUAddress should be 0xD2 according to documentation but we need to take just 7 bits of this value so I moved the value to one bit right.

Once we have I2cDevice object we can start to work with the device. It’s not so easy because MPU 6050 has lots of registers and you need to understand most of them. Additionally, you need to initialize the sensor to get values using needed scale range etc. Let’s see several registers there:

· 0x6B – power management. It’s possible to setup different settings related to power mode but the most important bit there is bit number seven. Thanks to this bit you can set the sensor to initial state;

· 0x3B – 0x40 – accelerometer data. There are 6 bytes which contain data for x, y and z axis. Because two bytes are required to present the data per each axis there are 6 bytes (not 3). So, to form result you need to use the first byte as a high part of short (int16) and the second one – as a low byte;

· 0x41 – 0x42 – two bytes which represent temperature there – high and low byte;

· 0x43 – 0x48 – 6 bytes for gyroscope data (as for accelerometer);

So, you can use mpuInit method to setup initial state of the sensor. For example, you can resent the sensor using the following command:

mpu5060device.Write(new byte[] { 0x6B, 0x80 });

In order to measure something you can use WriteRead method. I don’t want to create much code in this post, so I want to show how to measure temperature only. You can use the following code:

byte mpuRegRead(byte regAddr) { byte[] data=new byte[1]; mpu5060device.WriteRead(new byte[] { regAddr },data); return data[0]; } public double mpuGetTemperature() { double temperature; short calc = 0; byte []data = new byte[2]; data[0] = mpuRegRead(MPU_REG_TEMP_OUT_H);//0x41 data[1] = mpuRegRead(MPU_REG_TEMP_OUT_L);//0x42 calc = (short)((data[0] << 8) | data[1]); temperature = (calc / 340.0) + 36.53; return temperature; }

Later I am going to publish my MPU6050 class on GitHub as well as some additional classes which you can use from C# in order to work with accelerometer and other sensor.

Written by Sergiy Baydachnyy

06/10/2015 at 9:11 AM

Posted in IoT, Windows 10

Tagged with

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

IoT: I2C and Galileo board

leave a comment »

I spent last weekend finishing my first drone. It’s nothing special, I bought some standard components like brushless motors with ESCs, a radio receiver and transmitter and flight control board. The last one is compatible with Arduino and supports MultiWii open source project which helps manage drones based on gyroscope and accelerometer sensors. But it didn’t satisfy me because the drone in the existing configuration is just a toy and it doesn’t contain any brain. And, frankly speaking, Arduino board is not a good choice to make some sort of brain due to performance and memory limitations. So, if you want to develop a drone which will be able to fly “without you”, analyze existing environment and execute tasks like intercepting other drones, you need something more powerful. I believe that Raspberry Pi 2 is the best choice but I still don’t have Window 10 image there but I have wrote it before Build, so I decided to use Galileo 2. It’s very powerful and should satisfy my requirements except of tasks related to video (due to lack of GPU).

If you are going to add some brain to your drone you can follow one of the two ways. In the first one you will keep the existing flight control board and will place “your brain” like proxy between radio receiver and flight control board. In this case, the flight control board will continue to stabilize your drone but will get commands from Galileo and not from receiver, and Galileo can support several modes like autopilot and manual modes. The second way requires to remove your flight control board and implement the same logic in “the brain”. Of course, in this case you need to add some sensors like accelerometer and gyroscope to Galileo and analyze all incoming data from them. Obviously, the second way is more complex and you should not follow it in the most cases. But if you really want to develop a drone which will intercept enemy drones and use different flying techniques you need to implement your own code there. Because I want to have maximum fun I decided to follow the second way.

Of course, before implementing some algorithms I should think if it’s possible to connect all needed things to my Galileo. Since Galileo is Arduino compatible, there are 6 PWM pins which I can use to operate 6 brushless motors that are enough for my hexacopter. Additionally, I need 4 input pins in order to get data. Everything might be good but I need to connect some sensors as well. Frankly speaking, I need to connect many sensors like accelerometer and gyroscope to stabilize my drone, magnetometer, and GPS to navigate the drone to a goal, airspeed sensor for better navigation, distance sensor for better landing, GPRS to get some command and send logs when the drone is out of range etc. Looks like that standard IO pins will not satisfy all my requirements. So, it’s time to look at the board and find two more pins which are marked like SCL and SDA.

SCL (clock) and SDA (data) are implementation of I2C bus (Inter-Integrated Circuit) which allows to make communications between various integrated circuits using just two wires (SCL and SDA). And what is more important you can use the I2C to connect lots of different circuits in any order because each device has its own address and if you want to send or receive data from particular device you need to use this address, so other devices will ignore your message. That’s why you can find thousands of sensors in the market which support I2C because in Arduino world it’s the best way to manage hundred sensors using one board only.

So, if you are going to build something complex you need to check if selected sensor supports I2C before buying it. I checked all my sensors and found that I have SparkFun weather shield only which supports I2C. So, right now I am going to work with the shield.

The weather shield might contains several sensors like GPS and wind but all editions contain humidity and pressure sensors and you can work with any of them directly. In this case, the shield is just a board which combines all sensors together and allows to use I2C. So, the best way to start working there is to check datasheet for particular sensor there. Because temperature is something clear for me, I decided to use humidity sensor there for my experiments. You can find the datasheet for this sensor using the following link.

There are the following things in the datasheet which we are going to use in our application:

· The humidity sensor requires up to 50 ms to make measurement of temperature (page 4). It’s maximum value for 14 bits resolution and we definitely can count on it;

· The device address is 0x80 including data bit (page 9). I2C devices has 7 bits addresses but eight (zero bit) bit shows direction of command (read or write). It’s not so important for us because Arduino library uses different approach;

· 0xE3 and 0xF3 are codes for commands to the sensor which will request to measure temperature (page 10). The first one is hold I2C channel while measurement in progress but the second one allows to make other operations at the same time. We are going to use the second one;

· Request to the humidity sensor returns 3 bytes (page 10): 14 bits of data, 2 bits for status and 8 bits for checksum. The status allows to see if you get temperature or humidity and checksum allows to check the data;

· You can measure temperature like -46.85 + 175.72*data/65536 (page 14);

So, right now we are ready to write some code. I am not going to check errors from sensors or something like it in order to make the code as simple as possible. The good news there that you should not work with SDA, SCL pins directly. Arduino supports Wire library and it was successfully to Galileo platform as well. Using the library I developed the following code:

#include "stdafx.h" #include "arduino.h" #include "Wire.h" int _tmain(int argc, _TCHAR* argv[]) { return RunArduinoSketch(); } void setup() { Wire.begin(); } const byte humAddress = 0x40; const uint8_t measureTemp = 0xF3; void loop() { Wire.beginTransmission(humAddress); Wire.write(measureTemp); Wire.endTransmission(); delay(50); Wire.requestFrom(humAddress, 3); byte msb, lsb, checksum; msb = Wire.read(); lsb = Wire.read(); checksum = Wire.read(); unsigned int raw = ((unsigned int)msb << 8) | (unsigned int)lsb; raw = raw&0xFFFC; float rh = -46.85 + 175.72 * raw / (float)65536; Log("%f\n", rh); delay(1000); }

 

In order to start working with Wire library you need to include Wire.h and prepare I2C using Wire.begin. Of course, setup function is the best place to do it. Right after you are ready to talk to I2C device you need to call Wire.beginTransmission. And there is a trick because this function requires an address. You should not use 0 bit for direction instead of it you need to fill first 7 bits with the address. So, if we have 0x80 address including direction bit we need to shift 7 last bits right and get 0x40 – this address we should use in all commands. In order to write something to I2C we can use Wire.write and I am sending 0xF3 command in order to ask the sensor to measure temperature. Finally I need to call endTransmittion in order to stop communication and wait for 50 ms to give the sensor some time to make measurement.

In 50 ms we can send the second command and ask data from sensor. Thanks to requestFrom we should not think about begin, end and direction bits – we need to pass the address and number of bytes only. If data is available we can use read to get it byte by byte.

Of course, it’s better to check if data is available and correct but in general this code will work as well and it’s not so bad. The hardest part here is to understand the datasheet. It’s not easy sometimes and you need to read many pages.

I hope that next week I will get my MPU6050 and will show how to use it and combine accelerometer and gyros data using I2C bus.

Written by Sergiy Baydachnyy

04/30/2015 at 7:47 PM

Posted in IoT

Tagged with

IoT: Raspberry Pi 2, C# and blinking LED

leave a comment »

This week I decided to visit Lee’s Electronic in order to buy some sensors and capacitors for my future posts and, just in case, I asked if they have Raspberry PI 2 boards. The answer was: “Yes, we just received the package with plenty of them. Do you need just one?”

Of course, I was happy to get Raspberry Pi 2 because I still didn’t make any experiments with this board. I have a Raspberry Pi B+ but it’s “too lazy” for IoT projects. Of course, it has better CPU than Arduino and Netduino but developer experience is crazy there. So, I decided to avoid Raspberry up to more complex projects, which require cameras, GPU etc. But Raspberry Pi 2 should have better performance. I even heard that it should be in 6 times fasterJ So, I decided to buy a board.

So, Raspberry Pi 2 has the same form factor like B+ model.

clip_image002

And you can use the same operation system like before (several versions of Linux and RISK OS) but if you have a B+ board and you are going to use the same microSD, you need to rewrite operation system there. I have checked several articles and looks like that everybody recommends to use Debian/Raspbian, so I decided to use Raspbian as well.

Additionally I am using Edimax WiFi adapter to connect my Raspberry to WiFi. It’s a very common adapter and you should not make any additional actions in order to configure it. Just open Wi-Fi configuration window to select the right WiFi network and once your board is connected, you need to note assigned IP address. Finally, before disconnecting your board from the keyboard and the monitor, you need to activate xrdp:

sudo apt-get install xrdp

I discovered that many people use Putty and Xming in order to connect Raspberry in desktop mode. I installed these tools and I was playing with them some time but, finally, I decided to use Remote Desktop Connection, which is part of Windows 8, doesn’t require any actions to install it and allows to make any configuration changes very quickly.

Of course, I am a C# guy, so in the next step I installed mono-runtime and Mono Develop there.

$ sudo apt-get update

$ sudo apt-get install mono-runtime

$ sudo apt-get install monodevelop

Once Mono develop is installed I was ready to start my experiments. First of all, the latest board is really faster. I didn’t feel “6 times performance” but it requires no more than 10 seconds to launch Mono develop and 3-5 seconds to create a new project. At the same time Intellisense system works pretty good, compiler and debugger are fast as well. It still is no as fast as my Lenovo W530J but it’s possible to develop and debug IoT projects directly on board.

Additionally I think that there are some opportunities to increase speed of development once Windows 10 is available there. Probably it’s just my feeling but I think that Raspbian has the same problem as some versions of Android and simply doesn’t use all CPU cores in effective manner. So, you cannot see real performance improvement, which is guaranteed by additional cores.

The first problem, which I got during my experiments, was unusual behavior of Mono Develop. Once I created a new Console application and wrote my first “Hello World” there I got several compilation errors. I believe that it’s related to configuration of the template. I spent about 10 minutes to understand what has happened there but, finally, I decided to use a trick: I just created an Empty Project and added a class there. Inside the class I added Main method and launched my first “Hello World” without any problems.

The second problem is the right library to use GPIO from C#. It required much more time (I even wanted to start a new open source project) but finally I found a good library. Compared to other libraries this one doesn’t have problems with resources and pin locks, doesn’t require any additional actions to start using it, has good architecture and provides many examples.

In order to start using the library you need to download and recompile it. I made it in Mono develop and didn’t have any problems there. After that you need to add the assembly to your project. It’s easy to do using Edit references… dialog from the context menu there. Once you add the reference to the assembly you are ready to start development. Pay special attention that the library contains two similar sets of classes: GPIOMem and GPIOFile. The first one requires an additional library and because already precompiled version doesn’t work on my board I decided to use GPIOFile.

clip_image004

In order to initialize a pin you need to use the following code:

GPIOFile l=new GPIOFile(GPIOPins.V2_Pin_P1_07, GPIODirection.Out);

In order to understand, which pin you need to initialize, you can check the specification on raspberrypi.org. You can see that pin 7 is GPIO 4 and you can use it to output. You can use pins 2 or 4 in order to get 5V voltage.

clip_image005

Once you pin is ready you can use it to send signals there:

l.Write(true);

So, finally I made my blinking LED on Raspberry.

clip_image007

Written by Sergiy Baydachnyy

04/22/2015 at 8:57 PM

Posted in IoT

Tagged with