Hello Netduino!

(c) Bertrand Le Roy 2010We’re makers, all of us, we build stuff for work and pleasure. Software development is a great discipline for people like us as the ticket to entry is relatively modest. All you need is a computer and that is pretty much it. There is no real limit to what you can do.

Today, hobbyist electronics are blooming thanks to the availability of the universal logical components that are microcontrollers. Open-source hardware platforms such as the Arduino give anyone the ability to build pretty much anything they can think of for a few dozen dollars.

Microcontrollers are for all practical intents and purposes small computers with a bunch of digital and analogic inputs and outputs. They are more powerful than the multi-hundred dollars Ataris and Commodores I was playing with in my youth. And now, they can even be programmed in C# and debugged from Visual Studio.

Today, with the help of my friend Fabien, I started playing with one such microcontroller: a Netduino, which you can buy for $34.95. After stealing the micro-USB cable from my Kindle (most smartphones come with one too) and downloading the .NET Micro-Framework and the Netduino software, I was able to write my first program, which is just blinking the on-board LED until someone presses the on-board button:

public static void Main() {
    var ledPort = new OutputPort(Pins.ONBOARD_LED, false);
    var switchPort = new InputPort(Pins.ONBOARD_SW1, false,
Port.ResistorMode.Disabled); while (switchPort.Read()) { ledPort.Write(DateTime.Now.Second % 2 == 0); Thread.Sleep(100); } }

Here, I’m opening a port to the LED and a port from the button. Don’t worry about the other parameters for now, they are advanced features that you don’t need to know about just now. I haven’t myself taken the time yet to dive in there.

I’m then reading the button state until it’s false (counter-intuitive, but false is pressed). In the loop, I’m getting the state of the LED to toggle every second and tell the controller to sleep for 100ms until the next iteration.

That’s nice but how about some real hardware interaction? Well, we’ll do some of that next time but before I conclude this short post, here are a few little tricks I learned along the way…

  • Even though the Netduino has a power plug, you don’t need a power supply until you build autonomous projects: the USB cable is perfectly sufficient to power the microcontroller while connected to a computer.
  • You’re going to build your projects on a breadboard, and microcontrollers dangling to a USB cable have a natural tendency to wiggle around and fall off the table. Just get a big rubber band and use it to secure the microcontroller on the breadboard.
  • You’re going to need lots and lots of wires so buy a lot. The nicest to use are jumper wires, which take about a tenth of a second to plug or unplug into your Netduino ports or into a breadboard.
  • Oh, and resistors too. Well, we’ll include a big nice shopping list to the next post.

No Comments