Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

First Experiences with Netduino and the .NET Micro Framework

Pete Brown - 02 September 2010

I like gadgets. Some of the coolest gadgets are add-on boards like the Freescale board that works with the Win7 Sensor and Location API. Recently, Arduino and Netduino caught my eye. Arduino is an open source hardware platform / microcontroller with a long history. The specification for the board is completely open, allowing anyone to build one themselves, or purchase a pre-built one. Coding is typically done in C++. Tons of projects have been built on it over the years.

image 

License and Specs

Netduino is brand new Arduino-compatible board. It runs the .NET Micro Framework and, like the Arduino, is open source with a published schematic, making it possible for anyone to build or buy one. The .NET Micro Framework 4.1 source code is available under the Apache 2.0 license, making it easy to build custom boards. The licenses for Netduino itself are:

  • Hardware: Creative Commons-Attribution
  • Documentation: Creative Commons-Attribution+ShareAlike
  • Firmware: Apache 2.0 License

The boards are built to common specs. I've listed the interesting processor, memory, and I/O specs below.

Processor / Memory Specs

  • Atmel 32-bit microcontroller
  • Speed: 48MHz, ARM7
  • Code Storage: 128 KB
  • RAM: 60 KB

Digital and Analog I/O Specs

  • all 20 digital and analog pins: GPIO
  • digital pins 0-1: UART 1 RX, TX
  • digital pins 2-3: UART 2 RX, TX
  • digital pins 5-6: PWM, PWM
  • digital pins 7-8: UART 2 RTS, CTS
  • digital pins 9-10: PWM, PWM
  • digital pins 11-13: SPI MOSI, MISO, SPCK
  • analog pins 4-5: I2C SDA, SCL

The board itself can be powered via USB, a separate 9v power supply, or a 9v battery brick. The battery option lets you build robots and other mobile awesomeness with this board.

What can you do with it?

Imagine you just built a computer, but have left off the keyboard, mouse, display and drives. All you have included is the motherboard, CPU, memory, power LED and one extra LED. That's basically the situation you're in with this board. The real fun of working with a Microcontroller is wiring it up to other stuff. There are servo controllers, GPS units, wireless networking, 7-segment LEDs, temperature and light sensors and more. If you're not skilled in electronics (I am not), you can pick up project packs and tutorial books that will help you out.

Since I'm on campus at the moment, using my tablet PC, in a spare office, I don't have anything else I can wire this to. The bare board configuration really only provides one I/O device: a LED you can blink :)

Getting Started

What you'll need:

  • Netduino
  • USB Cable (early Netduino units come with the USB cable)
  • Visual Studio 2010 and the .NET Micro Framework 4.1 SDK  (you can use C# Express 2010 if you don't have Visual Studio)
  • Netduino SDK in 32 bit or 64 bit, depending on your host OS.
  • Optional: shields and starter kits to do cool things with netduino. Existing Arduino shields are compatible. A shield is just an add-on card that fits the pins on the board.

The SDK installs a device driver for talking to the Netduino. Make sure you select the one with the appropriate bitness, and that you install it before connecting the Netduino to the PC. I installed the VS2010 bits before the SDK, but it shouldn't matter.

Once you plug in the Netduino, using the USB cable, you should see the device driver get installed, and the power LED on the board light up.

First Netduino Program

Open up Visual Studio. With the correct install of the Micro Framework 4.1 SDK for Visual Studio 2010, you should see a new category and some new project types:

image

Once the project is created, you'll end up with a single code file: Program.cs. Think of this structure the same way you would a console app. It starts off looking like this:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
{
    public class Program
    {
        public static void Main()
        {
            // write your code here


        }

    }
}

Hmm. Looks like someone forgot to FXCop their namespace names :)

Der BlinkenLED

Earlier, I mentioned that about the only thing you can do with a bare board is blink the LED. So, that's what we'll do.

I'm going to make the assumption that almost everyone reading this is a .NET programmer. If you're not a .NET programmer, check out our beginner dev center on MSDN.

Getting the LED to blink is pretty simple. You create an OutputPort instance that you use as a wrapper for a particular pin or port on the board. Then you tell it to send true or false to this port. True turns the LED on, false turns it off. Complete the code by adding thread sleeps in between, and you get an LED that turns on for half a second, then off for half a second.

public static void Main()
{
    OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, false);

    while (true)
    {
        onboardLed.Write(true);
        Thread.Sleep(500);

        onboardLed.Write(false);
        Thread.Sleep(500);
    }
}

With that code in place, it's time to deploy and test.

Deployment

The project will run in an emulator by default. To change this, go into the project properties, click the .NET Micro Framework tab, and change the transport to USB.

image

Once you do that, save and build/run your project. If all goes well, you'll see the blinking LED.

Stopping it

Stop debugging. Hmm. The board is still blinking. Of course it is! We added an endless loop. How on earth do I stop it? Unplugging it doesn't work because your new BlinkenLED program is on the firmware.

The easiest way to stop it is to deploy an empty application. Of course, if you deploy when the LED is on, the LED will stay on (presumably) forever. If you want to be clean about it, make it an application that turns the LED on once as a test, then turns it off for good.

public static void Main()
{
    OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, true);
    Thread.Sleep(2000);
    onboardLed.Write(false);
}

Unplug the board and plug it back in. You'll see the same two second LED each time. You'll notice a single flicker in that because the board naturally lights the LED for a second or so during startup anyway.

More complex interactions with boards are usually just a wrapped set of inputport and outputport interactions. Those friendly wrappers are called "drivers" in the arduino world.

