Netduino and .NET Micro Framework (NETMF)

Early Arduino Experimentation

I recently purchased a few things from the MakerShed which included an Arduino and a Netduio Plus. I spent a couple weekends playing around with the Arduino first because I’m mostly a Mac guy at home and the code editor was available for Mac. I was up and running in under a couple minutes.

My first impression was that it was a lot like working with the BASIC stamps I had used for years except with the tremendous benefit of there being a Mini USB port right on the chip. (I bought the Nano which is just the brains without the shield-breakout. It’s the same form factor as a stamp and can be placed on a breadboard.)

The programming was shockingly similar except it used a variation of C instead of BASIC. The rest was about the same. In under an hour I had a Parallax RFID reader connected on a mini breadboard, troubleshot my first problem (you can’t program the Nano while the RFID reader is wired into the Rx pin!) and had my first project.

My observations were that the code editor, while designed to make it easy for people to stitch together lines of code to get something working, made it too easy to just stitch together lines of code without doing proper encapsulation or object oriented programming. Stepping back this trait seems endemic in the hobby hardware and microcontroller areas. As a software guy myself I can’t help but cringe and I immediately started trying to figure out how to build my own classes.

And that’s when I remembered I haven’t used C in a long, long time. Using impending deadlines as an excuse, I broke off my endeavors with the Arduino and let everything sit for a couple days.

Picking Up the Netduino

A few days later I saw an announcement from MakerShed that SparkFun and Instructables had teamed up and were hosting a microcontroller contest. Any project using a microcontroller was eligible for entry. Just make a project, post an instructable and open source your code. It was a simple gimmick but it got me to pull out the Netduino and have a crack at it.

The model I bought, the Netduino Plus, comes with onboard Micro USB connector for programming and powering the board and an Ethernet jack for network communication. My initial thought was to build a small device which could plug into the network and react to predefined things.

My thought was something like a message station. Configurable watch types (check an RSS feed, poll the updated status of a web page, etc.) would be assigned configurable notification types (led light up or flash, post a twitter message, etc.) to let the microcontroller notify you.

I had thought of having a pluggable system of watches and notifications so the system could be expanded. For instance if you bought a shield with a buzzer, you could add a library that made a buzz notification to be assigned to an event.

That’s what got me to try the Netduino out rather than continue with the Arduino with which I had already started experimenting. I spent a little time getting a system up from which I could develop and deploy my applications to the Netduino and began my work. And ran into my first problem. It took me a little while to figure out why I was receiving the errors I was but in the end I figured it all out.

Unfortunately one of my solutions was to increase my available flash space by flashing out the firmware for the stock Netduino firmware which doesn’t include the TCP/IP stack for Ethernet communication. My hopes and dreams of entering the contest with that idea were dashed.

Considering my idea had very little meat for an instructable I hadn’t had high expectations of winning anyway (the contest ends Feb 13) so I decided to push ahead with the libraries I had already started developing. Though they had nothing to do with my original idea, I now sit on a modest library which implements a subset of the Linq extensions on the .NET Micro Framework 4.1. I had wanted to move a lot of it to the TinyCLR but after days of trying, and failing, to build a stock version of the firmware so I could verify it worked before making changes I gave up and kept everything in managed code.

The library contains some features with which I have grown accustomed in the .NET Framework that aren’t present in the Micro Framework. First, generics are not supported. Visual Studio will happily let you write the code and validate it but compilation will fail. Linq is also missing. And strangest of all, yield is not working. It seems it did in previous versions but the code that is auto generated by the compiler to support yield can’t be compiled due to a dependency on System.Threading.Thread.ManagedThreadId.

These limitations gave rise to NearlyGenericArrayList, MicroLinq and a ConditionalEnumerator and ConditionalEnumerable pair, respectively.

I think I struck a good balance between size and usefulness but I’m sure others will have much stronger opinions about this. While fine tuning things I expanded the project a bit to include the Nearly Generic Array List class which extends the default Array List and attempts to constrain the user into storing only one type of object in the collection. It determines if that object type (specified in the constructor) implements IComparable and if so, provides a Sort function. I wrote some demo code and this is all working quite well.

As a proof of concept which could give rise to more asynchronous or multithreaded libraries I also added a small implementation of my Parallel ForEach class I wrote and blogged about previously. This also seems to work but it’s hard to tell since the board just time slices threads to work on them and there’s no real good way that I can think of to test if concurrency problems will arise.

I’m not sure if anyone else would find the libraries and demo code useful but I like the idea of having my comfortable Linq and some nearly-generic collections at the ready. Each distinct library is in its own project which build their own DLLs so you can pick and choose which functionality you want without being burdened with size from features you don’t need.

I’m considering creating a CodePlex project for this so others can review the code, download the libraries to use, see examples and hopefully contribute but I don’t want to be the owner of one of those empty CodePlex projects that never gets any attention!



2 responses to “Netduino and .NET Micro Framework (NETMF)

  1. George Boyd Ratcliff

    Hi Erik,

    I’m starting Arduino / Netduino in exactly the same position as you – I’m a .Net (SharePoint) developer by trade, but have enjoyed dabbling with iPhone development, Basic Stamp, and now the Arduino UNO and Netduino Plus. I bought the Wifly Wifi shield too, but have been very disappointed by the number of examples or libraries for the Netduino. It has such massive potential!

    • I’ve been thinking about the WiFly shield but the lack of examples on the Netduino has been a bit of a hinderance to me. Have you had much luck with it? I’m curious at how well it performs.

      I should make an update to this post. I made a few changes to the project and from some extensive code review by Corey Kosak on the Netduino forums it is in really good shape. I put the project up on Codeplex if you’d like to use it or view the source.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s