Hello,
After a few months playing with an arduino, it was time to write my first post. ![]()
Yesterday I was trying to help a friend setting up his arduino+Xbee Shield+Xbee. He had trouble configuring the xbee module from the arduino (duemilanove).
Trying with direct PC->xbee connection (using the arduino with the atmega removed and jumpers on xbee shield to USB) we were able to send '+++' to the xbee and get the 'OK' from it.
We wrote a small program to configure the Xbee from the arduino (see after my post).
This program sends the '+++' waits for the OK then asks for the network ID (ATID command). At the same time, the program lightens LEDs according to the progress of the process (no way to debug on serial... so we though blinking leds would help).
We first tested the code without the Xbee shield, emulating the responses from Hyperterminal (typing OK and sending the network ID). It seemed to work, so we plugged the Xbee shield, set the jumpers to xbee and let the program run.
Unfortunately the program got stuck while waiting for the OK (LED 12 on).
Now the weird part is that we decided, with a second arduino, to tap-in into the serial exchange. We removed the atmega from this second duemilanove, connected the ground of both boards and connected TX, RX of the arduino with the XBee to the RX, TX of the second board. Then we opened a serial connection with the "sniffer" board.
With the sniffer board connected, the program ran flawless, and we saw the responses from the Xbee (OK and the network ID) on hyperterminal.
However, without the "sniffer" board the problem would remain, no OK was being received by the arduino.
We figured out a way of taping in into serial communication, but still we cannot tell why we do not receive the OK from the XBee when the second board is not connected.
Do you have any clue?
Regards,
Jose
PS
Sorry for all the commented lines in the code... you can see how many things we tried to make it work.
#define maxLength 30
#include <WString.h>
int incomingByte = 0; // for incoming serial data
//declaration of the various used strings
String strXBeeCMD,strStartXBee,inString,strOK,strNetID;
void setup() {
Serial.begin(9600);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
setDestination();
}
void setDestination (){
//strcpy(str1,"hello");
strStartXBee="+++";
//put the radio in command mode
//Serial.print(strStartXBee);
Serial.flush();
delay(1500);
Serial.print("+++");
Serial.flush();
delay(1500);
//wait for the radio to respond with "OK\r"
int thisByte=0;
//while (thisByte!=13 and thisByte!=10 ){
while (!strOK.contains("OK")){
if (Serial.available()>0)
{
//Serial.println("Serial is available and we receive:");
digitalWrite(11,HIGH);
thisByte=Serial.read();
strOK.append(char(thisByte));
}
digitalWrite(12,HIGH);
//Serial.println(strOK);
//Serial.println("STILL IN THE WHILE");
}
digitalWrite(12,LOW);
digitalWrite(11,LOW);
//Serial.println(strOK);
if (strOK.contains("OK"))
{
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
}
}
void loop() {
// read the sensor:
//Serial.println("Get current address");
strXBeeCMD="ATID\r";
Serial.print(strXBeeCMD);
int thisByte=0;
while (thisByte!=13 and thisByte!=10){
if (Serial.available()>0)
{
//Serial.println("Serial is available and we receive:");
thisByte=Serial.read();
strNetID.append(char(thisByte));
}
}
if (strNetID.contains("3332"))
{
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
}
}
void getIncomingChars() {
// read the incoming data as a char:
char inChar = Serial.read();
// if you're not at the end of the string, append
// the incoming character:
if (inString.length() < maxLength) {
inString.append(inChar);
}
else {
// empty the string by setting it equal to the inoming char:
inString = inChar;
}
}