Tagged Posts

In case you missed the announcement on 4/4, the guys and Secret Labs, along with other members of the Netduino Community have come out with a new platform called Netduino Go. Head on over www.netduino.com for the introduction forum post.

This post is how to quickly get up and running with your Netduino Go, based on Chris Walker’s getting started forum post, with some enhancements that I think will make it easier to get up and running, as Chris’ post unfortunately leaves a few things out.

Hardware

I ordered a variety of hardware when I ordered my Netduino Go here’s a list, though in this tutorial I’ll only be using a small portion of this.

  1. (1) Netduino Go
  2. (1) Shield Base Module
  3. (2) RGB LED Module
  4. (4) Button Module
  5. (1) Potentiometer Module

One thing to keep in mind with the hardware is that each module needs a cable to be able to connect to the Go, but the Go only comes with two cables. I did order a 5 pack of cables as well, and up until about 2 minutes ago thought I left them at the office, only to realize I do have them at home, which is going to change the rest of this tutorial.

Software

  1. Visual Studio 2010
  2. .NET MicroFramework V4.2

First and foremost, you need to install the .NET MicroFramework 4.2 and Visual Studio 2010 (not sure if express will work). Chris’ post assumes that you already have .Net MicroFramework V4.2 installed. You can download this from Codeplex though to be honest I don’t know if you need the PK or the SDK, I installed both.

What will the project do?

Before we get into actually creating the project, what will it be? Well this is just something simple, nothing useful, but hopefully gives you an idea how to work with the Netduino Go.

We’re going to use the Netduino Go, one Button Module, one Potentiometer Module, and 3 RGB LED Modules. The button will be used to turn the system on and off. The RGB LEDs will blink in succession, one Red, one Green and one Blue (I realized during the development that I only had 2 RGB LED Modules, so I removed Blue from the code with comments, I ordered two more they should be here Friday. The potentiometer will be used to control the timing of the light succession.

Project Creation

For the first part of this you can follow Chris Walker’s instructions posted in the thread, copied here for ease of reading.

To manually create a project for your Netduino Go:

  • Download and unzip the attached assemblies.
  • Create a new .NET Micro Framework "Console Application"
  • Add the references "GoBus.dll" and "SecretLabs.NETMF.Hardware.NetduinoGo.dll" to your project. You'll need to use the "Browse..." tab for the moment.
  • Add the references to the go!modules you'd like to use (NetduinoGo.Button.dll, Nwazet.Relay.dll, etc.)
  • At the top of your project, add the line:
using SecretLabs.NETMF.Hardware.NetduinoGo;

From here I’ll switch out of Chris’ examples and provide my own code.

Plug your NetduinoGo into the MicroUsb cable attached to your computer. It might take your PC a few moments to find the drivers.

Right click on the Project properties and be sure to change your target framework to 4.2. You’ll also want to change the Deployment options on the .NET Micro Framework tab in the project properties, Transport = USB and Device = NetduinoGo_NetduinoGo.

The first thing we’re going to do is initialize the objects we’re going to use.

static NetduinoGo.Button button = new NetduinoGo.Button(GoSockets.Socket1); 
// this button will start/stop the flashing
static NetduinoGo.RgbLed redLed = new NetduinoGo.RgbLed(GoSockets.Socket2);
// this is the socket for the first LED

static
NetduinoGo.RgbLed greenLed = new NetduinoGo.RgbLed(GoSockets.Socket3);
// this is the socket for the second LED

//static NetduinoGo.RgbLed blueLed = new NetduinoGo.RgbLed(GoSockets.Socket4);
// this is the socket for the third LED
public static bool currentState = false; // keep track of if the button was pressed to turn it on, or off static NetduinoGo.Potentiometer pt = new Potentiometer(GoSockets.Socket5);
// the potentiometer to control the speed of the LEDs

We’re going to have a single method that turns off all the LEDs, likely not the most efficient approach, but it will do what I want. We also provide the button handler event.

//method to turn off all the LEDs
static void AllOff()
{
    redLed.SetColor((byte)0, (byte)0, (byte)0);
    greenLed.SetColor((byte)0, (byte)0, (byte)0);
    //blueLed.SetColor((byte)0, (byte)0, (byte)0);
}

//button handler
static void Button_ButtonReleased(object sender, bool buttonState)
{
    currentState = !currentState; //set the state to the opposite of whatever we were before
}

The Main() for the project is a bit longer, but nothing too complex. Basically we wire up the button handler, make sure to start in the off state, and then setup our While loop. Because we’re running on a device, this loop While(true) will just loop forever.

Inside of the loop we’re going to check if we should be on or off, if on, we go through and pass through each RGB LED Module to turn it on, then sleep for a moment, how long is based on the potentiometer, and then turn off the LEDs, move on to the next color.

public static void Main()
{

    button.ButtonReleased += new NetduinoGo.Button.ButtonEventHandler(Button_ButtonReleased); 
// setup the button handler currentState = false; //make sure we start with it off while (true) //we're using a device, it will never end { if (currentState) // see if we should be displaying the LEDs or not { redLed.SetColor((byte)255, (byte)0, (byte)0); // turn on the red LED System.Threading.Thread.Sleep((int)(100 * pt.GetValue()));
// pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs greenLed.SetColor((byte)0, (byte)255, (byte)0); // turn on the green LED System.Threading.Thread.Sleep((int)(100 * pt.GetValue()));
// pause for a moment based on the potentiometer state
AllOff(); // turn off all LEDs //blueLed.SetColor((byte)0, (byte)0, (byte)255); // turn on the blue LED //System.Threading.Thread.Sleep((int)(100 * pt.GetValue()));

// pause for a moment based on the potentiometer state

//AllOff(); // turn off all LEDs } } }

Once you have all this together you need to be able to deploy the code to your Netduino. Deploying the code is easy, simply hit F5 in Visual Studio and that should send it off to your device. From there you can see how well it works.

Here’s a video of the code in action on my Netduino Go, I’ll see if I can’t get another video done when I get the third LED module in place (only 2 for now).

For another overview and tutorial check out Pete’s blog post over on 10rem.net

UPDATE

I've updated the code to work with 3 RGB LED modules, you can find the updated code on Github at https://gist.github.com/2418912 

Here's an updated video, filmed using a GoPro, let me know what you think of the video quality.

RSS URL

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.