Can't get my XBees communicating again

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Can't get my XBees communicating again

Post by kcranley »

Hi
I have one XBee (S1) connected to an Arduino R3, powered by my PC, and running a sketch which receives signals from another XBee (S1), connected to a Boarduino, powered by a laptop, and connected to a PIR sensor, and running a sketch which sends signals to the first XBee.

I had this working on my desktop, intending to put the Boarduino/PIR sensor in a remote place eventually.

However, when the laptop decides to go to sleep, the Boarduino power goes off, and I can usually get the whole thing going again after a lot of wire swapping, resetting etc, but just at the moment, the XBees are not communicating.

Can you suggest a simple way of restoring communication if the Boarduino/PIR combination should temporarily lose power?
KC

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

I can usually get the whole thing going again after a lot of wire swapping, resetting etc
What kind of wire-swapping do you have to do? It should just come up running.

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

When the communication doesn't resume, I try a lot of things. I replace the Boarduino sketch with the Bare Minimum sketch - to do this, RX/TX needs to be reversed. This seems to be necessary to run X-CTU, to determine if the XBees actually work, and having done that, my sketches need to be re-uploaded, so to return to the original wiring, the RX/TXs need to be reversed again.

Apologies if this is a bit jumbled

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

So you change the wiring & sketch to verify that the XBee is still working, then put it back to the way it was? Normally, the Boarduino should just come up running on power-up. It is possible that there might be some issue with the power-up timing of the XBee vs the Boarduino, but I would expect that a simple reset would get you running again.

Do you have a simple wall-wart or battery supply for the Boarduino/XBee? There might be something funky in the way your laptop's USB port powers up.

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

Yes - that's right - I put it back the way it was when it worked. I now have it on an external supply, and that makes no difference.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

Are you sure the problem is at the Boarduino end? Maybe it is the receiving side that needs to be reset to re-sync.

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

How do you do that? The receiving end is another XBee (also on Adafruit adapter) with an Arduino Uno R3, powered by my desktop Windows PC.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

Press the reset button on the Uno.

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

OK - I've been doing that too - still nothing

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

Do the XBee leds indicate any transmission activity when the Boarduino powers up?

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

No - the red lights don't come on - except every few minutes the receive end's red light comes on but only for a few seconds, and not in response to a reset. The green lights on both XBees are blinking.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

Post the code you are using.

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

Here is the sketch on the Boarduino for detecting PIR signals and sending a stream of H's or L's depending on whether the PIR signal is high or low: (There is some redundant code for a Real Time Clock which hasn't been included yet).

Code: Select all

//
// PIR motion detector with LED indicator
// Status info by XBee to PC
// 11 Jan 2013
//

#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>

RTC_DS1307 RTC;

SoftwareSerial XBSerial = SoftwareSerial(2, 3);

int PIRpin = 4;		// digital pin 4 for PIR
int LEDpin = 13;	// digital pin 13 for LED
int PIRval;             // PIR HIGH or LOW value

void setup() {
  pinMode(LEDpin, OUTPUT);    // set the LED pin as ouput
  pinMode(PIRpin, INPUT);     // set the PIR pin as an input

  // Setup SoftwareSerial port
  XBSerial.begin(9600);
  Serial.begin(9600);
  XBSerial.println("Setup finished.");
  if (! RTC.isrunning())
  {
    Serial.println("RTC is NOT running!");
  }
}

void loop() {
  PIRval = digitalRead(PIRpin);    // read PIR
  if (PIRval == HIGH) {
    Serial.print("H");
    digitalWrite(LEDpin, HIGH);    // LED ON
  }
  else {
    Serial.print("L");
    digitalWrite(LEDpin, LOW);     // LED OFF
  }
  delay(100);
}
and here is the sketch on the Arduino for receiving XBee signals and outputting h's or l's depending on what it has received from the remote PIR:

Code: Select all

//XBeeReceive
//Sketch for receiving XBee transmissions from RemotePIR on remote 
//Boarduino connected to a PIR and XBee
//KC  11-Jan-13

int LedPin = 13;
int speakerPin = 9;

void setup() {
  // 
  Serial.begin(9600);
  pinMode(LedPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);
}

void playTone(int tone, int duration){
  for (long i = 0; i < duration*1000L; i += tone*2){
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);  
  }
}

void loop() {
  //   
  if (Serial.available())
  {
  int data = Serial.read();
    if (data == 'H')
    {
      //Serial.println("Somebody's in the garden");
      digitalWrite(LedPin, HIGH);
      Serial.write("h");
      playTone(956, 50);
      playTone(500, 50);
      playTone(250, 50);
      playTone(125, 50);
    }
    else if (data == 'L')
    {
      digitalWrite(LedPin, LOW);
      Serial.write("l");
    }
    else
    {
      digitalWrite(LedPin, LOW);      
    }
  //delay(10);
  }  
}

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: Can't get my XBees communicating again

Post by adafruit_support_bill »

On the Boarduino side, you have XBeeSerial and Serial. After setup, you only write the Serial.

XBSerial.println("Setup finished.");

Serial.println("RTC is NOT running!");

Serial.print("H");

Serial.print("L");

kcranley
 
Posts: 19
Joined: Sat Jul 21, 2012 4:35 am

Re: Can't get my XBees communicating again

Post by kcranley »

Sorry - my code is messy because I have been trying different things, and I'm still learning the basics. I am confused as to whether I should be using Serial or XBSerial. What I want to do is to send the characters "L" or "H" from the PIR/Boarduino/XBee (SENDER) powered by the Laptop to the Arduino/XBee/PC (RECEIVER) so that I can see either "l" or "h" on the PC serial monitor, and a LED comes on when the PIR goes high. I want to see either "L" or "H" on the Laptop serial monitor also, so that I can see that everything is doing what it's supposed to be doing.

Currently, using only XBSerial on the SENDER and only Serial on the RECEIVER, it is doing what I want. However, when I move the SENDER away from the Laptop, and power it with an external source, it no longer transmits.

Can you suggest what I might do to have the SENDER placed remotely, on external power, so that I can see on the PC when the PIR has been activated?

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”