Loading...
Pages: [1]   Go Down
Author Topic: Using the Xbee to sleep Arduino  (Read 625 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having trouble figuring out a simple way to control the sleep mode of the Arduino from Xbee. I have my Xbee on a cyclic sleep cycle and I want to wake the Arduino when the xbee wakes.  I found an article about making the Arduino go to sleep on this website's playground section. It appears that an Arduino can only be awaken when the interrupt pin goes LOW.  This appears to be opposite of what pin 13 on the xbee does when it awakes.  Pin 13 on the XBee is asserted HIGH when it turns on and it goes LOW when it turns off.  Has anybody found a way to use an Xbee to control a sleeping Arduino?



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino can wake on date received on UART pins. Maybe look into that
Logged

Check out my site for DIY information: http://inventige.com

Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was looking at that but its only available for SLEEP_MODE_PWR_IDLE and not SLEEP_MODE_PWR_DOWN.  I am trying to go with the most energy savings possible.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16540
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"Pin 13 on the XBee is asserted HIGH when it turns on and it goes LOW when it turns off. "
Can you add a transistor & use it as a simple inverter?
Interrupt pin with internal  pullup enabled. NPN transistor with base to XBee pin 13, collector to interrupt pin, emitter to gnd.
Collector pulled high by internal pullup, connects to GND when base goes high from Xbee.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Grand Blanc, MI, USA
Online Online
Faraday Member
**
Karma: 43
Posts: 2512
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pin change interrupt?
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16540
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure you can wake up from sleep with PCINT. Think you need to use one of the external INTs for that.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Grand Blanc, MI, USA
Online Online
Faraday Member
**
Karma: 43
Posts: 2512
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure you can wake up from sleep with PCINT. Think you need to use one of the external INTs for that.

Yep, have a project that does exactly that. From the datasheet:

Quote
10.5 Power-down Mode
When the SM2...0 bits are written to 010, the SLEEP instruction makes the MCU enter Powerdown
mode. In this mode, the external Oscillator is stopped, while the external interrupts, the 2-
wire Serial Interface address watch, and the Watchdog continue operating (if enabled). Only an
External Reset, a Watchdog System Reset, a Watchdog Interrupt, a Brown-out Reset, a 2-wire
Serial Interface address match, an external level interrupt on INT0 or INT1, or a pin change
interrupt can wake up the MCU. This sleep mode basically halts all generated clocks, allowing
operation of asynchronous modules only.

INT0, INT1, and pin change interrupts will wake from any of the sleep modes.
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 249
Posts: 16540
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good to know!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Can you please  send me an example code that uses pin interchange to wake up the arduino.

Thanku very much
Logged

Grand Blanc, MI, USA
Online Online
Faraday Member
**
Karma: 43
Posts: 2512
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Can you please  send me an example code that uses pin interchange to wake up the arduino.

Thanku very much

Code:
#include <avr/sleep.h>

void setup(void)
{
}

void loop(void)
{
}

void goToSleep()
{
    byte adcsra, mcucr1, mcucr2;

    sleep_enable();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    PCICR = _BV(PCIE1);            //enable pin change interrupts 8-14
    PCMSK1 = _BV(PCINT8) | _BV(PCINT11) | _BV(PCINT12) | _BV(PCINT13);    //enable PCINT8,11,12,13 (PC0,3,4,5)
    adcsra = ADCSRA;               //save the ADC Control and Status Register A
    ADCSRA = 0;                    //disable ADC
    cli();
    mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
    mcucr2 = mcucr1 & ~_BV(BODSE);
    MCUCR = mcucr1;                //timed sequence
    MCUCR = mcucr2;                //BODS stays active for 3 cycles, sleep instruction must be executed while it's active
    sei();                         //ensure interrupts enabled so we can wake up again
    sleep_cpu();                   //go to sleep
                                   //wake up here
    PCICR = 0x00;                  //disable pin change interrupts 8-14
    PCMSK1 = 0x00;
    sleep_disable();
    ADCSRA = adcsra;               //restore ADCSRA
}

ISR(PCINT1_vect)
{
    PCICR = 0x00;                  //disable pin change interrupts 8-14
    PCMSK1 = 0x00;
}
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Pages: [1]   Go Up
Print
 
Jump to: