Thursday, March 3, 2011

Simple Netduino plus example

Time for your first Netduino plus project. Let's build a very basic example to make sure everything is working correctly. If you have not installed all the software yet, see my previous blog post on how to setup your development environment.
  • Launch Visual Studio
  • Choose to create a new project
    • Select "Netduino Plus Application" and name the project "NetduinoPlusSimpleExample".
    • Enter the following code in the Main method
      • On line #3 we declare the on-board LED as an output port. The second parameter we set the default value to "false" (low or off).
      • Then we create an infinite loop.
      • Inside the loop on line #6 we write to the on-board LED true (high or on).
      • Line #7 we pause the application for one second
      • Then we turn off the LED for one second.
      • This loop will continue until you reset the Netduino plus or upload another program.
    public static void Main()
            {
                OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
                while (true)
                {
                    led.Write(true);
                    Thread.Sleep(1000);
                    led.Write(false);
                    Thread.Sleep(1000);
                }
            }
    


    • Now that we have the program written we are going to upload it to the Netduino. Attach a mini-USB cable to the Netduino plus and plug into a USB port. If you receive a driver error you must confirm or re-install the Netduino drivers.
    • Now we need to tell Visual Studio to run the program on the Netduino plus board and not the emulator. I have not found the emulator to be very useful as it does not display any outputs.
    • Right click on your project "NetduinoPlusSimpleExample" > "Properties"
    • Select the ".Net Micro Framework" tab and change the following settings.
      • Transport: USB
      • Device: NetduinoPlus_NetduinoPlus
    • Save your changes
    • Let's run the program. Select "Debug" > "Run" or F5
    • Here is a video of the program running on my Netduino plus

    • Download the complete project

    No comments:

    Post a Comment