# Sometimes good things happening to us when we are doing something good to others!

Last Sunday I started looking for not too expensive drone for my wife. As I am building my own DIY drone I am sure that next couple months Saturdays will be filled by the drone tests. So I decided to buy an inexpensive drone for my wife and make testing time more pleasant for her. When I ordered U818A I came up with an idea that I could use the drone to learn my piloting skills.

In my area sometimes we can get a lot of wind which will be moving drone left right up and done and actually I am really happy I will feel it on second drone.

# My first Udi R/C U818A HD impression

### Investigation of adequate drone. #Part 3: My build presentation.

I got my order which I have listed in my previous post. I was thinking what would be best set of pictures of a video for you to see all items. I decided to make a video which I hope you will like it. It is my very first video blog post and first ever video in English.

If you have some questions about my build and items I have bought let me know in a comment.

# All elements

### A little bit of theory: How do Quadcopters fly?

Quadcopeters as the name suggests use four motors to fly. Two motors rotates in clockwise direction and another two in counterclockwise direction. In this way their are balancing quadcopters rotation. When four clockwise motors would be used on the copter, it will start rotating always in clockwise direction and if only four counterclockwise motors copter would be rotating in counterclockwise direction. Having two pairs of contrary motors cause Quadcopters to stay in place. Peacefully hovering above ground. When speed on all motors equally increases or decreases drone will vertically take-off from the ground or

# Piloting

Quadcopter or any other copter, airplane or object can be rotated around three axis, they are called roll, pitch and yaw.

• Rotation around the front-to-back axis is called roll.
• Rotation around the side-to-side axis is called pitch.
• Rotation around the vertical axis is called yaw.

Airplanes use ailerons, rudder and elevator to rotate around one or another axis. However copters doesn’t have them instead use four motors with propellers. Airplanes are more intuitive to understand but quadcopters are not as complex as they look.

Always to rotate drone through one or another axis two motors on one side need to speed up and other two motors on opposite side must be inversely changed.

# Roll axis

To lean drone to right both left motors speed need to be increased and speed of both right motors decreased. To lean to left both right motors speed should be increased and left decreased.

# Pitch axis

Rotating a drone thought pitch axis requires speed change of back and front motors. To lean forward speed of ‘front’ motors need to be decreased and speed of ‘back’ should be increased. To lean backward speed of ‘front’ need to be increased and ‘back’ should be decreased.

# Yaw axis

Yaw axis full move explanation is a little bit more complex then other two axis. I would like to explain the basics here but if you would like to know more, just google it. Also good thing is that all flight controllers have this knowledge injected to their ‘brain’. In the nutshell, to turn drone left or right two diagonally across motors must speed up and second two should slow down.

### Setup Raspberry PI (+navio) Raspbian and Flight Control Software (Autopilot)

Setting up Raspberry Pi is very easy and you can find a lot of guides step by step on the internet. By just to make it easy for you I will add quick guide of Raspberry Pi Raspbian OS installation.

# Raspbian OS Installation

Raspbian

2) Download & Install: Win32diskimager Tool which Installs ISO on microSD card)

https://sourceforge.net/projects/win32diskimager/

3) Upload Raspbian ISO to SD Card using win32diskimager

# Flight Control Software (Autopilot)

There are two main free flight controllers Ardupilot and PX4. I think they both are good. They have very strong community which as I have noticed works all week to make their software as best as possible. Ardupilot is more mature flight controller which I think also supports more platforms rovers and subs. On the other hand PX4 as I have read is more advance in accordance to multicopters plus has more modern architecture which uses 32bit CPU and supports more peripherals. But also Ardupilot has much much better documentation so for users which are not very tech people it will be much easier to do anything related to drones. As it also contains some documentation about drone build.

My plan is to start with PX4 and see how it will work for me. I will keep you blog posted. If not I will test Ardupilot. I will be also working on their code so I could have some other thoughts later which I will post about. So let’s see how we can install both software on raspbian with navio2.

# Ardupilot Flight Control Software Installation

Whole installation process you can find on emlid.com docs page at:

https://docs.emlid.com/navio2/Navio-APM/installation-and-running/

# PX4 Flight Control Software Installation

PX4 support Navio2 board from I think couple months so there is not much guide how to install it best link I have found is the one below.

https://dev.px4.io/hardware-rpi.html

# Drone elements

