Click here to Skip to main content
15,884,783 members
Articles / Internet of Things

Measuring temperature, GPS, vibration and set alarms by NET Micro Framework

Rate me:
Please Sign up or sign in to vote.
4.96/5 (36 votes)
9 Nov 2014CPOL8 min read 53.4K   396   51   20
If you know C# or VB you are ready to learn desirable and Simple way for monitoring your environmental condition (measure temperature, humidity, GPS coordinate position, vibration) and set alarms (turn on or blinking LED, buzzer and etc) by installing NET Micro Framework and buy compatible board (F

IoT Competition Stage 2 - Preface

Internet of Things (IoT) makes our world as possible as connected together. Nowadays we almost have internet infrastructure wherever and we can use it whenever. Embedded computing devices would be exposed to internet influence. Common instances for embedded computing devices are MP3 players, MRI, traffic lights, microwave ovens, washing machines and dishwashers, GPS even heart monitoring implants or biochip and etc.

Now the important question is how to use cutting edge technologies to improve IoT developing and its performances, I mean how to make IoT easier by WIFI, High level language with the less confusing in writing code and configuring complex devices. Is there any way to buy compatible board and write your code in C# or VB on .NET platform and finally reach to your purpose ??!! 

What is your purpose:

Writing in C# or VB on .NET platform on compatible board by installing free and open source NET Micro Framework on .NET and measure your temperature, humidity, vibration, GPS  coordinate position and display alarm when its value are more or less than your expectation. 

 

Introduction

Why .NET Micro Framework (NETMF):

Advantages:

  1. If you want to build system and write your codes on classic ways, therefore you have to spend lots of your time to learn low level language while here with NETMF you just need to know C#, then you just be familiar with hardware catalog.
  2.  Classic ways need compiler for microcontroller while here you are free to install NETMF on your current .NET (Visual Studio 2010, 2012, 2013).
  3. NETMF is open source.
  4. Your code can be run on other devices in the range of NETMF compatible device.
  5. NETMF debugging is as easy as .NET debugging.

Disadvantage:

  • NETMF works with high level language such as C# or VB.NET so it might be slower than low level language such as Assembly.

Requirements (Totally)

1. Hardware: It is physical board that you are going to manage and control your environment by this device.

2. Software:

 

Installing Steps for NET Micro Framework (NETMF):

Installing NETMF Step 0 (Important Tip):

You should remove and uninstall any previous version .NET Micro Framework from your computer , because of preventing any confliction in your system. 

Installing NETMF Step 1:

Go to this link: https://netmf.codeplex.com/releases/view/118283 . 

Then click on SDK 4.3 (RTM QFE1) -> To download NET Micro Framework.

Image 1

 

Installing NETMF Step 2:

Now it will be placed on your local drive (C:\.... or D:\.....) -> Then right click on this "zip" file  and extract it.

Image 2

 

Installing NETMF Step 3:

Double click on the extracted file and run it.

Image 3

 

 

Installing NETMF Step 4:

This is "Welcome page" --> click on "Next"

Image 4

 

 

Installing NETMF Step 5:

Click on "I accept .. " --> Then click on "Next"

Image 5

 

Installing NETMF Step 6:

Click on "Complete Option" --> Then click on "Next"

Image 6

 

Installing NETMF Step 7:

It time to click on "Install"

Image 7

 

 

Installing NETMF Step 8:

Waite until finishing ...

Image 8

 

Installing NETMF Step 9:

Click on "Finish".  Now you have installed NETMF on your .net successfully.

Image 9

 

Running Simple Code on NETMF Just for Test:

Running Test on NETMF Step 1:

New Project: Open you Visual Studio 2012 or 2013 --> File (Menu) --> New --> Project

Image 10

 

 

Running Test on NETMF Step 2:

Select your language in the left side --> Select Micro Framework --> Select Console Application

Name your project & Determine Location & Solution Name --> Click on "Ok"

Image 11

 

Running Test on NETMF Step 3:

Now select "Program.cs" from your solution window --> Inside Main() (you start from Main() to do anything)

Write simple code just for illustrating on console to be sure everything is all right:

Image 12

 

Sample Code to Show Simple Text on Console:

C#
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Runtime.CompilerServices;
using Microsoft.SPOT.Presentation.Media;
using System.Diagnostics;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            
            Debug.Print("This is first project on NETMF");

           
        }

    }
}

 

 

