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 use xbees to transmit the data to pc from my netduino ???


  • Please log in to reply
6 replies to this topic

#1 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 01 October 2011 - 11:19 AM

hello,

i bought two xbees , with a 3.5 to 5.0 regulated explorer for my microcontroller board and a rs232 explorer board.

XBees: My link
Uc explorer: My link
rs232 for PC: http://www.rhydolabz...products_id=482

I connected both of them and tried to send the data from my microcontroller to pc. The DOUT pin's corresponding led blinks at transmission but the pc is not receiving ant data.
I used the X-CTU software and did the configuration as guided on this blog:

My link

Please help me out with this.

I am using the c# language for developing the both microcontroller and the pc apps. Using same apps when i connected both of them through the rs232 port of my pc using the rs232<->ttl converter and the data is transmitting easily than why is there the problem with the xbees also ????

Any help ???

i wrote following code:

Netduino Code:

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

namespace DataSender
{
    public class Program
    {
        public static SerialPort s;
        public static string message = "Hello World";
        public static byte[] bytes = Encoding.UTF8.GetBytes(message);
        public static void Main()
        {
            // write your code here
            s = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
            s.Open();
            while (true)
            {
                s.Write(bytes, 0, bytes.Length);
                Thread.Sleep(3000);
            }

        }

    }
}
[code]

PC code:

[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace COMReceive
{
    public partial class Form1 : Form
    {
        private delegate void SetTextDeleg(string text);
        static SerialPort s;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            s = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
            s.Handshake = Handshake.None;
            s.Open();
            textBox1.Text = "Port Opened ";

            s.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
        }
        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Thread.Sleep(500);
            string data = s.ReadExisting().ToString();
            this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
        }
        private void si_DataReceived(string data)
        {

            textBox1.Text += data.Trim();
        }
    }
}



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 October 2011 - 06:39 PM

Hi Beowolf, Have you double-checked the COM port (COM1 vs COM2)? COM1 is pins D0/D1. COM2 is pins D2/D3. Also, it's easy to reverse the TX and RX lines. Chris

#3 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 02 October 2011 - 02:54 AM

Hi Beowolf,

Have you double-checked the COM port (COM1 vs COM2)? COM1 is pins D0/D1. COM2 is pins D2/D3. Also, it's easy to reverse the TX and RX lines.

Chris


Yes crish i connected the tx of my transmitting xbee to thr pin D1 only and used the com1 port only.

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 02 October 2011 - 09:29 AM

i connected the tx of my transmitting xbee to thr pin D1 only and used the com1 port only.

Then why do you have "COM2" in the code?

#5 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 02 October 2011 - 12:42 PM

Hello,

Oh am sorry to say......i corrected the code to COM1. But still the same problem is continuing. I cannot transfer the data between my Netduino and PC.

today while coding the two programs i tried to send the data from my pc's xbee to my Netduino's xbee.
When i sent the data from my pc i made the following observations:

1. The DIN led blinks on my rs232 explorer even when i am sending the data. I suppose when i am sending the data from my pc to my Netduino the DOUT led should blink on my rs232 explorer.
2. When i transmit the data from my pc to my Netduino the RSSI led on my Uc's shield glows for a while and than goes off. But the DIN led doesn't blink at all.


but when i transmit the values from my Uc i found that the led of DOUT blinks but at the RS232 explorer side there is no LED showing any response to that.

for transmitting the data from my PC to my Netduino i wrote the following piece of code in c#:

For Netduino:

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

namespace DataSender
{
    public class Program
    {
        public static SerialPort s;
        public static string message = "Hello World";
        public static byte[] bytes = Encoding.UTF8.GetBytes(message);
        public static OutputPort o = new OutputPort(Pins.ONBOARD_LED, false);
        public static void Main()
        {
            int v=0;
            // write your code here
            s = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            s.Open();
            o.Write(true);
            byte[] a=new byte[10];
            while (true)
            {
                //s.Write(bytes, 0, bytes.Length);
                v=s.Read(a, 0, a.Length);
                if(v!=0)
                {
                    o.Write(true);
                    Thread.Sleep(2000);
                    o.Write(false);
                    v = 0;
                }
               

            }

        }

    }
}

For PC i wrote this code:

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

namespace COMReceive
{
    public partial class Form1 : Form
    {
        private delegate void SetTextDeleg(string text);
        static SerialPort s;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            s = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
            s.Handshake = Handshake.None;
            s.Open();
            textBox1.Text = "Port Opened ";

            s.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
        }
        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Thread.Sleep(500);
            string data = s.ReadExisting().ToString();
            this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
        }
        private void si_DataReceived(string data)
        {

            textBox1.Text += data.Trim();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            s.Write("Hello");
            textBox1.Text+="Data Sent";

        }
    }
}


i am using the following products:

1) Xbees
2) Uc Explorer
3) RS232 Explorer
4) Netduino

Thanks

#6 Terry Massey

Terry Massey

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationPekin, IL

Posted 03 October 2011 - 05:22 AM

beowolf: sorry I mised you in chat.

I have a video series I did on that on the TheShieldStore.com website.

http://www.theshield...ewsarchive.aspx
Thanks,
Terry Massey

#7 Beowolf

Beowolf

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 03 October 2011 - 09:49 AM

Thanks all for the patient reply.
I found out the solution and posted it as whole post in here.

I was actually doing the wrong wiring connection and my xbee modules were also not properly paired. Now i have got all the things in place and can transmit the data wirelessly.

Thanks once again. Specially It's Dan and Cris Walker, i troubled a lot to you guys with my bunch of questions both at the cat room and on forums.

Regards
Beowolf




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.