Below I would like to list all parts I think are necessary to build a proper drone. Also giving you name of element I have bought as I know now how hard it is to build your own drone. I was strangling, comparing, thinking and planning all week to finally order this what is in below table.

When I was ordering my quadcopter I was really close to skip couple elements like e.g. power distribution board or very useful mounting foam and other little but sometimes critical elements. Unfortunately, other blogs I have read about building a drone doesn’t include such as ‘not importans’ elements. Which I think is wrong as without them assembling the drone still will be possible but much harder to do.

Below is the table from my excel file which contains my drone elements. Actually it contains everything related to my very first drone assembly including threadlocker and heat sink tubes.

# Table of my drone elements

 Elements type What I bought Multicopter frame F450 Quadcopter Frame with integrated PDB ESCs CICADA BLHELI_S ESC (30A) – BB2 UT EDITION Motors MT 2216 810Kv Muticopter Motor Propellers 9443 Self-locking Propeller Pack Propellers 10×45 Propeller Set Carbon Fiber (discount) 6/9+ channel RC transmitter FLYSKY FS-I6 TRANSMITTER WITH FS-IA6 RECEIVER GPS Mount Foldable GPS Mast Mount LiPo battery Tattu 1300mAh 14.8V 45C 4S1P Lipo Battery Pack LiPo battery GENS ACE 3300MAH 11.1V 25C 3S1P LIPO Charger SKYRC E450 LIPO/LIFE/LIHV BATTERY CHARGER Wiring Navio Wire pack for Navio2 Flight Controller board Navio2 GPS Antenna GPS/GNSS antenna MCX for Navio Power Module HIGH VOLTAGE APM POWER MODULE WITH 3A UBEC Anti-vibration bed VIBRATION DAMPING MOUNTING SET Propellers guard 5″ PROPELLER GUARD PACK Cables Male XT60 wire – 10cm Cables Female XT60 wire – 10cm T-plug cable MALE DEANS / T-PLUG WIRE – 10CM Adaptor Male T plug to Female XT60 Adaptor Legs HIGH LANDING GEAR FOR F450/SK480/F550 SD 16GB microSD

As you can see I didn’t add any gps antenna and microsd card as I had them at home, but you can easily look for them at any shop. Also I haven’t ordered threadlocker blue, battery holder and heat shrink tubes as I bought them in local store.

Some parts could be unavailable in store you will be buying from, then I would recommend to find similar elements but from other manufactures. Trust me it is hard to find a copters related store which will have everything you want. Most of the time it is a hunting for the best equipped store which have as much items you need.

### My order

I order everything from Unmannedtech as they had elements all really wanted plus some others in decent price. In my case I was looking for store which will have F450 Quadcopter Frame, not to expensive carbor fiber propellers, navio2 board in good price and decent cheap transmitters. Which I all found there. But as I live in Ireland it was a priority for me to order from one shop from Ireland or UK. If you leave in UK or another in EU where you have more diy shops or you have couple weeks to wait for an order you will be might be able to lower the costs by ordering from couples different stores

# Autonomous Drone project post

### I wish you enjoyed my introductory post if not I am invite you to read it before this post. It contains the plan for this project.

Ah, the investigation… It took me half Saturday and half Sunday already. And to be honest I don’t know which drone I should buy not to mention which stabilization and control hardware I should use. I will try to find out it next week and I will let you know in my next blog post.

### Today I will share with you my experience with drones and drone related parts online stores. I will try to summarise what I have learned in the last two days.

During my search I have noticed that significant number of online shops don’t keep their stock updated. I am looking for pretty small drone to start with, which will cost me maximum £400 including everything. But unfortunately in drones world it is not much. So when I have visited five first websites they had their stock empty with good but still cheap drones or the shipping time was around 14-28 days.

That being said, some people order drones from Chinese online retailers. In my opinion drone is a pretty quick thing with crazy fast rotating propellers and when bought cheap could do more harm then pleasure. Some with drone controllers, actually especially them buy at some well known store.

### Selection:

I have found two looking good online stores in UK and Ireland but also I think it is really worth to check list of stores recommended by Ardupilot as I believe they have immensely more experience in it then I do:

Online stores recommended by Ardupilot

Stores I have found and I hope I will order from are UnmannedTech UK and RadioControlled ROI as they seem to have couple interesting drones and parts. But I will let you know as if they will have too many things out of stock I could order from other.

