Netduino home hardware projects downloads community

Jump to content


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

How to wire up the serial port


  • Please log in to reply
6 replies to this topic

#1 remllik

remllik

    New Member

  • Members
  • Pip
  • 3 posts

Posted 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 port.open 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()
        {
            serialPort.Open();

            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);

            Thread.Sleep(Timeout.Infinite);
        }

        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());
        }
    }
}



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 17 August 2010 - 06:32 PM

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.

Does that mean you connected Netduino pins directly to PC RS232 connector?

#3 remllik

remllik

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 August 2010 - 06:42 PM

Yes. I used a serial cable from the computer. I cut the end of the cable off to expose the wires.

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 17 August 2010 - 06:51 PM

Yes. I used a serial cable from the computer. I cut the end of the cable off to expose the wires.

Unfortunately, this does not work, because of different voltages - Netduino outputs serial signals at 3.3 V, while RS-232 requires voltage about ±10~12 V. You need a special converter cable or IC.

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 August 2010 - 07:09 PM

CW2 is right. You need a 3.3V (chip voltage) cable. Please don't feed 12V to the Netduino :) A few options... USB to TTL cable: http://www.adafruit....45194e0cdec2fb3 RS232 shield: http://www.cutedigi....roducts_id=4329 Chris

#6 remllik

remllik

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 August 2010 - 07:11 PM

Thanks. I guess I will need an RS232 shield? If that is the case I might use an ethernet shield or usb shield instead.

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 August 2010 - 07:20 AM

Thanks. I guess I will need an RS232 shield? If that is the case I might use an ethernet shield or usb shield instead.


I'd recommend using an RS232 shield. The Ethernet shields and USB shields require drivers. We're working on some solutions there, but they're a ways out... RS232 works today, and the shields are about $15 if I remember right. USB to TTL cables are even less...

Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.