Sergii Baidachnyi

Blog about technologies

Posts Tagged ‘IoT

How to manage AllJoyn devices in C#: LIFX Color 1000 Example

with one comment

In the previous video we discussed, how to onboard an AllJoyn device using Visual Studio, C# and Windows 10 AllJoyn features (How to onboard AllJoyn devices in C#: LIFX Color 1000 Example).

Today, I am going to show, how we can start working with an “onboarded” AllJoyn device.


Written by Sergiy Baydachnyy

06/06/2016 at 7:06 PM

Posted in IoT, Visual Studio, Windows 10

Tagged with

The second life for my Raspberry Pi B+

leave a comment »

Finally, I can use my favorite IDE – Visual Studio in order to develop applications for Linux devices, including Raspberry Pi B+. It’s really fast and I have not to deal with Linux at all. More details in my video:

Written by Sergiy Baydachnyy

04/12/2016 at 12:25 AM

Posted in IoT

Tagged with

Internet of Things via Microcontrollers: Introduction

leave a comment »

Looks like I have enough microcontrollers and boards in order to start (once again) my training about Internet of Things. I have decided to select a non-standard approach in the training, presenting more stuff about microcontrollers rather than about Arduino/Netduino/MyDuino boards, Let’s see if you like that. I will try to publish at least one module per two weeks plus some bonus videos.

The video is here.

Written by Sergiy Baydachnyy

02/05/2016 at 11:10 PM

Posted in IoT

Tagged with

How to build your own drone (part 2)

leave a comment »

Last time we discussed the common parts which you need to buy in order to assemble your drone. This week I have received all parts and I will show how to assemble everything and make it ready to start.

In the first step you need to assemble your frame and place some electronic components there like ESCs, motors and power distribution board. Of course, it’s easy to assemble the frame itself but in order to place all other components you need to use soldering iron before. I would not recommend to connect ESCs directly to power distribution board. In this case you will not be able to remove drone’s legs in case of transportation. Instead of that I used XT60 connectors. So, you need to solder your ESCs and connectors and use some wires to mount connectors to power distribution board as well. Don’t forget to use shrink tubes to avoid short circuit there.

In case of motors I am using banana connectors (3.5 mm) to connect motors and ESCs because you need a way to change sequence of wires there to run motors in the right way. Additionally, you can use insulating type to mount battery. If you don’t have a 3D printer in order to print some components for your frame, insulating type might help you from time to time.


In this step I recommend to connect battery to the power distribution board in order to understand that everything is OK and everything is soldered in the right way. Use multimeter to check that all ESCs produce 5V of power through control wires.

Once you assemble your frame, you need to mount fight control board and RC transmitter. Because these boards require 5V power I used power which is generated by ESCs using control wires. But each ESC contains its own power wire, so you need to remove all power wires except one. You can use knife to do this and use insulating type in order to insulate removed wires.


In the next step you can mount flight board, RC and connect them to each other. Don’t mount propellers in this step because you need to setup you flight controller before.

In the next step you can download OpenPilot software and use wizard to setup your drone. Thanks to the wizard it’s the simplest part there.

So, in the end I spent the following amount of time for each step:

· Frame assembly – 40 mins;

· Soldering (connectors, wires, motors) – 60 mins;

· Motors, ESCs and battery placement – 40 mins;

· Flight controller and RC placement – 20 mins;

· Setup – 10 mins;

Finally, my drone is ready to fly.


Written by Sergiy Baydachnyy

06/19/2015 at 11:59 PM

Posted in IoT

Tagged with

How to build your own drone (part 1)

leave a comment »

During the Maker Faire event I demonstrated my own drone based on Netduino. And I got lots of questions about hardware but not quite as many about software. Several people even told me that they tried to assemble own drone but failed. That’s why I decided to show my experience there. I am going to have vacation this week, so, I put aside software development and new APIs for some time and have some fun trying to assemble a new drone.