### Kits:

Another way to buy a diy drone is to buy whole kit with flight controller like Erle copter but it’s especially when adding more parts can grown quickly to couple hundred of pounds.

### Building own drone:

Last way is to build your own drone. Drone could cost a little bit more but will be equipment in parts that are ideal for your drone. But if don’t have much experience in drone architecture it might be better to purchase a low cost drone at the beginning. Then in the future build your own dream drone.

# Plan:

## First part:

First thing on my plan is purchasing a drone. This sounds easy but is not. DoItYourself drones need to be assembled manually, you need to carefully solder it and screw everything as manual says. Also it is good to plan what other parts you would like to equip your drone with. Like battery, flight controller, radio receiver, camera and many many more. And here it starts to be a little bit tricky. Drone need to be balance as best as possible and when you are assembling it you need to check if e.g. battery should be more on the back or maybe at front to balance the drone.

Second, ah silly thing but the drone will need to fly, finger cross everything is connected.

When will be able to hang in the air, just hover for couple minutes. I will start working on small WiFi controller.

Then drone firmware also will need to be extended with wifi controller code which will be able to understand wifi controller commands and transform it to real drone moves.

When all of this will be finished then will be a best time to start working on autonomous… Oh no, actually drone will need to be extended with some telemetry before autonomous. Will be extended with GPS module, accelerometer,  gyroscope, distance sensors and probably couple more.

The one thing I haven’t yet found-out is how to measure drone displacement inside a room when there won’t be a GPS signal obtainable. Probably I will need to work on some anti-collision system.

Perfect, we have everything, we can finally start working on autonomous code? Assuming all above sensor are communicating with drone control unit and they are working correctly, y… maybe, but no…

## Second part:

Because, the second part of the project is cloud (Azure or AWS). All sensors data will need to be aggregated and pushed to Azure where some analysis will be done. I am planning to use cloud to correct my autonomous code based on analysis made. I am not yet sure how but I will find a way to do it. In sum it is always better to start collecting data from the beginning of the work on something then later without having view on full process from the start to ‘now’.

When it’s done, yes I can…! No, I can’t… I forgot about one more thing. On a windy day or with people in the room, drone could be randomly moved or even be turned over. And this displacement need to be included in real-time flying calculations to immediately make a correction on the flight plan.

Come on! Let’s do some work on autonomous code.  Okay, okay! We can start now. Ah relief, happy days!

Autonomous part of the project will be the most complicated part but I cannot wait when I will start working on it. I have hope that above tasks will be finishes in next couple weeks/free weekends. So I could start coding as soon as possible!

### MQTT – why it is worth to look at?

Today I would like to introduce you MQTT (MQ Telemetry Transport). I would also like to describe it’s benefits and why it is better then HTTP protocol in Internet of Things (IoT) world.

HTTP is mature and really established protocol. Is easy to use and know by almost everybody. Is perfect for request and response. But in our IoT world is not ideal. It is text based protocol which requires more bandwidth. Also requires working web server which requires small or bigger server but will not work on really small IoT devices. This could be a bit a limitation for users as web server and long text response and request will require more power which unfortunately for IoT uptime (battery )is crucial.

However MQTT is publish and subscribe (pattern) based light weight messaging protocol with quality of service. I think this already give us flexibility. In large scale systems which based on network with small end-devices being able to subscribe to one or another sensor without writing a parser sound really useful. It requires minimal bandwidth as it is binary format. It header is build from just two bytes. Which also shows that devices uses MQTT requires less battery.

In MQTT our central point is a broker which sends received messages publishes to subscribers. As simply like that:

There are number of brokers but the one most is Mosquitto (mosquitto.org). It supports most of the platform and can be installed on almost any computer.

If you would like to read more about mqtt protocol in more technical view you can read it here:

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html

Okay done with theory. I have just installed Mosquitto on my Raspberry PI so in next post I would like to show you a bit more DIY base on ESP8266 sensors which we used previously. But if you haven’t do it then I am inviting you to read previous posts and get more familiar with ESP8266.

-> https://gettoknowthebob.wordpress.com/

Have a nice day!

#### Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

### Thingspeak – with Nodemcu (ESP8266) and DS18B20 thermometer sensor (part2)

