Giter VIP home page Giter VIP logo

snooze's People

Contributors

duff2013 avatar latimes2 avatar marcianopreciado avatar nburkitt avatar ticapix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snooze's Issues

Changing interrupt pins?

Hello,

Is it possible to enable and disable interrupts from different pins between sleeps?

I've tried using multiple digital blocks but I believe the use of static scope has prevented this from working.

Many Thanks,

Andrew

Current with snooze and TSI

On T3.6 (not sure, but probably same to other board)
When using touch pin to wake, it tooks a significant 60mA more currency at hibernate/sleep ,
which is, not good for sleeping project at all. It seems the TSI is continuously back to back scanning in the setting?

Is it possible to set the LPT counter overflow much lesser so it saves power?

I currently use snooze with timer and wake up each 25ms for a touchRead to detect a touch and (break;)
and this case current is much lower(<1mA) at my meters

Digital Interrupts not Working for Teensy LC on Sleep

When trying out the sleep_all_wakeups example code on my Teensy LC the digital interrupts aren't waking the processor from sleep. I switch the
#elif defined(__MKL26Z64__)
who = Snooze.sleep( config_teensyLC );// return module that woke processor
#endif
part for.
#elif defined(__MKL26Z64__)
who = Snooze.hibernate( config_teensyLC );// return module that woke processor
#endif

and the digital interrupt functionality works just fine.

Edit: It also works fine with deepSleep

attachInterrupt wakes up Teensy from hibernate

Hi duff,
i recently started playing around with your snooze library. I've noticed that when i attach an interrupt to a pin (not digital.pinMode but attachInterrupt) the interrupt will wake up my Teensy 3.6 from hibernation. Is this intended to be like this? As far as i understood the only pin interrupts that should wake up the Teensy are the ones declared by digital.pinMode but my normal Interrupts seem to wake the Teensy too.

Here is the code i've used:

#include <Snooze.h>
#define but_pin 23
#define but2_pin 10
boolean flag = true;

SnoozeDigital  digital;
SnoozeBlock config_teensy36(digital);
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digital.pinMode(but2_pin, INPUT_PULLUP, LOW);
  pinMode(but_pin, INPUT_PULLUP);
  attachInterrupt(but_pin, button_int, LOW);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  Snooze.hibernate( config_teensy36 );
  digitalWrite(LED_BUILTIN, LOW);
  delay(5000);
  if (flag == true) {
    for (int i = 0; i < 5; i++) {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(200);
      digitalWrite(LED_BUILTIN, LOW);
      delay(200);
    }
    flag = false;
  }
}
void button_int() {
  if (flag == false) {
    flag = true;
  }
}

i'm using :
Arduino IDE v1.8.1
Teensyduino v1.35
Snooze v6.2.5

Snooze config.pinMode example wrong?

In deepSleep_all_wakeups.ino there are these lines:
`

// trigger at threshold values greater than 1.65v
//config.pinMode(11, CMP, HIGH, 1.65);//pin, mode, type, threshold(v)
// trigger at threshold values less than 1.65v
compare.pinMode(11, LOW, 1.65);//pin, mode, type, threshold(v)`

But I think those examples are wrong. config.pinMode doesn't seem to exist and pinMode only takes 3 args, not 4. compare.pinMode exists though.

Teensy LC: Pin wakeups on pins 2, 7, 9 not working

The README states that for Teensy LC, Digital pins: 2,6,7,9,10,11,16,21,22 should work as wakeup sources. However, having tested them, I found that pins 2, 7, and 9 don't wake the CPU either from deepSleep or hibernate.

basic question

Hello Duff,

First I would like to know the difference between sleep modes.
Need to perform a simple task but do not know what is the best option.
The idea is something like this...

#include <TimeLib.h>

#include <Snooze.h>
SnoozeAlarm alarm;
SnoozeBlock config_teensy36(alarm);

unsigned long hours, hours1;
unsigned int record = 10; // in seconds

void setup() {
pinMode(LED_BUILTIN, OUTPUT);

hours1 = now() + 60; //first record from 1 minuto now

}

