Sergiy Baydachnyy

Blog about technologies

Archive for February 17th, 2015

IoT: How to integrate two boards

leave a comment »

In the previous posts I described some features of Galileo 2 board but there are still some scenarios, which may not be implemented on Galileo 2 boards only. For example, Galileo doesn’t have GPU, so you cannot use Galileo to output video. But there are several micro boards in the market like Raspberry Pi board, which supports GPU, HDMI output and allows to use camera as well. So, on the one hand we have a good solution with the Intel inside processor but on the other hand we still have some scenarios when we need to use several boards there. So, in this post I decided to show how to integrate two boards.

I used the Netduino and Galileo boards but this approach will work for Raspberry PI and Arduino as well. The idea is in using TX/RX pins, which are implemented in the most boards and allow to make serial communications. In fact, TX/RX pins is the same like COM1.

In order to test TX/RX pins I decided to build something like this

image

The idea of the project is too simple: we will use Galileo board in order to get input from two buttons and thanks to them we are going to control two leds, which are connected to Netduino. Because we use Netduino compatible boards, we can find TX/RX pins connected to pins 0 and 1. One of this pins is used for sending data and the second one – for receiving. So we should connect pin 0 (Galileo) to pin 1 (Netduino) and pin 1 (Galileo) to pin 0 (Netduino).

The code of our applications is pretty simple. In case of Arduino you can use the following example:

public class Program
{
public static void Main()
{
// write your code here
OutputPort ledRed = new OutputPort(Pins.GPIO_PIN_D8,false);
OutputPort ledYellow = new OutputPort(Pins.GPIO_PIN_D9,false);
SerialPort serial = new SerialPort(SerialPorts.COM1,9600,
Parity.None, 8, StopBits.One);
serial.Open();

while(true)
{
if (serial.CanRead)
{
int b=serial.ReadByte();
char c = (char)b;
switch(c)
{
case 'r':
ledRed.Write(true);
break;
case 'y':
ledYellow.Write(true);
break;
case 'f':
ledRed.Write(false);
break;
case 'h':
ledYellow.Write(false);
break;
}
}
}
}
}

This code just get the commands from serial port and switch on or switch of the leds.

In case of Galileo, you can use the following code:

#include "stdafx.h"
#include "arduino.h"

int _tmain(int argc, _TCHAR* argv[])
{
return RunArduinoSketch();
}

int but1 = 8;
int but2 = 9;
bool flag1 = false;
bool flag2 = false;

void setup()
{
Serial.begin(CBR_9600, Serial.SERIAL_8N1);
pinMode(but1, INPUT);
pinMode(but2, INPUT);
}

void loop()
{
if ((digitalRead(but1) == HIGH) && (!flag1))
{
Serial.write('r');
flag1 = true;
Sleep(1000);
}
if ((digitalRead(but2) == HIGH) && (!flag2))
{
Serial.write('y');
flag2 = true;
Sleep(1000);
}
if ((digitalRead(but1) == HIGH) && (flag1))
{
Serial.write('f');
flag1 = false;
Sleep(1000);
}
if ((digitalRead(but2) == HIGH) && (flag2))
{
Serial.write('h');
flag2 = false;
Sleep(1000);
}
}

I used sleep there in order to avoid several inputs from one button click there.

Finally I run my project:

image

In our case we used Galileo for sending data. But if you want to write some code which will able to receive some data you should add the following preprocessor directive to C/C++ configuration properties: SERIAL_EVENT; Additionally you should implement serialEvent method, which is called if some data is available.

You can use TX/RX pins in order to communicate with PC as well. In order to do it you can but UART->USB adapter which costs around 6 dollars (use just two pins there).

image

Advertisements

Written by Sergiy Baydachnyy

02/17/2015 at 10:11 PM

Posted in IoT

Tagged with

My first experience with 3D printer

with one comment

clip_image002

Last week, thanks to BizSpark program, finally, we got a 3D printer for the Launch Academy. Since I am a Technical Evangelist in Vancouver I got an exclusive offer to understand what is it and how can we use it for different projects. Frankly speaking we had a 3D printer in Ukrainian office but I have never touched it because in Ukraine I never had a chance to buy something, like motors and controllers at http://robotshop.ca/, Amazon or Fry’s Electronic and that printer wasn’t very valuable for me at that time. But today I need much stuff like propellers for my drone, wheels for micro robots, boxes for microcontrollers and sensors etc.

So, last Tuesday, I got a package and started my way in 3D experience. In this post I am going to share several learnings, which I got during my first steps.

