I’ve always found embedded programming on microcontrollers to be very fascinating and fun, whether it is using the Lego Mind Storm robotics system or C on an Intel 8051 microcontroller. To program a microcontroller to sense the outside world through sensors or control some device such as a motor, or servo, or actuator is very cool. I’ve taken a look at the Microsoft .Net Micro Framework numerous times but have never really had the opportunity to do much with it (other than the sample programs that come with the framework install that run on the emulator). I’ve looked at some of the development kits that are out there that run the Micro Framework but I wasn’t willing to spend the $300+ to get started. After reading a couple of blog posts by Scott Hanselman and Pete Brown I discovered the the Netduino as an inexpensive ($34.99 + S&H) development board to get started with (I actually purchased my board from a company out of Canada because S&H was only $4 versus the $7 that a similar US company was charging. I guess it is cheaper to outsource.).
Netduino
Technical Specs
- Atmel 32-bit microcontroller
- Speed: 48 Mhz, ARM7
- Code Storage: 128 KB
- RAM: 60 KB
- 20 Digital and Analog GPIO pins
The rest of the specs for the Netduino can be found on their website here.
The Netduino is an Arduino compatible open source board, which means that the schematics are available for download and you are free to build your own board if you so desire. It also means that you can extend the functionality of the Netduino by attaching various Arduino compatible modules called “Shields” since all Arduino compatible boards must be designed with a standard socket configuration allow for the shields to be easily added on top of the Arduino boards.
Arduino with an Ethernet Shield attached.
Motor Controller Shield for controlling DC motors and Servos.
Prototyping Shield.
There are also shields for GPS, GSM cellular, Zigbee, and touch screens. As you can see you can really extend the functionality of the Netduino well beyond the basic controller. (One note of caution, some shields come with drivers that need to be installed on the Micro Framework board. Some shields such as GSM cellular’s drivers may be too large to install in the available memory on the board.)
Microsoft .Net Micro Framework
The .Net Micro Framework is a subset of the .Net Framework that is even smaller than the .Net Compact Framework. Unlike the .Net Framework or the Compact framework, the Micro Framework does not require a host OS in order for it to run. The Micro Framework has a hardware abstraction layer which allows for it to run on the bare metal. You can also install and run the Micro Framework on a host OS if your requirements are such. Also unlike the Compact Framework, the Micro Framework is now open source under the Apache 2.0 license agreement making it a very cheap option for embedded devices when compared to the cost of the embedded OS such as CE that is need to run the Compact Framework. You can download the Micro Framework and find additional information on Microsoft’s MF website located here.
Getting Started
To get started developing in the Micro Frame work you must first either install Microsoft Visual Studio 2010 or install the Microsoft Visual C# Express 2010. Once Visual Studio is installed download and install the .NET Micro Framework SDK v4.1. Last download and install the Netduino SDK v4.1.0 (either the 32-bit or 64-bit version depending on your OS) from the Netduino website here.
Once Visual Studio and the software SDKs have been installed you can attached the Netduino to your computer via USB with the USB cable supplied with Netduino board.
The first project I created was a simple “Hello World” app (Netduino style) which made the onboard user LED blink on and off. (whoooo I know, how exciting. It gets better trust me) I select “Console Application” from the Micro Framework template in VS 2010.
Next I had to go into the project properties and tell Visual Studio to deploy via USB and select the Netduino device from my device list. If you don’t it defaults to using the emulator.
Next I added references to the Netduino libraries.
The code required to turn on and off the user LED is very simple. Basically you set the OutputPort to the use the user LED and then you toggle it back and forth between 1 and 0 with the .Write() method on the OutputPort object. This is the object you will instantiate when you want to interface with any of the GPIO pins.
public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
led.Write(true); // turn on the LED
Thread.Sleep(250); // sleep for 250ms
led.Write(false); // turn off the LED
Thread.Sleep(250); // sleep for 250ms
}
}
Press F5 to compile and run in debug. Visual Studio will take care of deploying the source code over to the Netduino and starts running it on the device. While running in debug and connected to the Netduino you can set breakpoints and step through your code all while running on the device.
Conclusion
As you can see there really isn’t much to getting the .Net Micro Framework installed and getting your first app up and running on the Netduino. The entire process of installing both SDK’s and write/deploying that first HelloWorld app too me less than 10 minutes. It’s really nice to be able to use the tools and languages that I’m familiar with and use everyday in my normal job.
Now I know this was a pretty simple example with not a lot of code to show but I just wanted to give a quick introduction to the .Net Micro Framework and the Netduino board before I move onto some more in-depth examples. I’ve already started working on a project that will use the Netduino to interface with a DS1621 Temperature sensor that communicates over the I2C (pronounced ‘I’ Squared ‘C’) 2-wire communications bus. I’m hoping have that project and blog post ready to publish by the end of this weekend. Stay tuned!


