Teensy 4.1, Sleep mode and wakeup by RTC

Mr_Monk

New member
Hello,

my name is Ingo. I am new in this forum. I am from Potsdam/Germany.

I like to use a Teensy 4.1 board in a battery powered application. The Teensy shall measure some data (ADC), print that data on a e-paper display and then start an actor for a calculated time. Then the actor has to be switched off and the Teensy controller shall sleep to save power. The RTC shall then wakeup the Teensy via interrupt and the same procedure shall be repeated.
I use Arduino IDE 2.3.2.

I found that thread: RTC alarm to wake up from deep sleep?

But the sketch published there does not run with Teensy 4.1. Trying to compile, gives a lot of error messages beginning with:
error: 'SIM_SCGC6' was not declared in this scope

SIM_SCGC6 |= SIM_SCGC6_RTC;// enable RTC clock

Can anyone help? Is it really possible to let the Teensy 4.1 sleep and be waked up by its own RTC?

I am familar with Arduinos (mostly programmed in Assembler) but unfortunately a newcomer to Teensy boards.

Best regards

Ingo.
 
Hello WMXZ,

I deleted all unwanted (beside some variables, that I d) parts of your program and checked the sleep function.
The resulti is that the Teensy is resetted in the moment, when the line
who = Snooze.deepSleep( config_teensy32 );
is processed.

Does this not work on an Teensy 4.1?

/* Teensy 4.1 Sleep test */
String VERSION_NUMBER = "0.0";
#include <Wire.h>
#include <TimeLib.h> // For RTC
#include <Snooze.h>
#include <FreqMeasure.h>
// CREATE TIMERS
elapsedMillis master;

// CREATE OBJECTS
SnoozeDigital digital;
SnoozeAlarm alarm;
SnoozeBlock config_teensy32(digital, alarm);
// PIN DEFINES

#define LED_PIN 13
#define RAIN_INPUT 16
#define WIND_SPEED_INPUT 22
// MISC DEFINES
#define ARRAY_SIZE 200
// REPORTING LEVEL DEFINES (These tell the RPi what color to use for console messages )
#define OH_NO "0"
#define REQUEST_DATA "2"
#define SENSOR_DATA "3"
#define RAIN_DATA "3"
#define WIND_DATA "3"
#define GOOD_TO_KNOW "5"
#define NO_CHANGE "7"
#define MISC_DATA "8"
#define LOW_PRIORITY "9"
// Variables
String Node = "Backyard";
String datastring;
String messageType, reportingLevel, sensorName, sensorModel, sensorInfo, data01, data02, data03, future1, future2, comment;
boolean newData = false;
boolean recvInProgress = false;
boolean restarted = true;
unsigned int masterTime = 3000; // 3 second timer
unsigned int pingCount = 0;
unsigned long externalTime;
int who;
float seaLevelPressure;
// RTC VARIABLES
int RTCTime[6]; // ------ To do
// SERIAL2 VARIABLES
double freqsum = 0; // frequency counter summing
int freqcount = 0;
int incomingByte = 0; // incoming serial data
String serial2InData;
// WIND SPEED VARIABLES
int windSpeedRotations = 0;
int windSpeedSampleCount = 0;
float windSpeedArray[ARRAY_SIZE];
//timer counters
unsigned int Counter30sec = 10, Counter5min = 100, Counter20min = 400, Counter60min = 1200;
unsigned int uptimeSeconds = 0, uptimeMinutes, uptimeDays, uptimeHours;
void setup(){
//Serial.begin(19200);
Serial2.begin(9600, SERIAL_8N1);
//FreqMeasure.begin();
delay(1000); // Give Serial2 a moment to collect itself.
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
delay(5000);
digitalWrite(LED_PIN, LOW);


// RTC initialize
setSyncProvider(getTeensy3Time); // Use RTC
externalTime = 278631501; // Fake epoch time for testing
Teensy3Clock.set(externalTime);
setTime(externalTime); // Set the RTC
// RAINFALL INITIALIZE
digital.pinMode(16, INPUT_PULLDOWN, RISING); // Rainfall
// attachInterrupt(digitalPinToInterrupt(16), rainfallGetSample, RISING);
// WIND SPEED INITIALIZE
digital.pinMode(22, INPUT_PULLDOWN, RISING); // Wind speed
// attachInterrupt(digitalPinToInterrupt(22), windSpeedGetSample, RISING);

// RESTART MESSAGE

messageType = "Diagnostics";
reportingLevel = OH_NO;
comment = "Weather station " + VERSION_NUMBER + " has restarted.";

restarted = false;
alarm.setRtcTimer(0, 1, 30); // Set RTC alarm for 3 seconds.
}
void loop() {
who = Snooze.deepSleep( config_teensy32 ); // return module that woke processor
if (who == 16) {
delay(300);
digitalWrite(LED_PIN, HIGH);
delay(300);
digitalWrite(LED_PIN, LOW);
}
if (who == 22) {
delay(2000);
digitalWrite(LED_PIN, HIGH);
delay(2000);
digitalWrite(LED_PIN, LOW);
delay(2000);
digitalWrite(LED_PIN, HIGH);
delay(2000);
digitalWrite(LED_PIN, LOW);

}
if (who == 35) { // process counters
// 3 second events
digitalWrite(LED_PIN, HIGH);
delay(150);
digitalWrite(LED_PIN, LOW);
delay(150);
digitalWrite(LED_PIN, HIGH);
delay(150);
digitalWrite(LED_PIN, LOW);
delay(150);
alarm.setRtcTimer(0, 1, 10); // Set RTC alarm for 3 seconds.
Counter30sec += 1; Counter5min += 1; Counter20min += 1; Counter60min += 1; uptimeSeconds += 3;


}
}
// FUNCTIONS

float rounder(float roundme){ // Round float to the nearest .5
roundme = roundme * 2;
roundme = round(roundme);
roundme = roundme / 2;
return roundme;
}
void uptimeUpdate(){
if (uptimeSeconds >= 60) { uptimeSeconds = 0; uptimeMinutes += 1; }
if (uptimeMinutes >= 60) { uptimeMinutes = 0; uptimeHours += 1; }
if (uptimeHours >= 24) { uptimeHours = 0; uptimeDays += 1; }
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
 
I measured the current of the Teensy while running this program. The current drops to nearly 0mA for very short time. But the power enable pin of the controller does not switch off the power regulator.
If I connect the on/off - line for more than 3 seconds to GND, then the controller switches off its 3.3V regulator and sleeps (current is about 0.3 mA). Then the Teensy is waked after the time delay (90s) that is defined in the line:
alarm.setRtcTimer(0, 1, 30);

So I have to find a possibility to get the switch off effect by software and then there would be a solution to let the Teensy sleep and be waked by timer. The bad effect is that in that case the Teensy is resetted in every cycle.

Do you have any suggestion?

Greetings Ingo.
 
hibernate (switch off teensy) can only be woken up by RTC alarm (which is done by the code in other thread). once woken up, program starts with setup(). I cannot talk about snooze library that I do not use.
 
Back
Top