Test Software for RFBee communication.

Hello,

this article would be a "newbie to newbie" tutorial for the implementation of a simple communication system between RFbee node from Seeedstudio. Seeed Studio Bazaar, The IoT Hardware enabler.

I have to say many thanks to Icing Chang from Seeedustudio for helping me when I erased the firmware of one my RFBee module, pushing accidentally the reset button int RFBee shield. Really big service for little bucks :D.

Upload the RFBee firmware
There is a tutorial for uploading the RFBee firmware in his manual (Seeed Studio Bazaar, The IoT Hardware enabler.), just wanted to add that the firmware code folder shouldn't be copied in an internal folder of the arduino folder (as I have done first), put it elsewhere, as in the desktop, and you will able to compile it.

The test software
The test software in a console program written in C++ (Visual C++ Express 2010 in a windows 7 system) that sends to the serial port a single char, namely H, L and others (if == e it close the programs).

The Arduino sketch
The arduino sketch receive data from the serial port and if it is an H it turns on the built in-led (pin 13), off if the data is an L

Hardware configuration
The Hardware chain is the following:

PC -> Seeedstudio UartSBee V3.1 -> XBee module ->.....-> XBee module ->Seeedstudio XFBee Shield V1.1->Arduino 2009

UartSBee is working at 3v3 volts, XBee Shield is plugged only after the arduino sketch is uploaded, otherwise you could not be able to upload. This shield has two switches, I have to put the two to the right (external side) to enable polling (in this configuration you link XBee TX with atmega RXD and XBee RX to Atmega TXD....dunno why but it works ;D Seeed Studio Bazaar, The IoT Hardware enabler.)

Test software code

// RFBeeTest.cpp : file di progetto principale.

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <string.h>


using namespace std;
using namespace System;
using namespace System::Threading;
using namespace System::IO::Ports;



void send_data(unsigned char c)
{
    // Create a new SerialPort object with default settings.
    SerialPort^  _serialPort = gcnew SerialPort("COM4");

    // Allow the user to set the appropriate properties.
    _serialPort->BaudRate = 9600 ;
    _serialPort->Parity = Parity::None;
    _serialPort->DataBits = 8;
    _serialPort->StopBits = StopBits::One;
    _serialPort->Handshake =Handshake::None;

      // Set the read/write timeouts
    _serialPort->ReadTimeout = 100;
    _serialPort->WriteTimeout = 500;

      //convert char to string
      String^ d = Char::ToString(c);
      //open-send-close port
    printf("\n\nsending data: %s\n ",d);
      _serialPort->Open();
      _serialPort->Write(d);
      Thread::Sleep(50);
    _serialPort->Close();
}

int main() {

   //initialize var
   char c;
   char exit = 0x65;

   //take the char from keyboard and print to monitor
   cout <<"\nType a char [H turn on] [L turn off] [e exit]: ";
   cin >>  c;
   cout <<"\nchar is "<< c;

   Thread::Sleep(500);

   // the switch has to run untill the "e" char is entered
   while (c != exit){
   switch ( c )
      {
         case 'L':
             send_data(c);
             cout <<"\nType a char [H turn on] [L turn off] [e exit]: ";
             cin >>  c;
         break;
         case 'H':
         send_data(c);
             cout <<"\nType a char [H turn on] [L turn off] [e exit]: ";
             cin >>  c;
         break;
             case 'e':
         printf ("\nexit now");
             break;
         default:
         printf ("\nchar not allowed, retry: \n");
             cout <<"\nType a char [H turn on] [L turn off] [e exit]: ";
             cin >>  c;
             break;
      }
   }
   send_data(0x4c); //turn off led
   return 0;
}

Arduino sketch

/*
Program that read a char from serial port and turn on a led (pin 13) 
 if the char was H. Put it low is the char is an L
 */
int ledPin = 13;

void setup() {
  // initialize serial communication:
  Serial.begin(9600); 
  // initialize the LED pins:
  pinMode(ledPin, OUTPUT);
} 


void loop() {
  // read the port:
  if (Serial.available() > 0) {
    int inByte = Serial.read();


    switch (inByte) {
    case 'H':    
      digitalWrite(ledPin, HIGH);
      break;
    case 'L':    
      digitalWrite(ledPin, LOW);
      break;
    default:
      // turn all the LEDs off:
      digitalWrite(ledPin, LOW);

    } 
  }
}

Low quality photo of the system

...And that's all. Have nice communications!

Marco