Running Test on NETMF Step 4:

When you encounter NETMF you have two options for running your project on "Emulator" or "Device". Now you should test if your NETMF works all right or not, so let`s to select "Emulator" mode instead of any device or board.

On "Solution Explorer"  right click on Project Name --> Select "Properties"

Image 13

 

Running Test on NETMF Step 5:

Firstly on the left side select ".NET Micro Framework" --> Transport: Emulator  & Device: Microsoft Emulator

Tick "Generate native stubs for internal methods"

Image 14

 

Running Test on NETMF Step 6:

To see your result on output window:  Go "View" (Menu) --> Select "Output" 

 Image 15

 

Running Test on NETMF Step 7:

Build your project: Go to "Build" (Menu) --> Select "Build Solution"

Image 16

 

Running Test on NETMF Step 8:

Press "F5" or "Start" (Green button) to run:

Image 17

 

Running Test on NETMF Step 9:

If you are not able to see output result --> Go to: "Tools" (Menu) --> "Import and Export Settings"

Image 18

 

Running Test on NETMF Step 10:

Select "Export selected environment settings"

Image 19

 

Running Test on NETMF Step 11:

Select "Import and Export Settings"

Image 20

 

Running Test on NETMF Step 12:

Do not change anything and click "Finish"

Image 21

 

Running Test on NETMF Step 13:

Now again run your project "F5" or press "Start" then you will see something like below picture.

You will see your text here "This is first project on NETMF"

Image 22

 

Running Test on NETMF Step 14:

Debugging: Debugging in NET MF is as easy as on .NET platform. Click on left side where I have drawn "red line" to point red circle --> then run project "F5" --> to go through code press "F11" --> you can use "Call Stack", "Immediate Window", "Locals", "Watch"

Image 23

Press "F11":

Image 24

 

 

Setup Device  PC Steps:

Tip : You should not produce any static electricity via rubbing body or anything on your board to avoid discharge your board.

Setup Device on PC Step 1: "Red Board"

In this section I just explained GHI Electronics devices (FEZ), to have more information please go to: https://www.ghielectronics.com/docs/230/netmf-processor-setup

There are two types: First one is red board --> you should connect USB cable from computer to black board.

Image 25

 

Setup Device on PC Step 2: "Black Board" or "Gadgeteer"

The second one is black board which is called "Gadgeteer" --> you should connect wire from black board ("Gadgeteer") to "D" labeled socket on red board --> then connect via USB cable from your PC to his red board

Image 26

 

Setup Device on PC Step 3: "Wait to Load Driver"

Fez Config: You will see window like this --> Select "USB" & Device Name: "X" --> Then click on "Check Update"

Image 27

 

Setup Device on PC Step 4: "MFDeploy"

Actually "NETMF SDK" from "MFDeploy" and here it helps us to get it if our device was connected properly or not?

Go to: Start --> Select  ".Net Micro Framework Deploy"

Image 28

 

Image 29

You should see "Confirm Message" which includes: "Pinging ...  TinyCLR" --> So now everything is ok by now.

Image 30

 

Setup Device on PC Step 5: "Convert from Emulator mode to device mode"

On your solution explorer right click on project name --> select "properties" 

Image 31

On the left side select ".NET Micro Framework" --> ( Transport = USB )  &  ( Device = your Device Name  )

Image 32

Installing Gadgeteer Steps:

Installing Gadgeteer on your PC Step 1: 

If your device is belong to "black board" such below picture so you have to install "Gadgeteer".

Go to: https://gadgeteer.codeplex.com/releases/view/119122

Image 33

 

Image 34

 

Installing Gadgeteer on your PC Step 2:

Expand zip file and run .exe

Image 35

Allow it to install and wait until it is finished.

Image 36

 

 

Requirement Assemblies Steps:

Requirement Assemblies Step 1: 

On Solution Explorer --> right click on References Folder --> select "Add Reference"

Image 37

 

Requirement Assemblies Step 2: 

You need these selected references for now select them and click on "OK"

Image 38

 

Requirement Assemblies Step 3: 

Add these references to your "program.cs"

C#
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Runtime.CompilerServices;
using Microsoft.SPOT.Presentation.Media;
using System.Diagnostics;

 

Turn on and Blink LED Steps:

Turn on LED Step 1: 

Read carefully catalog or any guidance text on your board. If it mentions:

( Output pins can be in "0" or "1" states )

"This board is powered off 3.3V"  --> pin set to "1" you have  ~ 3.3V  (near 3.3V) on output pin

                                                  --> pin set to "0" you have  ~ 0V  (near 0V) on output pin

 

Turn on LED Step 2: 

FEZ boards have LED pin. Now I want to write a sample code to turn on LED either totally or on the FEZ board:

For having more information please look at: http://www.ghielectronics.com/downloads/FEZ/Beginners%20guide%20to%20NETMF.pdf

Image 39

Developers use "Thread" for making interrupt inside code (albeit in a very simple description). Here I used Thread.Sleep(Timeout.Infinite); --> It causes to LED turn on Infinitely. If you insert value according to millisecond this LED will be blinked 

C#
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Runtime.CompilerServices;
using Microsoft.SPOT.Presentation.Media;
using System.Diagnostics;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
           
            OutputPort <code>LED</code>;
            <code>LED</code> = new OutputPort((Cpu.Pin)4, true);
            Thread.Sleep(Timeout.Infinite);
           
        }

    }
}

 

Or by adding "GHIElectronics" to your references and write:

 

C#
using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
OutputPort <code>LED</code>;
<code>LED</code> = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
Thread.Sleep(Timeout.Infinite);
}
}
}

 

Blink LED Step 1: 

C#
using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
OutputPort LED;
LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
while (true)
{
LED.Write(!LED.Read());
Thread.Sleep(300);
}
}
}
}

 

 

Measuring Temprature by NETduino Steps:

For having more information please look at: http://forums.netduino.com/index.php?/topic/1008-analog-in-put-c-coding/

C#
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NDP_SocketSender1
{
    public class Program
    {
        public static void Main()
        {
       
            AnalogInput a5 = new AnalogInput(Pins.GPIO_PIN_A5);

            while (true)
            {
                string s = a5.Read().ToString();
                Debug.Print(s);
                Thread.Sleep(200);
            }
        }
    }
}

 

Measuring Vibration by FEZ Steps:

For having more information please look at: https://www.ghielectronics.com/community/forum/topic?id=4013

You can measure vibration for setting alarm, you need "  Piezo electric transducer, 30Vp-p   "

C#
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Runtime.CompilerServices;
using Microsoft.SPOT.Presentation.Media;
using System.Diagnostics;
using GHIElectronics.NETMF.FEZ;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
            GHIElectronics.NETMF.Hardware.AnalogIn analog= new GHIElectronics.NETMF.Hardware.AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain0);

analog.SetLinearScale(-512, 512);

            int MaxVibration = 0;
            int analog_Value=0;
            while (true)
            {
                
                Thread.Sleep(50000);
                
                
                
                MaxVibration = 0;
                for (int Count = 0; Count < 1000; Count++)
                {
                    
                    analog_Value = analog.Read();


                    analog_Value = System.Math.Abs(analog_Value);

                    if (MaxVibration < analog_Value)
                    {
                        MaxVibration = analog_Value;
                    }
                }

                if (MaxVibration > 100)
                {
                    led.Write(true);
                }
                else
                {
                    led.Write(false);
                }

            }

    
        }

    }
}

 

Measuring GPS by NETduino Steps:

For having more information please look at:

http://bobcravens.com/2010/09/gps-using-the-netduino/

http://forums.netduino.com/index.php?/topic/37-yet-another-supported-shield-question-gps/

C#
using System;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.Text;
using System.Runtime.CompilerServices;
using Microsoft.SPOT.Presentation.Media;
using System.Diagnostics;

namespace MFConsoleApplication1
{
    public class Program
    {
       
        public static void Main()
        {

           SerialPort serialPort = new SerialPort("COM1", 4800, Parity.None, 8, StopBits.One);
            serialPort.Open();

          OutputPort powerPin = new OutputPort(Pins.GPIO_PIN_D2, false);
 
            while (true)
            {
                int bytesToRead = serialPort.BytesToRead;
                if (bytesToRead > 0)
                {
                    // waiting ........
                    byte[] buffer = new byte[bytesToRead];
                    serialPort.Read(buffer, 0, buffer.Length);
                    // print out our received data
                    Debug.Print(new String(System.Text.Encoding.UTF8.GetChars(buffer)));
                }
 
                Thread.Sleep(100); // wait ......
            }


 }

    }
}

Netduino Shape:

Image 40

GPS Shield:

Image 41

References:

http://www.netmf.com/get-started/

https://www.ghielectronics.com

http://netduino.com/

http://netmf.codeplex.com/

 

 

 

Feedback

Feel free to leave any feedback on this article; it is a pleasure to see your comments and vote about this code. If you have any questions, please do not hesitate to ask me here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Doctorandin Technische Universität Berlin
Iran (Islamic Republic of) Iran (Islamic Republic of)
I have been working with different technologies and data more than 10 years.
I`d like to challenge with complex problem, then make it easy for using everyone. This is the best joy.

