SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By bcrosby
#126151
My FIO is a sleep most of the time, however it wakes up occasionally to send a "1" via serial using two xbee modems.

The problem is, i'm seeing garbage on the serial line as soon as the xbee wakes up, before my "1" is sent.

Image

You can see the "1" at the end of the lines.

I've configured the xbee to use pin sleep (hibernate). I have the DTR pin attached to Digital pin 6. And to wake the xbee I'm setting the pin low.

My code does the following:

- Sleep and listen for an interrupt on D2
- Interrupt wakes arduino, increments the counter and puts the unit back to sleep
- When the counter reaches 10, we wake the Xbee, and send a "1"
- Delay 200ms
- Reset counter to 0, go back to sleep:

Code: Select all
#include <avr/sleep.h>

#define photoPin  2      // pin used for waking up
#define ledPin 13        //on board LED
int blinkCount = 0;
#define XBEE_sleepPin 6              // connected to pin 9 of the XBEE


void wakeUpNow()        // here the interrupt is handled after wakeup
{

}

void sleepNow()         // here we put the arduino to sleep
{
  // sleep mode is set here
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // enables the sleep bit in the mcucr register
  sleep_enable();                        
                                         
  //switch off ADC
  ADCSRA = ADCSRA & 0x7F;  // clear ADEN
 
  // switch off analog comparator
  ACSR = ACSR & 0x7F;
 
  // turn off the onboard LED during sleep (just incase it's turned on)
  pinMode (ledPin, INPUT);
  digitalWrite(ledPin,LOW);
 
  //put the xbee to sleep. Need to verify.
  pinMode (XBEE_sleepPin,INPUT);  // put XBee to sleep
  digitalWrite(XBEE_sleepPin,LOW); // disable our pullup reduce amps required

  // use interrupt 0 (digital pin 2) and run the wakeUpNow function. 
  // When this pin is LOW, the interrupt is triggered and wakes up the board.
  attachInterrupt(0,wakeUpNow, LOW); 
   
  // Good night Fio! zzZZzzz (We are now sleeping)
  sleep_mode();

  // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP

  // first thing after waking from sleep, disable sleeping.
  sleep_disable();

  // Don't listen for an interrupt, we dont want to run the wake up code again
  // incase the pin goes LOW
  detachInterrupt(0);

  // Do the things we want to do when we come out of sleep. Count the blink!
  restoreFromSleep();
 
}
 
void restoreFromSleep()
{

  //delay(200);
  // Pin 13 is the onboard LED
  // We want to use a visual cue so we know when a blink from the meter has happened
  // This was "disabled" earlier when the Fio went to sleep.
  pinMode(13, OUTPUT);
  digitalWrite(13,HIGH);
  // Add 1 to our counter
  blinkCount++;  
}


void setup()   {                
  
  // Make sure the pin the photo detector is set to input mode
  pinMode(photoPin, INPUT);

  // Do you have your own pull up resistor? Comment this out. If not, you can use
  // the built in one. 
  digitalWrite(photoPin, HIGH);

  // Start serial communication (57600 baud)
  Serial.begin(57600);
}

void loop()
{
 
  // if we have 10 blinks (we used 0.01 kWh of electricity) 
  // send a "1" over the serial line
  if (blinkCount == 10) {
    // Wake up the Xbee. So we can send data to the server
    pinMode(XBEE_sleepPin,OUTPUT); // control XBee Sleep
    digitalWrite(XBEE_sleepPin,LOW); // wake-up XBee
    // small delay to make sure that the xbee has associated with the server
    delay(2000);    
    // send data
    Serial.println("1");
    blinkCount = 0;

  }
  delay(200);
  sleepNow();     // sleep function called here 
}  
Anyone have any idea what I could be doing wrong? Thanks.
By waltr
#126170
Just a guess but try putting a pull-up resistor (~10k) on the XBee Dout line. My theory is that the pin is not being driven during wake-up and creating garbage characters to the terminal.
By blink
#133698
old thread but I had exact same promblem.
The fix is to restore the xbee settings to default with X-CTU.
And the adjust sleep mode.
By bryandowen
#184092
*REALLY* old thread at this point, but I'm not sure that just resetting w/ X-CTU is the fix. I'm using a Fio, which is pretty sensitive to having the XBee's settings tinkered with if I'm going to program it remotely (over XBee), so I'm very hesitant to try to fix this by resetting the XBee.

To thicken the plot a little, however, transmission was working just fine between my two XBee radios until I started putting the radio to sleep between sensor measurements. I do this by setting SM to 1 (PIN HIBERNATE), pinning RTS (which, on Fio, is connected to XBee pin 7) to a Digital output pin on the Fio (pin D3 in this case), and setting the pin HIGH during sleep and LOW to wake it up. I delay(50); after waking the radio, as suggested in another forum. But when I send measurements over the newly-awakened radio, I get a few garbage characters at the beginning of the transmission. (When I paste it in this editor, it truncates my message...) It's a tilde, ? inside a diamond, and a couple of changing characters (e.g., "~?B(").

This *does not* happen if I don't put the radio to sleep between transmissions (i.e., pin RTS to GND). This would seem to rule out radio configuration.

In another thread, I saw someone suggest that this has to do with the transmitting modem being in API mode, and the extra characters are a length/checksum header of some sort. I don't understand why this would be different if I'm sleeping my radio between transmissions than if I'm not.

Any thoughts?