Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.


Member Since 17 Aug 2010
Offline Last Active Sep 03 2010 07:35 PM

Topics I've Started

How to wire up the serial port

17 August 2010 - 06:24 PM

I am trying to wire up the serial port and have the AdvancedButton demo send a message when the button is pressed. I am trying to use HyperTerminal to monitor the messages from the NetDuino.

I connected pin 5 on the serial cable to Gnd next to digital pin 13.
I tried connecting Pin 2 on the serial cable to D0 and Pin 3 to D1.

Hyperterminal is configured for 4800,8,N,1 with no handshaking.

Here is the code I am using. Stepping through the code the works and the send returns 12 bytes written.

Am I doing anything wrong?

using System;
using System.IO.Ports;
using System.Text;                              // UTF Encoding
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
    public class Program
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        //instantiate the serial port connection                           
        static SerialPort serialPort = new SerialPort("COM1", 4800, Parity.None, 8, StopBits.One);

        public static void Main()

            if (serialPort.IsOpen)
                Debug.Print("Serial Port is open.");

            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);


        static void button_OnInterrupt(uint data1, uint data2, DateTime time)
            // Set the led
            led.Write(data2 == 0);

            // Encode to UTF8
            UTF8Encoding enc = new UTF8Encoding();
            // Encode Byte array
            string tempString = "Button Press";
            byte[] tempData = enc.GetBytes(tempString);
            // Write to Serial Port
            int bytesWritten = serialPort.Write(tempData, 0, tempData.Length);

            Debug.Print("Bytes Written" + bytesWritten.ToString());

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.