Arduino, Netduino Plus and XBee Radio
- Philippe Chretien

- Feb 24, 2011
- 2 min read
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.
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.



Comments