Last post I wrote about Thingspeak – easy to use IoT platform (part1) where I hope I showed you why I really liked this platform. I invite you to read it before reading this post.
Today I would like to show you how to use your device (in my case it was Nodemcu and ESP8266) with thingspeak account. How to read temperature from DS18B20 sensor and upload it to right thingspeak channel field.

## Account

First thing you need to do you need to create account on thingspeak.com.

### Channels / device

Next thing you need to add new channel which could be your device or group of devices. Each channel have 8 fields which then you can use to store data from your device or devices. I have used one channel with one field where I am writing temperature values every 17 seconds (thingspeak is able to store data after 16s).

### Source code

I think there is not ESP6288 on supported list of devices but as they API is really easy to use we can use it to send data to ThingSpeak from any device which has internet connection.
Below I have added source code I have used on my Nodemcu (ESP8266-12E).
It read data from DS18B20 sensor then send it to thingspeak server. This way updates temperature value.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define myPeriodic 15 // Seconds
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
WiFiClient client;

// replace with your channel’s thingspeak API key,
String apiKey = “B9HSYHJWRKYUILAA”;
const char* ssid = “ssid”;
const char* server = “api.thingspeak.com”;

void setup() {
Serial.begin(115200);
delay(10);

Serial.println();
Serial.println();
Serial.print(“Connecting with “);
Serial.println(ssid);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi Connected”);
}

void loop() {
float temp;
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);

if (client.connect(server,80)) {
String postStr = apiKey;
postStr +=”&field1=”;
postStr += String(temp);
postStr += “\r\n\r\n”;

client.print(“POST /update HTTP/1.1\n”);
client.print(“Host: api.thingspeak.com\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: “+apiKey+”\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);
client.print(postStr.length());
client.print(“\n\n”);
client.print(postStr);

Serial.print(“Temperature: “);
Serial.println(temp);
}
client.stop();

delay(17000); // 17sec delay between updates
}

# Thingspeak & ESP8266Network channel

So this is how it looks after couple hours:

Thingspeak also offers matlab code run tool which you can use to process all gained data in the way you need.

For example I have used example matlab code to calculate average temperature I have at home.

Matlab source code:

% Channel ID to read data from
% Temperature Field ID
TemperatureFieldID = 1;

% Key between the ” below:

% Calculate the average temperature
avgTemperature = mean(temperature);
display(avgTemperature, ‘Average Temperature’)

And results:

I hope it helped you. Give me a should in comments when you will have some questions.

Have a nice day!

#### Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

### Thingspeak – easy to use IoT platform (part1)

Today I would like to introduce Thingspeak – open data platform for the IoT.

This platform allows you to simply collect data from your sensor then analyze it and trigger selected action:

## ThingSpeak Features

• Real-time data collection and storage
• MATLAB® analytics and visualizations
• Scheduling
• Device communication
• Open API
• Geolocation data
• Available on GitHub®

Personally I especially like ThingSpeak from its easy to use web panel and API. Last couple months I had many problems with ESP8266, nodemcu or some with domoticz configuration, uploading firmwares or testing tools and IDEs. I have spend many times hours on small problems which had resulting during tasks. And here I found ThingSpeak which I wanted to test. And you know what? In just 10minutes (really) I have created new account I have added new channel (device) and I have learned basic API example. Easy peazy, first time.

In my next blog post I will show you example source code I have created to upload data to thingspeak base on their API. Which again, wasn’t so hard.

Next thing I did base on temperature data I have tried to create basic Matlab project which was calculating average temperature in my home. Pretty easy. I will paste here Matlan source as and example.

% Channel ID to read data from
% Temperature Field ID
TemperatureFieldID = YourFieldId;

% Key between the ” below:

% Calculate the average temperature
avgTemperature = mean(temperature);
display(avgTemperature, ‘Average Temperature’)

This is very useful feature. Last year we have rent new apartment. It is a lovely place but walls are really thin. When winter came it was really cold. I was heating apartment to 22-23 degrees in evening to have in the morning something close to 6-8 degrees which is really cold when you are getting up from under your linen. And today I see how useful it would be to store this data and next day see how fast temperature is decreasing. After that use this matlab code to get average and then easily program your central heating to be effective.

Of course we can buy thermometers which already do it. There is a lot of devices on the market but here you can do it in DIY manner based on 2\$ nodemcu and spending time on something useful. Only benefits and all of it for almost free.

This is why I liked ThingSpeak so much. It is really cool platform for everybody.

#### Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,