void loop() {
hours = now();

int who;
who = Snooze.deepSleep( config_teensy36 );

if (hours1 >= hours){
//Start_record
alarm.setRtcTimer(0, parar, 0); //sleep for sametime
}
//wake up here?! go to loop
}

but this reset all the system and does not start again from the last line...

Do you have any suggestion here.
Thanks

Snooze prevents loading new code?

@duff2013
When using the Snooze Library, I have the following error when trying to upload new code :

Arduino: 1.8.5 (Linux), TD: 1.42, Board: "Teensy LC, Serial, 48 MHz, Smallest Code with LTO, US English"

Sketch uses 13612 bytes (21%) of program storage space. Maximum is 63488 bytes.
Global variables use 3404 bytes (41%) of dynamic memory, leaving 4788 bytes for local variables. Maximum is 8192 bytes.
No Teensy boards were found on any USB ports of your computer.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

It seems that the port disappears because of the hibernation :
../arduino-1.8.5/hardware/teensy/../tools/teensy_post_compile -file=Test.pde -path=/tmp/arduino_build_52483 -tools=../arduino-1.8.5/hardware/teensy/../tools -board=TEENSYLC -reboot -port=/sys/devices/pci0000:00/0000:00:0c.0/usb1/1-3 -portlabel=(null) -portprotocol=(null)

if i comment this code Snooze.hibernate( config_teensyLC ); //teensy go to hibernate mode for LOOP_DELAY
then it works again but only if i keep the reset button pressed while trying to upload the sketch several time until it succeeds.

Teensy freezes

We are using the deepsleep function with the digital and timer modules imported. Around half the time the teensy 3.5 responds on time to timer wakeups and responds, albeit slowly, to digital wakeups. The other half of the time it just freezes up and we have to use the reset button to make it respond. If it matters, the calls to snooze are being made in a library, not in the main function code. Please help!

Questions

What is the difference between sleep, deep sleep and hibernate?

Also, I'm assuming when I call the sleep mode in the main loop it blocks the loop until it wakes up?

Thank you!

Missing kinetis.h?

I've tried to compile the Snooze library in the Arduino IDE, but I get an error that kinetis.h is missing. This file is referenced in mcg.h and peripheral.h. Commenting out the #include lines in both these files just causes a number of missing function declarations. The kinetis.h file seems to be missing from the source code of all available releases (checked 5.0 to 5.5). Am I missing something?

Support for SLEEP_MODE_IDLE on Teensy 3

Hi,