It’s not very complex thing

There are several technologies, which are used in 3D printers today. For example in medicine area you can find some printers, which use powder or photopolymers and are based on Selective Laser Sintering or Stereo Lithography technologies. But today, the most common technology for innovators and hobbyists is Fused Deposition Modeling or Fused Filament Fabrication. This technology works by laying down material in layers. It can use plastic or metal to create a thing, layer by layer

In my case I have a Makerbot Mini 3D printer, which looks like a small box without any complex things inside. Because it was a new one, it required 6-9 steps in order to assemble it but I was not required to use any instruments.

clip_image004

3D printer is not a very complex thing in sense of software as well. It contains software, which allows to use G-Code to print your things layer by layer. In any case, before printing something, you need to update your printer. In case of Makerbot I used Makerbot Desktop tool. This tool is not just updated in (?) my printer but it’s required to load and unload filament there.

Windows 8.1 drivers

It’s very important to buy a printer, which supports drivers for Windows. Makerbot is such a printer, so it supports Plug and Play experience.

If your printer doesn’t support Windows 8.1 drivers, you will have much more steps to print your things. Usually you should convert your 3D model to STL format and use some slicer tools in order to set some settings and slice your model. Additionally, the tools should generate G-Code for the printer. But in case of Windows 8.1 compatible printers, driver can do many things for you. It allows you to use common tools for printing and you even can implement printing experience in your application. If you want to create an application, which will print something, you can download 3D printing SDK and find several examples there. You can use the following link in order to download the sdk.

Additionally, SDK contains some documents, which describe how to create your own driver. So, if you assembled your own printer or want to help the community, you can use 3D printing SDK in order to build a driver as well.

Tools

As I mentioned earlier, 3D printing SDK for Windows contains some samples about how to implement 3D printing experience in your applications. But if you are going to start printing right now you can install already prepared application for your – 3D Builder. You can find this application in the Window Store and it allows to create, modify, fix and print your models. Of course, you can use Maya or 3D Max in order to create a new model but I don’t have experience with it. So, I decided to use 3D builder.

clip_image006

Additionally, 3D Builder allows to use Kinect to scan real objects.

clip_image008

If you downloaded Makerbot desktop tool, you will find it valuable as well. Of course, it doesn’t support any features which help to modify your model but it allows to understand your printer status and estimate printing time.

clip_image010

Where to find some stuff

No matter what printer model you have I would like to recommend to visit site http://www.thingiverse.com/. It contains a lot of free models, which you can use for your experiments.

clip_image012

Usually you can find STL file there. So, you can print it directly or use them to create new models in 3D Builder.

Some tips

I found that my printer is too noisy. So, if you are going to print something at home – find a good place for it. Additionally, it requires much time to print things. For example, in order to print a trinket, it will spend more than hour but for a drone propeller it spent 3 hours.

Before starting printing, remove all garbage from the printing area. Usually you can find some filament there because it accumulated there during heating process etc. If it happened right before printing, you can use Makerbot desktop in order to pause the process. Usually, it’s not very dangerous to put your hands inside.

Use 3D builder to change orientation of your things. Sometimes your things are not stable during printing process due to wrong orientation. Think some time before starting the process.

Use raft and support features. It requires additional printing time but it’s easy to remove raft and it really helps.

Summary

3D printers are very popular today and they allow to bring your ideas to real world with less cost. Today, you can find many utilities, APIs and models, which are ready for 3D printers. At the same time, 3D printers are not very expensive like several years ago. In any case, if you still don’t have your own 3D printer, you can visit one of the place for innovators and startups – in many cases you will find many 3D printers there. And today I would like to announce 3D printer availability at Launch Academy in Vancouver.

image

Written by Sergiy Baydachnyy

02/17/2015 at 10:05 PM

Posted in Microsoft

Tagged with

Internet of Things: What about C# there?

leave a comment »

In my post about Galileo we used C++ language in order to build some code. But what about C# and is there a way to use management language in micro devices based on different types of microcontrollers? So, this post I decided to devote to C# language.

First of all you need to understand that there is no way to use C# for Arduino boards. Of course, Arduino is very popular today but there are many different solutions in the market as well. Some of these solutions are Netduino, Raspberry PI and Galileo. Today, you can find much more different boards but these microcontrollers have better support, community and popularity. So, let’s discuss all these boards and try to understand if there is a place for C# and .NET Framework.

I am going to start with Netduino boards. You can find many different models using the following link. I would recommend Netduino Plus 2, which is the most advanced board there but it’s not important right now because all these boards run .NET Micro Framework and allow to use C# there.

