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

Serial port data transfer code and connection help !!!


  • Please log in to reply
4 replies to this topic

#1 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 18 August 2011 - 01:54 PM

Hi, I am want to transfer the string (say "hello world") to my pc using the serial port (Com1). But i don't have any idea how to make the connection. I have a female socket in my PC for this COM1 port through which i want to send this string. I also need your help to code this solution. if you can give me the c# code and the hardware connection details i'll be great full to you. Regards

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 August 2011 - 02:02 PM

With a netduino classic or plus you need a TTL to RS232 converter. I used two successfully: http://wiki.netduino...hifter-SMD.ashx http://wiki.netduino...-to-Serial.ashx perhaps this thread could help you with code: http://forums.netdui...rt-code-review/
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Dan Morphis

Dan Morphis

    Advanced Member

  • Members
  • PipPipPip
  • 188 posts

Posted 18 August 2011 - 06:22 PM

With a netduino classic or plus you need a TTL to RS232 converter. I used two successfully:
http://wiki.netduino...hifter-SMD.ashx
http://wiki.netduino...-to-Serial.ashx

perhaps this thread could help you with code:
http://forums.netdui...rt-code-review/


You can also wire up a USB->Serial adapter directly to the serial pins on the Netduino. But be very careful. Some USB->Serial adapters output 12v and that will cook your Netduino (unless you use a level shifter). The USB->Serial adapter I have happens to put out TTL levels.

-dan

#4 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 02 September 2011 - 09:34 AM

Hi,

As per your suggestions i did the following:

I connected the digital I/O pins 0 and 1 to the MAX232 ic's to convert the rs323 signal to ttl standard for the incoming receive signal and ttl signal to rs232 standard for the netduino's outgoing transmit signal. then i connected the GND from the netduino to the GND of the rs232 cable(with female connector) and the respective receive and transmit signal pins of the cable to the max 232's respective pins.

Then i connected the other end of the cable to my pc with the following code:

Netduino Code:

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

namespace RFCOM
{
    public class Program
    {

        public static void Main()
        {
            SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            port.Open();
            OutputPort o1 = new OutputPort(Pins.ONBOARD_LED, false);
            string message = "Hello World";
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            while (true)
            {
                o1.Write(true);
                port.Write(bytes, 0, bytes.Length);
                System.Threading.Thread.Sleep(1000);
                o1.Write(false);
                System.Threading.Thread.Sleep(1000);
            }
            
            

        }

    }
}

PC code:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace SmartDeviceProject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private SerialPort port = new SerialPort("COM1",9600, Parity.None, 8, StopBits.One);


        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text="Incoming Data:";
            // Begin communications 
            port.Open();
            textBox1.Text = "Port Opened";
            // Attach a method to be called when there
            // is data waiting in the port's buffer 
            port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
            textBox1.Text = "Data recieve function called";
            // Enter an application loop to keep this thread alive 
            
        }
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        { // Show all the incoming data in the port's buffer 
            Console.WriteLine(port.ReadExisting());
            textBox1.Text = port.ReadExisting().ToString();
        }
    }
}


But inspite of trying the above, data is not transmitting from the netduino to the PC

Edited by Stefan, 02 September 2011 - 10:10 AM.
Added [code]-tags


#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 September 2011 - 01:34 PM

Wow...there are many points where to investigate!
The code seems OK.

Here is a checklist:
  • here are the MAX232 specs, and the circuit is depicted in figure 5;
  • if you own a multimeter, check the voltages as indicates in the Max232 schematic;
  • the TX data output of the Netduino is on I/O #3, it must be connected to the pin 10 (or 11) of the Max232;
  • the related TXD (RS232 side) is on pin 7 (or 14) of the MAX232, and must be connected to the RXD of the PC RS232 connector.
The above checklist should be enough for transfer data FROM the Netduino TO the PC.

For the opposite direction check these additional points:
  • the RX data input of the Netduino is on I/O #2, it must be connected to the pin 12 (or 9) of the MAX232;
  • the related RXD (RS232 side) is pin 13 (or 8) of the MAX232, and must be connected to the TXD of the PC RS232 connector.

Also, take care about the RS232 connector (DB9 or DB25) pinout: I always find confusing, and it is very easy to mistake the correct pins.
Cheers
Biggest fault of Netduino? It runs by electricity.




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.