Skip to content
Tochinet edited this page Jun 2, 2015 · 28 revisions

Introduction

Battery-powered devices usually need to be put in sleep mode to save current. This is a crucial technique when you want your devices to last for years from simple battery packs. panStamp provides multiple commands to make the nodes come in sleep mode.

Low power nodes usually follow this workflow:

  1. Read sensors and transmit values
  2. Enter sleep mode
  3. Stay in sleep mode until an event (external pin or RTC) occurs
  4. Leave sleep mode
  5. Back to 1

The above workflow can be implemented in the arduino loop so that the process is repeated forever.

Available commands

There are different ways to enter sleep mode from a panStamp:

sleep with external pin interrupt

This command belongs to the global panstamp object and puts the module in sleep mode until a pin change interruption is detected. If no interrupt is enabled or detected, the module could stay in sleep mode forever.

Example:

void myIsr()
{
  // This function is called whenever digital pin changes
}

void setup()
{
  swap.init();
  attachInterrupt(1, myIsr, CHANGE);  // Attach interrupt on digital pin 1 to custom ISR
}

void loop()
{
  // Read sensor and transmit SWAP status packet
  swap.getRegister(REGI_MYSENSOR)->getData();
  // Enter sleep mode
  panstamp.sleep();
  // The panStamp is now sleeping. It will wake up when pin 1 changes
  // ZZZZZZZZ....
}

sleep with RTC calendar

This option is only available for panStamp NRG. The CC430 SoC from NRG has a hardware RTC module which can be put in calendar mode. In order to wake-up from sleep, the appilcation needs to initialize the RTC clock and program an alarm before calling panstamp.sleep()

Example:

void setup()
{
  // Set current time : Thursday 8-Apr 2015 12:15:00 (PM)
  rtcData.year = 2015;
  rtcData.mon = 4;
  rtcData.day = 9;
  rtcData.wday = 4;
  rtcData.hour = 13;
  rtcData.min = 48;
  rtcData.sec = 0;
  
  panstamp.rtc.startCalendar(&rtcData);
  
  // Trigger alarm at every day at 10h00 AM
  panstamp.rtc.setAlarmHour(10);
}

void loop()
{
  // Read sensor and transmit SWAP status packet
  swap.getRegister(REGI_MYSENSOR)->getData();
  // Enter sleep mode
  panstamp.sleep();
  // The panStamp is now sleeping. It will wake up when the RTC alarm occurs
  // ZZZZZZZZ....
}

sleepSec

This command belongs to the global panstamp object as well and puts the module in sleep mode for the amount of seconds passed as argument. Even in the absence of a pin interrupt the module comes out from sleep once the sleeping interval has elapsed.

Example:

void loop()
{
  // Read sensor and transmit SWAP status packet
  swap.getRegister(REGI_MYSENSOR)->getData();
  // Enter sleep mode for 30 seconds
  panstamp.sleepSec(30);
  // The panStamp is now sleeping. It will wake up after 30 seconds
  // ZZZZZZZZ....
}

goToSleep

This command is part of the global swap object, as far as the SWAP library is being used of course. It also puts the panStamp in sleep mode for a fixed period of time but, unlike panstamp.sleep(), the interval is taken from the global SWAP register txInterval, making the sleeping interval dynamically modifiable wirelessly via SWAP commands or from the application itself.

Example:

void loop()
{
  // Read sensor and transmit SWAP status packet
  swap.getRegister(REGI_MYSENSOR)->getData();
  // Enter sleep mode for txInterval seconds
  swap.goToSleep();
  // The panStamp is now sleeping. It will wake up after txInterval seconds
  // ZZZZZZZZ....
}

Anti Swap

API for Anti Swap

Clone this wiki locally