Pages: [1]   Go Down
Author Topic: Need help interfacing this xbee shield question  (Read 283 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I brought this http://proto-pic.co.uk/products/XBS005-%252d-Shield-for-the-Arduino-%26-Amicus-development-boards.html Xbee shield as a substitute to the digi mainstream one, the only problem is its new to the market (so no example complete sketches and I'm a noob)  :-X.

Basically the xbee modules are configured to talk to each other, I used two xbee explorers for this. So I don't need any config code. The board came with minimal documentation. Only really says " Turning on the Xbee requires digital pin 8 to be taken HIGH, you need to do this in your code, something like this will suffice (other systems should be equally simple ):
Code:
pinMode(8,OUTPUT);
digitalWrite(8, High0;

Their example script isn't complete and I'm stuck. Heres their code http://www.openkontrol.org/wiki/tiki-index.php?page=Arduino+Code. I'll paste it below.

Code:
// Arduino example code
void setup() // always called at the start to setup I/Os etc
{
Serial.begin(9600); // start the serial port at 9600 baud
}

void loop() // repeatedly called
{
static boolean waitingForStart = true; // true if waiting for start of message
static long time; // used to store time of first character - for timeout

if (waitingForStart) // we are waiting for the first character of a message
{
if (Serial.available()) // got some characters
{
waitingForStart=false; // in message, enable timeout
time=millis(); // set up timeout
}
}
else // timing out
{
if (Serial.available()==12) // have we got the message?
{
processCommand(); // yes - process the message
waitingForStart = true; // and wait for the next one
}
else if (millis()-time > 100) // 100 millisecs should be enough to receive the message
{
Serial.flush(); // timed out - flush any characters received
waitingForStart = true; // wait for the next message
}
}
}
void processCommand() // message received - process it
{
char message[12]; // buffer to store message in
for (int i=0; i<12; i++) message[i] = Serial.read(); // read the message into the buffer
if (strncmp(message,"aC01",4) == 0) // check first four characters of message
{ // it is for us
if (message[4] == 'E') // test 5th char
{
Serial.print("aR01EHERE---");// send 12 byte reply
}
}
}
uint8_t charToHex(char c)
{
if (c < 'A') return (c-'0');
return (c-'A'+10);
}
int char2hex(char* msg) // char * means a pointer to a char
{
return(charToHex(msg[0])*16+ charToHex(msg[1]));
}

Can anyone help me complete this sketch?. I'm perplexed wishing I had brought a digi shield! smiley-sad
Logged

Pages: [1]   Go Up
Jump to: