Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.1 sleep support?

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Posts
    4

    Teensy 4.1 sleep support?

    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 by KailoWren; 10-05-2022 at 10:37 PM.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,433
    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.

  3. #3
    Junior Member
    Join Date
    Oct 2022
    Posts
    4
    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.

  4. #4
    Senior Member
    Join Date
    Oct 2019
    Posts
    450
    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.

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,433
    Good pointer REZO - should have suggested checking the OPEN issues ... there it is.

  6. #6
    Junior Member
    Join Date
    Oct 2022
    Posts
    4
    Quote Originally Posted by Rezo View Post
    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!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •