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:
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!
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: