Teensy 4.1 sleep support?

KailoWren

New member
I'm working on a project that requires running a Teensy 4.1 in low-power mode with the ability to wake it up. However, it appears that any example code I attempt to load on the device that uses <Snooze.h> prevents the Teensy 4.1 from functioning. In fact, just adding the line "#include <Snooze.h>" to my main project file causes problems. The code compiles and even loads onto the device, but the red LED near the USB port flashes repeatedly and the device serial port disappears.

Here's the most recent example code I attempted to load:

Code:
//quick n dirty teensythreads deepSleep test with Snooze

#include <Snooze.h>
#include <SnoozeBlock.h>
#include <Arduino.h>

#include "TeensyThreads.h"
SnoozeTimer timer;
SnoozeBlock config(timer);

const int LED = 13;
const int UserLED = 2;

//your sleeping funcion
int enter_sleep(int ms) {
  timer.setTimer(ms);//set sleep time in milliseconds  
  Snooze.hibernate( config ); //go to actual sleep
  //additional, one can use the RTC or a low power timer
  //to calculate actual time spent asleep and return the
  //value to the scheduler to calculate better times.
  return ms;
}

void heartbeat() {
  while (1) {
    threads.sleep(3000);
    digitalWriteFast(LED, !digitalRead(LED));
  }
}

void fastbeat() {
  while (1) {
    threads.sleep(1555);
    digitalWriteFast(UserLED, !digitalRead(UserLED));
  }
}

void setup() {
  pinMode(2, OUTPUT);
  digitalWriteFast(2, LOW); 
  pinMode(LED, OUTPUT);
  digitalWriteFast(LED, LOW);
  delay(2000);
  threads.addThread(heartbeat);
  threads.addThread(fastbeat);
  while(1) {
    threads.idle();
    //custom infinite loop
  }
}
void loop() {
  //i prefer to prevent the main loop from running as it causes CPU overhead because USB and other event handlers..
}

The documentation of this library indicates that it should work on the Teensy 4.0, which has the same processor. This is highly problematic, as we cannot locate any older Teensy devices to underpin this project. Is there a working sleep library for the 4.1 that I'm not aware of? What differences in the 4.1 hardware would prevent this library from functioning? Thanks in advance!
 
Last edited:
The included SNOOZE lib comes from github.com/duff2013/Snooze - I suppose it is current in the present TD releases as it doesn't seem to have recent changes.

Not indicated - Assuming the TeensyDuino in use is current 1.57 or 1.58 in beta?

The Readme does indicate:
Code:
Snooze v6.3.9
Low power library for the Teensy LC/3.2/3.5/3.6/4.0 class microcontrollers.
Teensy 4.0 v2 update!

This is a maintenance update because of a change in the new class structure which the main Snooze Class is now decoupled from the Drivers and HAL. Now sleep*, deepSleepand hibernate work with T_LC and 3.x. Now the T_LC/36 Driver "Touch" works in "sleep" mode.

not all drivers work in "sleep" yet.

Try the complete simple examples there for functionality.

Having the RED bootloader LED light is an indication of an odd problem. The Teensy T_4.1 bootloader was updated in 1.56 (?) when run with Teensy Loader for an upload, and there was a startup problem fixed as well. Running TD 1.57 and IDE upload with Teensy Loader will have those changes.
 
Thanks for the fast reply; I'm running Teensyduino 1.57. I'll go through the referenced examples tomorrow and see if something sticks. I might try a different device to see if maybe I have a defective one here.
 
A manual fix needs to be applied to the Snooze library
There was a breaking change with TD1.56 I believe: here it is
Placing startup_early_hook into FLASHMEM will fix the blinking bootloader led and allow the Teensy to startup.
 
A manual fix needs to be applied to the Snooze library
There was a breaking change with TD1.56 I believe: here it is
Placing startup_early_hook into FLASHMEM will fix the blinking bootloader led and allow the Teensy to startup.

That did it! Now to press forward and see if I can make it work with the rest of the code. :) Thanks!!
 
Back
Top