I am going to develop a powerful outdoor drone. So, it should be heavy enough to fly stable despite the wind and at the same time it should have enough power to fly up as well.

Let’s start with components which you need to buy.

Pay attention that in some cases it requires some time to receive it by mail. Usually I use – if they have something you can get it in 2-3 days but it’s a little bit expensive compared to amazon and they only have a few components in each category. If I am ready to wait some time I use or – the second one has many more components and 2-3 days delivery option for some of them but you will need visit the US to get your package.

First of all you need to decide which type of drone you are going to build and select the right frame. I would recommend to start with a quadcopter but during my vacation I will build a hexacopter. It’s better to select a metal (aluminum) frame because it’s not easy to break this frame. Of course, you can build your own frame using wood or metal parts but you spend much more time and lots of money compared to exiting frames which starts from $17. I have tested two frames: X525 and 650X6. They are pretty good and not very expensive.

Once you know number of motors based on your frame you can select motors. For drone, you need to buy brushless motors which can run you propellers with different speeds. Additionally you need to buy a special control board for each motor called ESC. Thanks to ESC you can run your motors with different speed and motors have as much energy as needed. Different brushless motors require different ESC (based on voltage), so you need to read specification for motors before to buy ESCs. For the frames which I mentioned early I would recommend to buy 1000KV motors like A2212. You even can find pack of similar motors with ESC and propellers. I like this pack and usually I buy it.

Motors and ESCs is the most expensive part of the drone but the second one is battery pack. If you want to fly 20-30 minutes you need to buy a good LiPo battery and you need to buy a charger as well. I bought a 5100 mAh battery but you can buy anything from 2200 mAh. Just verify that it produces 11.1 Volts of power – it guarantees that you will have enough power for your motors and control board. Charger is usually expensive as well but you need a way to power your battery.

In order to operate your drone you need to buy radio control receiver and transmitter. I have FlySky RC but you can buy anything. In general you can fly using 4 channels only but you can use other channels for camera or something like this. Pay special attention that from time to time you can find some receivers which don’t work with common transmitters. So it’s better to buy both things together from the same company. Of course, you can use WiFi modules to operate drones from your phone or laptop but in this case your drone will not fly far away.

The most important part of your drone is the control board which sends signals to your motors, receives signal from your RC and implements some algorithms for stabilizing your drone. Usually this board contains several sensors like accelerometer and gyroscope but you can add barometer and GPS as well. For the first drone it’s enough to have just Accelerometer and gyro. I would recommend OpenPilot board because that software supports wizard which helps setup your drone, and drones based on OpenPilot are very stable. I used MultiWii boards as well but you need spend much time in order to setup those boards, and I encountered some problems with algorithms there. You can use Arduino, Netduino and even Raspberry and implement your own algorithms but it requires additional time and good math knowledge.

Finally, you need to buy some components which help to solder the frame like soldering iron, iron wires, connectors, power distribution board. Once you have all these things you are ready to start assembling your drone.

Next time I will show how to assemble my hexacopter step by step but at the end of the post I want to share list of expenses for my drone:

· Frame – $38

· Brushless motors (two packs, because I need at least 6 motors) – $146

· Power distribution board – $7

· Wires – $10

· Shrink Tubes – $3

· Banana connectors – $5

· Connectors – $8

· Battery – $38

· Charging station – $23 (probably, it’s better to buy more expensive charger in order to avoid big boom at your house)

· RC – $100

· Flight control board – $19

· Soldering iron and some stuff there – $30

So, total price of my drone is about $427 but there are still opportunities to cut down the price. For example you can buy cheaper RC, battery etc. At the same time you can increase the price adding camera, GPS, barometer etc.

Written by Sergiy Baydachnyy

06/19/2015 at 11:54 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.


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.


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


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


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.


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.


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 ,

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 =; lsb =; checksum =; 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.


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.


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 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.


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


So, finally I made my blinking LED on Raspberry.


Written by Sergiy Baydachnyy

04/22/2015 at 8:57 PM

Posted in IoT

Tagged with