To be Continued

I'm off to Fry's here in WA to get something unrelated, but while there, I'll see what kind of goodies they have that I can use with the Netduino. If anything cool, I'll put up another post while I'm here on campus :)

             
posted by Pete Brown on Thursday, September 2, 2010
filed under:              

26 comments for “First Experiences with Netduino and the .NET Micro Framework”

  1. Petesays:
    @Kelps

    It's compatible with most, if not all, Arduino shields. The pins are the same. You'll need to create your own wrapper (driver) classes, however.

    Only difference I've seen so far is one of the pins is 3.3v rather than 5v.

    Pete
  2. Massimo Banzisays:
    Hello

    Just to clarify.

    Arduino is programmed in C++. What the Arduino IDE does is to hide the parts of C++ that beginners might find frightening at the beginning.

    When you hit the compile button an "#include" is added at the beginning of the code and prototypes are automatically generated for all the functions you wrote.

    After that is all c++.

    +3.3v IO is an issue that makes this incompatible with quite a few shields. If the input pins aren't 5v tolerant it might die on you pretty soon.

    Some shields require companion libraries to work properly (Ethernet comes to mind)

    m
  3. Ricksays:
    The Netduino does have a 5v shield pin. It is pin-for-pin compatible with the Arduino Duemilanove. However, it doesn't have the ICSP pins, though the solder holes are in the board in the same place. It also has two, slightly larger voltage regulators. Also it has a white power LED that would light up 10x10 Rm at night!

  4. JSsays:
    the lack of shield drivers makes the micro framework boards less compelling than the straight up arduino boards. maybe pete and scott hanselman can rally the troops to build some micro framework-compatible drivers; ethernet and wifi drivers would be a big, big boost to the dev community.
  5. Mike Gallaghersays:
    You say that it takes Visual Studio 2010 in order to program it.
    What is mission in the eralier versions - like Visual Studio 6.0?
    How about the various flavors of the micro versions of Linux or some of the RTOSs?
  6. Mike Gallaghersays:
    Sorry about the typos in the earlier post. Too big a hurry. I apologize. It should read:
    You say that it takes Visual Studio 2010 in order to program it.
    What is missing in the earlier versions - like Visual Studio 6.0?
    How about the various flavors of the micro versions of Linux or some of the RTOSs?
  7. Petesays:
    @Mike

    If you want to use Visual Studio, you need to use the 2010 version, which enables multi-targeting and specifically targeting .NET 4.

    You can code without VS2010, but you won't get the debugging support or auto deployment. The .NET Micro Framework is completely open source. I have zero experience with trying to code for/deploy to the Netduino outside of using Visual Studio. I'm also not aware of any work done on Linux to support the Micro Framework.

    Keep in mind you can use the free version of Visual Studio 2010 (Visual C# Expression 2010) to code for the Netduino. http://www.microsoft.com/express/downloads/

    Pete
  8. Dave Msays:
    According to Freetronics, which makes an Arduino Ethernet Shield (http://www.freetronics.com/products/ethernet-shield-with-poe):

    Compatibility

    Compatible with official Arduino models and equivalent boards such as our TwentyTen that use the standard shield header format. Tested and confirmed to work with many variants, including Duemilanove, Uno, TwentyTen, Pro, Seeeduino, and Netduino. Not directly compatible with the Arduino Mega, although it can be made to work using the same modification as the official Ethernet shield discussed here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239058804/0
  9. Gutworkssays:
    Netduino has recently released the Netduino Plus which has built-in Ethernet as well as microSD support. They start shipping on Jan 7, so you had better get your orders in. The costs is $59.99 CDN/US compared to $34.99 for the standard version.

    http://netduino.com/netduinoplus/specs.htm

  10. James Taylorsays:
    Hi Pete. Thanks for this very informative article. I just gave you a shout out on the Microsoft Training and Certification forum in the following thread.

    http://social.microsoft.com/Forums/en/CertGeneral/thread/f598d847-e468-4c7e-a017-99028cb3f848

    It's through you that I discovered the Netduino and the .NET Micro Framework, and I wanted to share this with my colleagues on the forum. For those of us on the forum doing Microsoft .NET exams, I believe the Netduino could be a fun educational tool to enhance our learning and spice up or training, so I shared this information.

    BTW, I just received my own Netduino, so I'm looking forward to experiencing all its joys. Thanks again for a very helpful article.
  11. James Taylorsays:
    Hi Pete. Thanks for this very informative article. I just gave you a shout out on the Microsoft Training and Certification forum in the following thread.

    http://social.microsoft.com/Forums/en/CertGeneral/thread/f598d847-e468-4c7e-a017-99028cb3f848

    It's through you that I discovered the Netduino and the .NET Micro Framework, and I wanted to share this with my colleagues on the forum. For those of us on the forum doing Microsoft .NET exams, I believe the Netduino could be a fun educational tool to enhance our learning and spice up or training, so I shared this information.

    BTW, I just received my own Netduino, so I'm looking forward to experiencing all its joys. Thanks again for a very helpful article.
  12. Drestumsays:
    дрессировка ягдтерьера [url=http://dressirovat-sobaku.dressirovka-shenkov.ru]курс дрессировки немецкой овчарки[/url] курс послушания для собак [url=http://vidy-dressirovki-sobak.dressirovka-shenkov.ru]стоимость обучения собаки[/url] курсы послушания для собак [url=http://obschiy-kurs-dressirovki.dressirovka-shenkov.ru ]дрессировка бультерьера в домашних условиях[/url] начало дрессировки щенка

Comment on this Post

Remember me