Friday, February 21, 2014

Netduino 2 Getting Started

While I'm waiting for my other parts to come in, I got one of these Netduino's a while back to try out. After all, most of my programming experience is in .Net, not C! So for $35 I figured this board is worth a try. The board touts an ARM 7 processor with multi-processing capability and a form factor that almost exactly matches the Arduino Uno. So all the Uno proto shields can be used with this board. You can write code for it using Visual Studio and C# which is pretty sweet.

Getting started is pretty simple, especially if you already use C#.Net for other programming projects.
You'll need to install 3 things to get going:

http://www.netduino.com/

  1. MS Visual Studio C# Express 2010
  2. Net MicroFramework 4.2 SDK
  3. Netduino SDK v4.2.2.0 (32-bit) or Netduino SDK v4.2.2.0 (64-bit)

And of course.. you need a Netduino 2 ($34.95)

To create a new Application for the Arduino 2, open Visual Studio and create a new project.
When the dialog comes up select Micro Framework and Netduino 2 Application.



I want to debug on the real hardware, not using the Emulator. To do this I'm going to set the Project properties for the .Net Micro Framework:

  1. Make sure the Netduino is plugged into the computers USB port so it will show up in the device list.
  2. Change the Transport to USB and select Netduino2_Netduino as the device.

That's all it takes to be able to debug your code on the hardware. I can now run my code in debug mode, directly on the Netduino 2!

Now just write a little code to blink the blue on board LED (to the right of the board) in program.cs. Here is some code:

namespace NetduinoApplication1
{
    public class Program
    {
        public static void Main()
        {
            // Create an Output port for the Onboard led pin and set it to false.
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            // Blink the LED
            Blink(led);
        }

        // Blink the LED at 250ms on/off intervals
        public static void Blink(OutputPort led)
        {
            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 the run button to start debugging, the blue LED will blink..  Hello World Netduino!

More information about the Netduino can be found at Netduino.com.