clip_image002

.NET Micro Framework is an open source platform, which is developed for low memory devices with limited amount of resources. In fact, .NET Micro Framework could be run on devices with 64 kilobytes memory that is very important for cheap and really small devices. .NET Micro Framework has a very interesting story. Probably, it was announced too early, about 9 years ago and since that time, .NET Micro Framework supported many different microcontrollers. Today, the most popular microcontrollers are Netduino 2 and Netduino Plus 2, which are Arduino compatible. It’s very important right now because it’s easy to find many different stuff for Arduino. At the same time there are special controllers for people, who don’t have enough knowledge in electronics – Netduino Go and Gadgeteer. These two boards allow to use plug and play modules to create your own prototype fast.

In my case I decided to buy Netduino Plus 2 board and make some small projects there. And of course, if you have a board you will need to install some stuff to your computer like: .NET Micro Framework SDK, Tools for Visual Studio and board specific SDK. In case of Netduino Plus 2 I would recommend the following steps there:

· Update Netduino firmware – when I bought the board I found that it has version of .NET MF less than 4.3. But if you have older version of firmware on your board you will not be able to use the latest version of SDKs. How to update firmware you can find in Arduino forum.

· Install .NET Micro Framework SDKs and tools for Visual Studio – you can find the package using the following link;

· Install Netduino SDK – you can download it there;

In any case, before download something, check the latest versions of SDKs and firmware.

Once you install all needed software, you can use USB -> micro USB cable in order to connect it to PC. You can use this cable in order to provide power to Netduino board. Using Visual Studio you can create an application based on special templates for Netduino boards and you can start to use C# and many classes from .NET Micro Framework and Arduino there. Visual Studio supports not just deployment of applications to Netduino but debugging and Intellisense system as well. So, you developer experience should look like common Windows platform experience. It’s really cool.

clip_image004

The second board, which allows to use C# there is Raspberry PI board. This board is not compatible with Arduino but it’s very popular because there is not just CPU but GPU as well. The board contains HDMI output and you can connect it to TV sets, projectors etc. And you still may use many sensors from Arduino world because Raspberry supports the same voltage. Frankly speaking, Raspberry doesn’t support Visual Studio or any special tools for Windows developers but Raspberry is designed for full version of Linux operation system. You can find many different Linux edition for Raspberry but in any case you need to work with Linux. But as you know, there is an open source version of .NET Framework – Mono. So, you still can use C# and .NET framework features there.

In my research I decided to use Raspbian image based on Debian Wheezy. Somebody told me that it’s very popular and it was the first in the list of images. Of course, for Windows developers it’s not easy to understand, how to use this image but I just connected my board to TV Set, using HDMI cable and plugin keyboard and mouse there. Thanks to Edimax WiFi adapter and WiFi Config tool in the image, I easily setup Internet connection there and got IP address. Once you get Internet connection, you need to run one more command, using LXTerminal:

sudo apt-get install xrdp

This command will activate remote desktop on your board. It’s time to disconnect your board from TV, keyboard and mouse because you may use Remote desktop right now.

In the next step, you need to run to more commands to install Mono runtime:

$ sudo apt-get update

$ sudo apt-get install mono-runtime

Thanks to Mono runtime you are ready to launch you C# application but you still don’t have tools. So, finally, in order to install Mono Develop, you can use the following command:

sudo apt-get install monodevelop

Now, you ready to run Mono Develop and launch your applications.

clip_image006

Frankly speaking, I am not sure if you will get much happiness while developing something on Raspberry directly. It’s not a very productive environment and it’s better to use your PC to create code and just use Raspberry to compile and launch it. While it’s interesting to create Windows Form applications on Raspberry usually you are interested in PINs there. In order to use pins from C# and make real micro solutions you will need to download RaspberryPI.NET library, which you can find using the link.

And a few words about Galileo. Officially Microsoft doesn’t support .NET Framework on Galileo boards. According to official FAQ there is a chance to see Windows Runtime or something like this soon:

Q: Will you support C#/WinRT/.NET/Node/JS… ?
A: For this first preview release, we’re focusing on C++ and Arduino compatibility. In future iterations, our intent is to support the Universal App model announced at Build.

But I found that many people already tried to make some research around Mono and Galileo board as well. For example, you can check this post in order to find some instructions about it.

Written by Sergiy Baydachnyy

02/17/2015 at 9:56 PM

Posted in IoT

Tagged with