Sergiy Baydachnyy

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.

https://channel9.msdn.com/Series/Internet-of-Things-micro-boards-for-beginners/How-to-work-with-AllJoyn-devices-in-C-LIFX-Color-1000-example/player

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:

https://channel9.msdn.com/Series/Internet-of-Things-micro-boards-for-beginners/Bonus-Video-The-second-life-for-Raspberry-Pi-B/player?wt.mc_id=DX_836329

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.

WP_20150617_09_32_38_Pro

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.

WP_20150617_10_06_12_Pro

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.

WP_20150618_18_06_36_Pro

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 robotshop.ca – 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 amazon.ca or amazon.com – 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.

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