I would like to implement support for low power sleep (similar to SLEEP_MODE_IDLE of the Arduino) on Teensy to make it part of the TaskScheduler library
(https://github.com/arkhipenko/TaskScheduler)
The Teensy "avr/sleep.h" does not seem to have have any code actually, and "avr/power.h" is simply empty.
I have looked at the Snooze library and tried to use the Timer initiated power sleep, but it seems to be working differently then Arduino.

TaskScheduler uses SLEEP_MODE_IDLE to place Arduino into low power mode for approximately 1 ms. It is awaken back by the timer interrupt responsible for updating millis() counter. This way I am achieving 1ms scheduling resolution. Arduino does not power down any peripherals while in SLEEP_MODE_IDLE, so USB and other communications continue to run normal.

Teensy seems to be behaving differently.

class definition:
#ifdef CORE_TEENSY
	SnoozeTimer *timer;
	SnoozeBlock *config;
#endif //CORE_TEENSY

constructor:
#ifdef CORE_TEENSY
	timer = new SnoozeTimer;
	config = new SnoozeBlock(*timer);
	timer->setTimer(1);
#endif //CORE_TEENSY

actual sleep:
#ifdef CORE_TEENSY
	Snooze.sleep(*config);
#endif //CORE_TEENSY

causes my Tennsy 3.5 periodically connect and disconnect, so I can't even monitor what is going on with the device.

Is there a sleep function that is close to AVR's SLEEP_MODE_IDLE mode?

Your help is greatly appreciated.
Thanks.
Anatoli

"who" return value always -1

Hi - great library, I am successfully sleeping the teensy down to the 100 uA range! I can't seem to figure out why the deep_sleep_all example didn't exactly work right. The LED never flashed based on the who integer. When I print the value of "who" I always get -1. I am entering deep sleep with a timer AND interrupt:

SnoozeDigital digital;
SnoozeTimer timer;
SnoozeBlock config_teensy32(digital,timer);
setup()
{
digital.pinMode(16, INPUT_PULLUP, FALLING);
timer.setTimer(100000);
}
void loop() {
    int who=0;
    who = Snooze.deepSleep( config_teensy32 );
   //Serial.print(who) / write always shows -1 
}

Am I missing something in the config?

ADC, deepSleep, and the missing ~250uA

First, great library! I've used it on a few projects and recommended it often. I'm moving a project over to v6 and going for absolute minimum power, which I haven't done in the past.

I've got a bone stock Teensy 3.2 running your button_hold_wakeup example. I'm seeing ~40mA while running and ~270uA while in deepSleep. I'm using David Jones' uCurrrent gold to measure the current.

A google search hints at turning off the ADC. Is that done in your library or do I have to diddle the bit elsewhere?

Set Timer w/ Microseconds?

Considering the Teensy's clock has sub-microsecond length periods, it'd be nice if the timer could be set for shorter than a millisecond. Is there any simple work-around for this?

LC not staying in Hibernate

My Teensy LC project has been having lifespan issues when running on battery. When I throw it into hibernate mode, the current drops to 2 uA. Not long after initiating hibernation, the current returns to about 5 mA but stays in hibernation mode. I'm not sure what is going on here, but this reduces the battery life by several orders of magnitude. It seems to me that maybe internally most of the aspects of hibernation that effect power draw are being disabled, but the processor is still sleeping and hibernation is nominally active, but not truly.

Serial output is corrupted after waking

Tested using sleep and hibernate, this code is based in a paired down sleep_all_wakeups example.

#include <Snooze.h>

SnoozeDigital digital;

SnoozeBlock config_teensy32(digital);

void setup() {
    Serial3.begin(57600); //Tx on pin 8
    Serial3.println("Debug Serial started");
    pinMode(LED_BUILTIN, OUTPUT);
    digital.pinMode(10, INPUT_PULLUP, RISING);//pin, mode, type       
}

void loop() {
    int who;   
    Serial3.println("Sleeping");
    who = Snooze.hibernate( config_teensy32 );// return module that woke processor    
    if (who == 10) { // pin wakeup source is its pin value
        Serial3.println("triggered by pin 10");   
        for (int i = 0; i < 2; i++) {
            digitalWrite(LED_BUILTIN, HIGH);
            delay(200);
            digitalWrite(LED_BUILTIN, LOW);
            delay(200);
        }
    }     
}

Here is the output:

Sleeping
triggered by pin 10
ÿ*[YYÿZÿVHÿÿWÿÿVÿÿÿÿ$ÿ^HÿZÿÿ10
ÿÿÿÿÿÿW-ÿVHÿÿWÿÿVÿÿÿÿ$ÿ^HÿZÿÿ10
ÿ

The corruption occurs following the first wake up. subsequent interrupts do flash the LED but the serial output remains corrupted.
Tested with a teensy3.1 and Snooze version 6.2.9 using Arduino IDE 1.8.1

Teensy 3.2 Pin 16 not working correctly

Hi,

I have a cuircit with a Teensy LC. It will be wake up by a alarm interrupt on Pin 16 from a DS3231 (direct connectet). It works perfectly. When I use a Teensy 3.2 on the same cuircit the chip never wake up on an alarm interrupt. It´s possible that the Teensy 3.2 Snooze libery don´t working correct?
Thank for your help.
Boris

Error while using Snooze library on Teensy 3.5

Hi,

I'm trying to run the example in "Snooze/examples/sleep/sleep_all_wakeups/sleep_all_wakeups.ino" on Teensy 3.5 board. It compiles fine. However, after I try to run, I get this error in the serial terminal. I'm using Platformio IDE.

Exception in thread rx: Traceback (most recent call last): File "C:\...\.platformio\python27\Lib\threading.py", line 801, in __bootstrap_inner self.run() File "C:\...\.platformio\python27\Lib\threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "c:\...\.platformio\penv\lib\site-packages\serial\tools\miniterm.py", line 445, in reader data = self.serial.read(self.serial.in_waiting or 1) File "c:\...\.platformio\penv\lib\site-packages\serial\serialwin32.py", line 257, in in_waiting raise SerialException("ClearCommError failed ({!r})".format(ctypes.WinError())) SerialException: ClearCommError failed (WindowsError(22, 'The device does not recognize the command.'))

I also found this answer:

https://forum.pjrc.com/threads/41262-Snooze-hibernate-deepsleep-sleep-not-working-on-Teensy-3-5

I checked my "kinetis.h" file and I already have "#define HAS_KINETIS_LLWU_16CH" on line 548.

Any ideas what went wrong?

Thank you for help,
Regards

config error for Teensy LC?

Compiling pushbutton_pullup_hibernate.ino example (and my application too) for Teensy LC generates this error:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Snooze\Snooze.cpp:210:33: error: 'rtc_alarm_set' was not declared in this scope
rtc_alarm_set( &p->rtc_mask );

It works ok for Teensy 3.1.

No Hibernate

When I try to run the Hibernation example I get the following error: 'class SnoozeClass' has no member named 'hibernate'

RTC not advancing in deepSleep

I don't know what can be the cause, or whether this is voluntary and/or needed in order for this library to run, but I notice that the Teensy RTC stops when I put it in deepSleep... And this can cause problems to many applications that need the RTC to run in background. I'm using a Teensy 3.1 board. Thanks in advance.

Pin compare on Teensy 3.2 pin 12 not working

Has anyone been able to get a compare.pinMode wakeup to work on a Teensy 3.2 on pin 12? It says that pins 11 and 12 can do it but the exact same code works on pin 11 and doesn't work on pin 12, and I tried this across two Teensy 3.2's, including a brand new one that I just bought only to test this. Still only works on pin 11 which is unfortunately also the SPI MOSI default pin.

Here is the code I'm using, taken from the larger sample code of wakeups:

`

#include <Snooze.h>
#include <ADC.h>

const int PGOODpin = 12;

// Load snooze drivers
SnoozeCompare compare;

SnoozeBlock config_teensy32( compare );

void setup() {
  pinMode(13,OUTPUT);
  digitalWriteFast(13,HIGH);
  delay(1000);
  digitalWriteFast(13,LOW);
  
  setupAlarms();
}

void loop() {
  Snooze.hibernate( config_teensy32 );
  digitalWriteFast(13,HIGH);
  delay(200);
  digitalWriteFast(13,LOW);

}

void setupAlarms() {
  pinMode(PGOODpin, INPUT_PULLDOWN);
  compare.pinMode(PGOODpin, HIGH, 3.03); //pin, mode, threshold(v)
}`

dynamic cpu speeds

i'm missing this feature, and i find it weird why you did remove it.

purely so i can keep running my code without hibernating, deepsleep or whatever.

because it would be needed if one wants to dynamically control their cpu speed to keep running and save power. much like a smartwatch could does.

Example doesn't compile with Teensy LC

I downloaded a fresh Arduino 1.8.4, added Teensyduino 1.39, and tried to compile Examples/Snooze/deepsleep/deepsleep_all_wakeups, but had an error. The problem is localized to use of keywords in SnoozeCompare.cpp that are not available in Teensy LC.

I commented references to IRQ_CMP2 and LLWU_CMP2_MOD, and everything compiles and the timer wakeup works (I'm not using the comparator).

I'm new to github, but would be willing to try fixing this. I really appreciate your work to produce this library!

Snooze\utility\SnoozeCompare.cpp:195:42: error: 'IRQ_CMP2' was not declared in this scope

 if ( mode == VLPW ) NVIC_ENABLE_IRQ( IRQ_CMP2 );

Snooze\utility\SnoozeCompare.cpp:170:57: error: 'LLWU_CMP2_MOD' was not declared in this scope

     if ( mode >= LLS ) llwu_configure_modules_mask( LLWU_CMP2_MOD );

4.5mA drain in any sleep mode

Hi, thanks for the great library !

A quick question - I don't seem to be able to go under 4.5mA on my teensy 3.1. Using the (sleep/deep-sleep/hibernate) examples, I'm always in the 4~5 mA range... Any clue where I should investigate ?

I usually use platformio, but I get the exact same results using the recommended arduino+teensyduino way.

Setup wise, I don't have the crystal soldered (I commented out everything time/rtc-related in the example), and I'm testing the board directly with a hyelec multimeter from the 5v of an USB port on my Vin.

Cheers !

deepSleep prevents loading new code?

I'm dealing with an issue where it looks like my Teensy 3.2 is in deepSleep mode (which I put it in) but that turns off the bootloader, and now I can't get any new code loaded on there. I posted the issue on the official pjrc forum:
https://forum.pjrc.com/threads/45544-Teensy-3-2-no-longer-able-to-upload-code-via-Arduino-IDE?p=149695#post149695

Is this a known issue where someone can "lock" themselves out of a Teensy 3.2 by putting it in deepSleep, which turns off the bootloader, which disables loading new code?

While we're on the topic is there a nice list of all the differences between sleep, deepSleep, and hibernate? I couldn't find anything in the datasheet or chip reference manual that made that clear and going through all the register calls in the code would take a while.

How to count interrupts in sleep mode

Hello.

How can i count interrupts on pins 2 and 3 (simple increments of variables) without losing this information and without the teensy 3.2/LC waking from one of the sleep modes?

Can i change the CPU Prescaler to values lower than 2mHz?

tks, André

Alarm with hour,minute, second params does not wake

I am able to trigger alarms passing the epoch for the alarm time but not the hours minutes and seconds.
this fragment illustrates the issue:

time_t t = now() + 20; // 20 seconds from now
alarm.setAlarm(t); // this works

alarm.setAlarm(hour(t), minute(t), second(t));  //this does not trigger at the expected time 

Have I missed something?

here is the full test sketch

#include <TimeLib.h>
#include <Snooze.h>

#define debugPort Serial3

SnoozeAlarm  alarm;

SnoozeBlock snoozeConfig(alarm); 

const int alarmTriggered = 35; // friendly name 

int wakeReason;

void setup() {  
  debugPort.begin(57600); //Tx on pin 8
  debugPort.println("debug serial started\n");
 
  setSyncProvider(getTeensy3Time);
  time_t t = now();
  debugPort.print("time now is "); digitalClockDisplay(t);
  t = t+20;  // next alarm in 20 seconds
  debugPort.print("next alarm will be at "); digitalClockDisplay(t);
  //alarm.setAlarm(t);
  alarm.setAlarm(hour(t), minute(t), second(t));
  debugPort.flush();
  wakeReason = Snooze.hibernate(snoozeConfig);  
}

void loop()
{
  if (wakeReason == alarmTriggered) {
    time_t t = getTeensy3Time();
    debugPort.print("triggered by alarm at");  digitalClockDisplay(t);
    t += 20;
    debugPort.print("next alarm will be at "); digitalClockDisplay(t);
    //alarm.setAlarm(t);
    alarm.setAlarm(hour(t), minute(t), second(t));
    debugPort.flush();
    wakeReason = Snooze.hibernate(snoozeConfig);// wakeReason is module that woke processor
  }
}

void digitalClockDisplay(time_t t)
{  
  char timeStr[12]; 
  sprintf(timeStr, "%d:%02d.%02d", hour(t), minute(t), second(t)); 
  debugPort.println(timeStr);
}

time_t getTeensy3Time()
{
  return Teensy3Clock.get(); 
}

Snooze Audio Example

Is there an example for using the audio adaptor? Also, it says that it can wake up the adaptor without waking up the Teensy...does that mean the audio adaptor would still be able to detect input (from the mic or line-in jack, for example) and then wake the Teensy? Not sure I understand how that works ;) Thank you!

Detecting what triggered a wake up

Hello,

My use case requires a couple of different wake up sources and I need to know which was responsible for waking from a hibernate. Is there any possibility of doing that with this library?

I saw that the sleep methods return a source, but it appears that that variable is static across all instances of snooze block classes and always -1. I have done some experimentation and my results back that up (hibernate() appears to always return -1 no matter what woke it).

Any help is much appreciated,

Thanks

Maximum delay of Timer

Duff,
I am trying to set the timer to fire after 5 minutes (3e5 milliseconds) but I am noticing that fires at maximum after 60 seconds. Is this the limit?
How can I set the module to wake up every 5 minutes?

Thx,
Iraklis

Multiple Compare Inputs

Hey,
is it possible to use more than one pin to wake Teensy 3.6 with the compare-mode? It's said that there are 3 possible pins for compare (4, 9, 11) and I would like to use at least two of them to create something like a comparator by using compare. And which value would "who" have, if I was using for example pin 9 and 11, when the Teensy is either triggered by 9 or 11?

Current wakeup from deepSleep takes ~350us, can it be sped up?

First off thanks for this great library!
I've been using it extensively over the last year, but what I noticed is that the time from pin interrupt occurring to code getting back to the 'main' section is around 350 us. From what I can see the majority of the tasks that are being accomplished after the wakeup are fairly straightforward and should complete in a fraction of that time, the only reason for such a long delay seems to be the transition from PBE to PEE, could you confirm? Also, any suggestions on how to speed it up?

Wire conflicts

I am using a i2c wire device.
With the last version, I am not able to compile it anymore (multiple definitions of Wire).

I saw that SnoozeAudio has this include:
"Wire.h"

If I replace it with "#include <i2c_t3.h>"
it works.

I know, it should remain compatible... But I was not able to compile it with Wire.h.

// Using Serial.end() to plug a power leak on an un-powered serial port //

It appears Snooze doesn't shut down the serial ports before hibernating. I'm using serial2 and serial3 on the Teensy 3.2 and I'm seeing ~13mA draw on each port in the hibernate mode. I'm guessing that the devices on these ports are pulling power even though they are powered down. If I use Serial.end() on both ports before calling Snooze the power leak is gone. Of course, I need to remember to call Serial.begin() for both ports after I wake back up.

Not able to wake up with multiple assigned buttons

Hi,

For my sample code below, I assign 2 buttons (33 & 35) to wake the system up when it goes to sleep. The issues here are:

  1. It freezes every time I press either one of them after the system goes to sleep. (not able to wake up when having 2 assigned buttons)
  2. When using 1 button, it works perfectly if I press that button for once. If I already wake it up by pressing the button, the system will freeze if I press that button again before sleep mode.

I'm not sure if those issues are related to the button itself or if I'm missing anything here. Any help is appreciated!

Below is my sample code:

(My Teensy version is 3.5 and I'm using Snooze 6.2.8)

#include <Snooze.h>

SnoozeDigital digital;
SnoozeCompare compare;
SnoozeTimer timer;
SnoozeAlarm alarm;

#if defined(__MK66FX1M0__)
SnoozeBlock config_teensy36(digital, alarm, compare);
#elif defined(__MK64FX512__)
SnoozeBlock config_teensy35(digital, timer, compare);
#elif defined(__MK20DX256__)
SnoozeBlock config_teensy32(digital, timer, compare);
#elif defined(__MK20DX128__)
SnoozeBlock config_teensy30(digital, timer, compare);
#elif defined(__MKL26Z64__)
SnoozeBlock config_teensyLC(digital, timer, lc5vBuffer);
#endif

int sleepTiming = millis();
void setup() {
  Serial.begin(9600);
  pinMode(33, INPUT_PULLUP);
  pinMode(35, INPUT_PULLUP);

  digital.pinMode(33, INPUT_PULLUP, RISING);
  digital.pinMode(35, INPUT_PULLUP, RISING);
}

void loop() {
  if (millis() - sleepTiming > 3000) {
    Serial.println("Test Sleep");
    delay(100);
    #if defined(__MK66FX1M0__)
        Snooze.sleep( config_teensy36 );// return module that woke processor
    #elif defined(__MK64FX512__)
        Snooze.sleep( config_teensy35 );// return module that woke processor
    #elif defined(__MK20DX256__)
        Snooze.sleep( config_teensy32 );// return module that woke processor
    #elif defined(__MK20DX128__)
        Snooze.sleep( config_teensy30 );// return module that woke processor
    #elif defined(__MKL26Z64__)
        Snooze.sleep( config_teensyLC );// return module that woke processor
    #endif

    sleepTiming = millis();
  }

  delay(100);
}

Thanks,
Uyen

USB-HID device failure after call to 'sleep' or 'deepSleep'

Hi.

I have a Teensy 3.0 set up as a USB-HID device acting as a keyboard.
Arduino IDE 1.6.8, Teensyduino 1.28. Running at 48MHz.

My setup contains

  config.setTimer(35);
  config.setPeripheral = USB_ON;
  Keyboard.begin();
. . .

And my loop is like

. . .
  rescanKeyboard();

  // Snooze.idle();  // this works, but has a minimal effect
  // Snooze.sleep(config); // this pauses, but breaks USB-HID
  // Snooze.deepSleep(config);  // this pauses, but breaks USB-HID
  delay(35); // the old, power hungry code
. . . // do keyboard logic . . .
  digitalWrite(ledPin, (keyDown) ? HIGH : LOW);

If I call Snooze.idle, the USB device continues to work, but the delay is very small (I haven't checked with a scope, but it's around 500us)
The sleep and deepSleep calls pause and resume effectively -- I can see a big power consumption drop, and the 'key-down' led lights as expected.
However, the USB HID device no longer works (does not show up as a device) as soon as the delay is called.
If I reduce config.setTimer to 1 or 0, the USB still dies.

This failure also happens if I use the REDUCED_CPU_BLOCK call at any point.

Power consumptions are (approx):

plain delay()            -- 130mw
for() loop around idle() -- 127mw
sleep() / deepSleep()    -- 50mw

Can you help?

Many thanks.

power consumption comparison between Teensy3.1 and TeensyLC

Hi, first of all, thank you for your great work!

I use your library on a Tennsy32 (no modification) and measure hibernate power consumption of about 43uA. Did you manage to have less than that?

I'm also wondering whether using an TeensyLC would provide further lower consumption or not. I do not have the TeensyLC and if you measure lower power consumption, then it will definitely be interesting for me to buy some. Thank you for any answer you can provide.

regards,

Snooze changes pin function

I try to use snooze but it changes the behavior of my software.

I have a pump and a switch (usual pullup configuration). If switch is not pressed the pump shall pump. If switch is hold down the pump shall continue pumping for some seconds and then stop.

It is more or less this:

void setup() {
pinMode(13,OUTPUT); // pump
pinMode(8,INPUT_PULLUP); // switch
}

void loop() {
static unsigned long ticker;
if (digitalRead(8)==LOW) {
if (millis()-ticker>5000) {
digitalWrite(13,LOW);
}
} else {
ticker=millis();
digitalWrite(13,HIGH);
}
}

I thought I could send the teensy 3.1 to sleep and wake it up again if button moves... I downloaded current snooze and now it looks like that:

include <Snooze.h>

SnoozeBlock config;

void setup() {
pinMode(13,OUTPUT); // pump
config.pinMode(8, INPUT_PULLUP, CHANGE);
}

void loop() {
static unsigned long ticker;
if (digitalRead(8)==LOW) {
if (millis()-ticker>5000) {
digitalWrite(13,LOW);
}
} else {
ticker=millis();
digitalWrite(13,HIGH);
}
}

I didn't implement the sleep, because it already stopped working; reading the input seems to be always low.

Any hint? Thanks!

Maintaining PWM output during sleep/hibernate modes

Hi,

First of all, thanks for this great library!

I have a project (it will use either Teensy 3.2 or LC, still TBD) where I need to output PWM for a about a second, and then possibly update the PWM value, wait another second, and so forth. I want to put the MCU into a sleep mode in order to save power during the wait period. Is this possible?

This is the code I tried, however it does not seem to work.

Code:

/*`
	AnalogWrite with snooze test
	01/01/2017
 */

#include <Snooze.h>
SnoozeTimer timer;
SnoozeBlock config(timer);


void setup() {
  pinMode(3, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  timer.setTimer(1000);
}

void loop() {
	analogWrite(3, 32);
	Snooze.hibernate(config);
	analogWrite(3, 0);
	blink();
	analogWrite(3, 64);
	Snooze.hibernate(config);
	analogWrite(3, 0);
	blink();
	analogWrite(3, 128);
	Snooze.hibernate(config);
	analogWrite(3, 0);
	blink();
	analogWrite(3, 256);
	Snooze.hibernate(config);
	analogWrite(3, 0);
	blink();
}

void blink() {
	for (int i = 0; i < 2; i++) {
		digitalWrite(LED_BUILTIN, HIGH);
		delay(200);
		digitalWrite(LED_BUILTIN, LOW);
		delay(200);
	}
}

This code is supposed to sweep the PWM output of pin 3 after a wait period of a second. It also blinks the onboard LED two times between transitions.
When I run this, I don't see the PWM rate updating. What I see instead is that pin 3 will be stuck to either high or low during the sleep. It seems like that pin gets stuck at whatever the PWM output was just as the MCU entered the sleep mode.

Any insights and tips are appreciated. Thank you and a happy new year!

Can we configure wakeup for 3 seconds longhold of button press?

Hi,
Thanks a lot for this amazing library. We are using your library to put our teensy3.2 enabled prototype into sleep. I am configuring 2 pin of teensy as input pull up to wake up teensy. I have connected a active low detection switch with 2nd pin. Hence, Teensy is waking up fantastically on pressing switch after sleep.
According to utility of our product, Teensy should wake up from sleep after button press of 3 seconds hold. Now, as far as I understand your library, if i press button & release (irrespective of for how much seconds it pressed), teensy takes it as a single press & wakes up. So when we configure 2nd pin of teensy as wake up pin in void setup(), is there any instruction set by which I can configure wake up detection after 3 seconds of long hold?. So that Teensy only wakes up after 3 seconds of button press or in other words, teensy considers 3 seconds long hold button press as wake up signal.
If you can give us a solution or any config settings, your library can satisfies our this functionality also.
Thanks again for awesome library.

Hibernate not able to wakeup

Hi,

I want to implement Hibernate but it's not able to wake the system up with a specified button (pin 33 in my sample). My Teensy version is 3.5 and I'm using Snooze 6.2.8

Below is my sample code:

// Sample code: Hibernate after 5 seconds
#include <Snooze.h>

SnoozeDigital digital;
SnoozeCompare compare;
SnoozeTimer timer;
SnoozeAlarm alarm;

#if defined(__MK66FX1M0__)
SnoozeBlock config_teensy36(digital, alarm, compare);
#elif defined(__MK64FX512__)
SnoozeBlock config_teensy35(digital, timer, compare);
#elif defined(__MK20DX256__)
SnoozeBlock config_teensy32(digital, timer, compare);
#elif defined(__MK20DX128__)
SnoozeBlock config_teensy30(digital, timer, compare);
#elif defined(__MKL26Z64__)
SnoozeBlock config_teensyLC(digital, timer, lc5vBuffer);
#endif

int sleepTiming = millis();
void setup() {
  Serial.begin(9600);
  pinMode(33, INPUT_PULLUP);
  digital.pinMode(33, INPUT_PULLUP, RISING);
}

void loop() {
  if (millis() - sleepTiming > 5000) {
    Serial.println("Test Hibernate");
    delay(100);
    #if defined(__MK66FX1M0__)
        Snooze.hibernate( config_teensy36 );// return module that woke processor
    #elif defined(__MK64FX512__)
        Snooze.hibernate( config_teensy35 );// return module that woke processor
    #elif defined(__MK20DX256__)
        Snooze.hibernate( config_teensy32 );// return module that woke processor
    #elif defined(__MK20DX128__)
        Snooze.hibernate( config_teensy30 );// return module that woke processor
    #elif defined(__MKL26Z64__)
        Snooze.hibernate( config_teensyLC );// return module that woke processor
    #endif

    sleepTiming = millis();
  }
  delay(100);
}

Thanks!
Uyen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.