Arduino, Netduino Plus and XBee Radio

I just received two XBee wireless modems with an Arduino shield and an USB adapter board. I bought all these parts from Sparkfun.com. I followed the instructions from the Lady Ada website to configure both modems so they can talk to each other.

Arduino, Netduino Plus and XBee modems

Arduino, Netduino Plus and XBee modems

Once I finished soldering the XBee shield stackable headers I tried the simple “serial echo sample” from the Sparkfun website. I modified it to turn a LED on and off depending on the data received.

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(19200);
}

void loop() {
  if (Serial.available()) {
    char c = (char) Serial.read();
    if(c == 'h')
      digitalWrite(13,HIGH);
    if(c == 'l')
      digitalWrite(13,LOW);
    Serial.print(c);
    delay(10);
  }
}

I connected an XBee board to the USB adapter connected to my computer and the other on the Arduino mocro-controller powered by a 9V battery. No mater where I hided the Arduino board in my house, the communication between both XBee modems was perfect.

I then decided to give it a try using my new Netduino Plus. I replicated the exact same behavior as on the Arduino to compare both platforms. It took me less then 30 minutes to port the code to the Netduino Plus.

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

namespace NetduinoPlusXbeeEcho
{
    public class Program
    {
        private static bool pin13Value;
        private static OutputPort pin13 = new OutputPort(Pins.GPIO_PIN_D13, false);

        public static void Main()
        {
            byte[] buffer = new byte[32];

            SerialPort port = new SerialPort("COM1", 19200);
            port.ReadTimeout = 0;
            port.Open();

            while(true)
            {
                int count = port.Read(buffer, 0, buffer.Length);
                if(count > 0)
                {
                    char[] chars = Encoding.UTF8.GetChars(buffer);
                    if (chars[0] == 'h')
                        pin13Value = true;
                    if (chars[0] == 'l')
                        pin13Value = false;

                    pin13.Write(pin13Value);
                    port.Write(buffer, 0, count);
                }
            }
        }
    }
}

The code is a bit longer but it has more to do with the structure of the program than the complexity of the code. The Netduino Plus has a direct advantage over the Arduino because it can connect to the net through its Ethernet port.

Tags: , , , , , , , , ,

1 Reply

Trackback  •  Comments RSS

  1. Eric Dunn says:

    Couldn’t find contact info, so hopefully you’ll see this comment.

    With little electronics background and no experience or knowledge of Xbee, I have a project that I would desperately like to attempt. If the project is successful, it has the potential of being commercialized.

    In simple terms, I need to relay signals from one point to the other wirelessly. As I see it:

    Digital I/O and a microprocessor to interpret changes in the inputs and transmit control codes, and an Xbee relay board at the other.

    Do you, or do you know people/groups who, take on projects of this nature?

Post a Reply

Your email address will not be published. Required fields are marked *

Top