Go Down

Topic: Need help interfacing this xbee shield question (Read 310 times) previous topic - next topic

merlspiers

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: [Select]

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: [Select]
// 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! :(

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy