Quantcast
Channel: Mark Sweeting's Blog
Viewing all articles
Browse latest Browse all 10

Quick test with Xbee alternative: Ciseco XRF module

$
0
0

This is a quick post to explain how to get a pair of Arduinos talking to each other wirelessly, using XRF wireless modules from Ciseco. They actually work straight out of the box, but if like me you like to have some instructions to get you going then hopefully you’ll find this post useful.

I’ve recently started learning/playing/experimenting with Arduino - an open-source microcontroller. Reading around, I saw lots of people mentioning Xbee wireless modules, which enable your Arduinos to talk wirelessly to each other (or to your computer) which sounded fun. However, the Xbee modules I’ve seen generally tend to operate at 2.4 GHz (along with every other wireless device in my home and the houses around me like cordless telephones and wi-fi), so I wasn’t really keen to add the the radio pollution in that band. They’re also moderately expensive (starting price circa £20 each with a range of 100m or so, and don’t forget you need a pair). But then I came across the XRF wireless module from Ciseco.

For about £10, you get a wireless module that’s pin-for-pin compatible with Xbee (Series 1), works over a range of different frequencies (868.3MHz by default, but also 315MHz, 433.5MHz, 868MHz, 903MHz and 915MHz), and has a standard range of approximately 300m (although ranges of over 3 Km are claimed). At this point I should make it clear that I’m a complete beginner at this stuff, but I was curious so emailed Ciseco with a few of my newbie questions. Their responses were quick and made everything sound simple, so, loving a bargain and challenge, I decided to order a pair and have a tinker.

Shopping List

The shopping list was pretty minimal. I already had an Arduino Uno and an Arduino Ethernet, so as well as ordering 2 x XRF modules, I also ordered 2 x Ciseco Xbee shields. These sit between the Arduino and the XRF, and were about £17 each. So although these are about the same price as alternatives, they have some nice features like an onboard 3v3 regulator, automatic disabling of the TX/RX lines when uploading a new sketch to the arduino (means you don’t have to unplug the XRF/Xbee when replacing the sketch), and space to solder on additional components (sensors, things that go blink etc….).

A simple test

I was assured that using the XRF was easy, and that when using the Xbee shield it was simply a matter of:

  1. Plugging the three PCBs together (Xbee shield into the Arduino, and the XRF into the Xbee shield),
  2. Enabling the XRF module by holding pin 8 high, and
  3. Reading/Writing between the two Arduinos using standard Serial.read()/Serial.write() commands.

I admit that it sounded much easier than I was expecting, so, with a little disbelief, I dropped the following code onto my arduinos. First up, a “Beacon”. This just sends the letter “H” (for Hello) every few moments, and listens for the letter “K” (for OK) in response. (Actually it doesn’t care if the letter K is in response to anything - it just listens for the K regardless.) If a letter K is received then the status LED on pin 13 of the Arduino Uno it lit for a moment, and because this LED is difficult to see (with two PCBs stacked on top of the Uno) I added in a piezo buzzer too — wiring it straight on to pin 7.

You can grab the PDE file for this sketch here: XRFTestBeacon.pde. This should compile to 3566 bytes. Note that it doesn’t do much on its own; you need to grab the second file below.

/* XRF Arduino Test Sketch - Beacon
 *
 * Full details of this example: http://bit.ly/sPPN8a
 *
 * Simple sketch to check the XRF radio modules are working.
 * Broadcasts the letter "H" (Hello) every 5 seconds.
 *
 * I'm using 2 x XRF modules and 2 x Xbee sheilds from Ciseco, and an
 * Arduino Uno and Arduino Ethernet. The default XRF baud rate in 9600.
 *
 * This sketch (1 of 2) is running on the Arduino Uno, which has a
 * built in LED on pin 13. A piezo beeper was connected to pin 7 for
 * audiable acknowledgment of activity.
 *
 *  Created 4 Dec 2011
 *  by Mark Sweeting - www.sweeting.org/mark
 */

int LEDPin = 13; // built in to the Uno PCB
int XbeeEnable = 8; // powers up the XRF when using the Xbee shield
int BuzzerPin = 7;
int BuzzerTone = 6000;
unsigned long lastBeaconTime = 0;
unsigned long nowTime = 0;
unsigned long LEDTime = 0;
int beaconInterval = 2000;
int LEDPeriod = 300;

void setup()
{
  pinMode(LEDPin, OUTPUT);
  pinMode(XbeeEnable, OUTPUT);

  // Turn XRF on
  digitalWrite(XbeeEnable, HIGH);

  Serial.begin(9600);
}

void loop()
{
  // Get the current time since power-up
  nowTime = millis();

  // Send the letter 'H' ("Hello") on the serial line every few
  // seconds
  if((nowTime - lastBeaconTime) > beaconInterval)
  {
    Serial.print("H");
    lastBeaconTime = nowTime;
  }

  // If we receive the letter 'K' (for "OK"), then turn the LED on
  // for a moment and beep the buzzer
  if(Serial.available() > 0)
  {
    if(Serial.read() == 'K')
    {
      LEDTime = nowTime;
    }
  }

  if(LEDTime)
  {
    digitalWrite(LEDPin, HIGH);
    tone(BuzzerPin, BuzzerTone);

    // Turn LED off after a short period
    if((nowTime - LEDTime) > LEDPeriod)
    {
      LEDTime = 0;
      digitalWrite(LEDPin, LOW);
      noTone(BuzzerPin);
    }
  }
}

The beacon “relay” code is even simpler: it just listens out for the letter “H” and sends a letter “O” in response. It was running on an Arduino Ethernet, and this doesn’t have a status LED on pin 13 so there was nothing for me to blink without wiring things in. For the purpose of the demo there was no need.

You can grab the PDE file for this second sketch here: XRFTestBeaconRelay.pde. This should compile to 2234 bytes.

/* XRF Arduino Test Sketch - Beacon Client Relay
 *
 * Full details of this example: http://bit.ly/sPPN8a
 *
 * Simple sketch to test a pair of XRF modules are working. Listens
 * for the letter "H" (Hello) on the serial line, and sends the letter
 * "K" (OK) in response.
 *
 * I'm using 2 x XRF modules and 2 x Xbee sheilds from Ciseco, and an
 * Arduino Uno and Arduino Ethernet. The default XRF baud rate in 9600.
 *
 * This sketch (2 of 2) is running on the Arduino Ethernet which
 * doesn't have a built in LED, so there's nothing for us to blink by
 * way of acknowledgement.
 *
 *  Created 4 Dec 2011
 *  by Mark Sweeting - www.sweeting.org/mark
 */

int XbeeEnable = 8;

void setup()
{
  pinMode(XbeeEnable, OUTPUT); 

  // Turn XRF on
  digitalWrite(XbeeEnable, HIGH);
  Serial.begin(9600);
}

void loop()
{
  // listen out for the letter "H", and send a "K" if we get one.
  if(Serial.available() > 0)
  {
    if(Serial.read() == 'H')
    {
      Serial.print('K');
    }
  }
}

So once I’d plugged everything together and the sketches were loaded onto the Arduinos, I powered them up, waited, and bingo! The beeper started to beep, meaning the letter “H” was being received by the second module, which was sending the letter “K” back in response. So it really was as simple as the folk at Ciseco said it would be!

I’m sure I’ll be posting more about the XRF modules in time as they’re pretty canny devices. In the meantime, it’s worth checking out the Openmicros forum (run by Ciseco, and includes a good support forum) as they’re very quick at responding to queries.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images