ICT Master in Norway 2013
Doctorandin at Technische Universität Berlin in Data Scientist ( currently )
-------------------------------------------------------------
Diamond is nothing except the pieces of the coal which have continued their activities finally they have become Diamond.

http://www.repocomp.com/

Comments and Discussions

 
PraiseGreat Article Pin
VR Karthikeyan27-Dec-15 17:42
professionalVR Karthikeyan27-Dec-15 17:42 
GeneralRe: Great Article Pin
Mahsa Hassankashi14-Aug-16 6:42
Mahsa Hassankashi14-Aug-16 6:42 
GeneralMy vote of 5 Pin
Dariush Tasdighi8-Apr-15 20:33
Dariush Tasdighi8-Apr-15 20:33 
QuestionHow to buy NET Gadgeteer Pin
Mekki Ahmedi9-Feb-15 22:05
Mekki Ahmedi9-Feb-15 22:05 
AnswerRe: How to buy NET Gadgeteer Pin
Mahsa Hassankashi14-Aug-16 6:42
Mahsa Hassankashi14-Aug-16 6:42 
GeneralMy vote of 5 Pin
Igor Ladnik22-Nov-14 6:43
professionalIgor Ladnik22-Nov-14 6:43 
GeneralRe: My vote of 5 Pin
Mahsa Hassankashi22-Nov-14 7:39
Mahsa Hassankashi22-Nov-14 7:39 
GeneralMy vote of 5 Pin
Guruprasad.K.Basavaraju18-Nov-14 6:39
professionalGuruprasad.K.Basavaraju18-Nov-14 6:39 
GeneralRe: My vote of 5 Pin
Mahsa Hassankashi18-Nov-14 7:59
Mahsa Hassankashi18-Nov-14 7:59 
Questionwhich hardwares are required to startup for beginners Pin
Darshan.Pa11-Nov-14 20:25
professionalDarshan.Pa11-Nov-14 20:25 
AnswerRe: which hardwares are required to startup for beginners Pin
Mahsa Hassankashi12-Nov-14 2:00
Mahsa Hassankashi12-Nov-14 2:00 
GeneralRe: which hardwares are required to startup for beginners Pin
Darshan.Pa12-Nov-14 17:47
professionalDarshan.Pa12-Nov-14 17:47 
GeneralRe: which hardwares are required to startup for beginners Pin
Mahsa Hassankashi12-Nov-14 23:04
Mahsa Hassankashi12-Nov-14 23:04 
QuestionGreat article! Pin
Fernando A. Gomez F.10-Nov-14 8:39
Fernando A. Gomez F.10-Nov-14 8:39 
AnswerRe: Great article! Pin
Mahsa Hassankashi11-Nov-14 0:44
Mahsa Hassankashi11-Nov-14 0:44 
GeneralMy vote of 5 Pin
darkliahos10-Nov-14 2:43
darkliahos10-Nov-14 2:43 
GeneralRe: My vote of 5 Pin
Mahsa Hassankashi10-Nov-14 3:20
Mahsa Hassankashi10-Nov-14 3:20 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun9-Nov-14 22:01
Humayun Kabir Mamun9-Nov-14 22:01 
GeneralRe: My vote of 5 Pin
Mahsa Hassankashi10-Nov-14 3:20
Mahsa Hassankashi10-Nov-14 3:20 
QuestionGreat Article! Pin
Grasshopper.iics9-Nov-14 18:34
Grasshopper.iics9-Nov-14 18:34 
AnswerRe: Great Article! Pin
Mahsa Hassankashi9-Nov-14 18:37
Mahsa Hassankashi9-Nov-14 18:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.