Hi,
While working on getting my board to sleep and wake up, I've isolated a pretty strange behavior.
After the *second* time teensy wakes from deepSleep(), and after all subsequent wakeups, the first two Serial.println() statements have their output swapped.
I found this while running a simple test script based on the Snooze audio deepSleep_all_wakeups example. I just added some logging to it.
Here's what the output looks like before the first sleep:
Then after it wakes up again the first time, I see this (expected) output:
But after subsequent wakeups, I see this:
This happens even if I wait a good long time (2 seconds) after wakeup before I print anything.
This could be a bug in Teensy code, or in MacOS 11.2.3, or in Teensyduino, or my code, or who knows what else.
I wonder if this is a known problem, or if there's anything else I can do to help solve it. It's not really an issue for me because I only use it for logging, but I bet it's a problem for someone.
For the record, this is with TeensyDuino 1.53, Arduino 1.8.13, MacOS 11.2.3 , Snooze 6.3.9 .
Code included below:
While working on getting my board to sleep and wake up, I've isolated a pretty strange behavior.
After the *second* time teensy wakes from deepSleep(), and after all subsequent wakeups, the first two Serial.println() statements have their output swapped.
I found this while running a simple test script based on the Snooze audio deepSleep_all_wakeups example. I just added some logging to it.
Here's what the output looks like before the first sleep:
Code:
three
two
one
zzz
Then after it wakes up again the first time, I see this (expected) output:
Code:
Good morning
three
two
one
zzz
But after subsequent wakeups, I see this:
Code:
three
Good morning
two
one
zzz
This happens even if I wait a good long time (2 seconds) after wakeup before I print anything.
This could be a bug in Teensy code, or in MacOS 11.2.3, or in Teensyduino, or my code, or who knows what else.
I wonder if this is a known problem, or if there's anything else I can do to help solve it. It's not really an issue for me because I only use it for logging, but I bet it's a problem for someone.
For the record, this is with TeensyDuino 1.53, Arduino 1.8.13, MacOS 11.2.3 , Snooze 6.3.9 .
Code included below:
Code:
/***************************************
This shows all the wakeups for deepSleep
Supported Micros: T-LC/3.x/4.0
****************************************/
#include "Bounce2.h"
#include <Snooze.h>
// Load drivers
SnoozeDigital digital;
SnoozeCompare compare;
SnoozeTimer timer;
//SnoozeUSBSerial usb;
#if !defined(__MK64FX512__) && !defined(__IMXRT1062__)
SnoozeTouch touch;
#endif
SnoozeAlarm alarm;
#if defined(__MKL26Z64__)
// configures the lc's 5v data buffer (OUTPUT, LOW) for low power
Snoozelc5vBuffer lc5vBuffer;
#endif
/***********************************************************
Teensy 4.0 does not have a Touch Interface. Always use the
SnoozeUSBSerial Driver.
Teensy 3.6/LC can't use Timer Driver with either Touch or
Compare Drivers and Touch can't be used with Compare.
Teensy 3.5 does not Touch Interface.
Teensy LC does not have a rtc so Alarm Driver can't be
used as of yet.
Teensy 3.2 can use any Core Drivers together.
***********************************************************/
#if defined(__IMXRT1062__)
SnoozeBlock config_teensy40(usb, digital, alarm);
#elif defined(__MK66FX1M0__)
SnoozeBlock config_teensy36(touch, digital, alarm);
#elif defined(__MK64FX512__)
SnoozeBlock config_teensy35(digital, compare, timer);
#elif defined(__MK20DX256__)
//SnoozeBlock config_teensy32(touch, digital, compare, timer);
//SnoozeBlock config_teensy32(digital, timer);
SnoozeBlock config_teensy32(timer);
#elif defined(__MK20DX128__)
SnoozeBlock config_teensy30(touch, digital, compare, timer);
#elif defined(__MKL26Z64__)
SnoozeBlock config_teensyLC(lc5vBuffer, digital, timer);
#endif
// GUItool reqs:
#include <Audio.h>
// GUItool: begin automatically generated code
//AudioSynthNoisePink pink1; //xy=88,242
AudioSynthNoiseWhite pink1; //xy=88,242
AudioAmplifier amp1; //xy=257,241
//AudioEffectReverb reverb1; //xy=440,243
AudioOutputAnalog dac1; //xy=628,246
AudioConnection patchCord1(pink1, amp1);
//AudioConnection patchCord2(amp1, reverb1);
//AudioConnection patchCord3(reverb1, dac1);
AudioConnection patchCord2(amp1, dac1);
// GUItool: end automatically generated code
// set pin numbers:
const int button1Pin = 0; // sw1
const int button2Pin = 9; // sw2
const int led1Pin = 21; // led1
const int led2Pin = 20; // led2
const int pulsePin1 = 11; // j1 tip
const int pulsePin2 = 8; // j2 tip
const int analogOut = 14; // j1/j2 ring: 12 bit DAC on Teensy 3.2 !
const int PO_play = 16; // goes high on PO play (runs to play LED)
const int PO_wake = 17; // goes low when PO sleeps I think
const int PO_reset = 7;
const int PO_SWCLK = 6;
const int PO_SWDIO = 5;
const int PO_SWO = 4;
const int IMU_fsync = 1; // need to ground this on icm-42605
const int IMU_int = 2;
// default time periods:
const int debounceLen = 2;
// Objects:
Bounce btn1 = Bounce();
Bounce btn2 = Bounce();
#define PRESSED(btn) (btn.read() == LOW)
void setup() {
Serial.begin(115200); // not needed? see if it affects sleep? sleep seems good atm.
// TODO: also check if Serial+Midi mode affects sleep ...
// slight hack:
// because i changed chips, this pin (imu pin 10) is now "reserved" on the IMU:
pinMode(IMU_fsync, OUTPUT);
digitalWrite(IMU_fsync, 1); // ground this pin (teensy signals are "active low" so ground == 1)
// imu pin 11 is also reserved but I can't get to it from software ...
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
/********************************************************
Define digital pins for waking the teensy up. This
combines pinMode and attachInterrupt in one function.
Teensy 4.0
Digtal pins: all pins
Teensy 3.x
Digtal pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
Teensy LC
Digtal pins: 6,9,10,11,13,16,21,22
********************************************************/
//digital.pinMode(button1Pin, INPUT_PULLUP, FALLING);//pin, mode, type
digital.pinMode(button1Pin, INPUT_PULLUP, FALLING);//pin, mode, type
digital.pinMode(button2Pin, INPUT_PULLUP, FALLING);//pin, mode, type
pinMode(button1Pin, INPUT_PULLUP); // sw1
pinMode(button2Pin, INPUT_PULLUP); // sw2
btn1.attach(button1Pin);
btn1.interval(debounceLen);
btn2.attach(button2Pin);
btn2.interval(debounceLen);
/********************************************************
Teensy LC Does not have a RTC.
Set RTC alarm wake up in (hours, minutes, seconds).
********************************************************/
#if !defined(__MKL26Z64__)
alarm.setRtcTimer(0, 0, 10);// hour, min, sec
#endif
/********************************************************
Teensy 4.0 Set Low Power Timer wake up in Seconds.
MAX: 131071s
Teensy 3.x/LC Set Low Power Timer wake up in Milliseconds.
MAX: 65535ms
********************************************************/
#if defined(__IMXRT1062__)
timer.setTimer(5);// seconds
#else
timer.setTimer(5000);// milliseconds
#endif
/********************************************************
In deeSleep the Compare module works by setting the
internal 6 bit DAC to a volatge threshold for voltage
crossing measurements. The internal DAC uses a 64 tap
resistor ladder network supplied by VOUT33 at 0.0515625v
per tap (VOUT33/64). Thus the possible threshold voltages
are 0.0515625*(0-64). Only one compare pin can be used at
a time.
parameter "type": LOW & FALLING are the same and have no effect.
parameter "type": HIGH & RISING are the same and have no effect.
Teensy 4.0
Compare pins: 0, 1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
Teensy 3.x
Compare pins: 11,9,4
Teensy LC
Compare pins: 11
********************************************************/
// trigger at threshold values greater than 1.65v
//(pin, type, threshold(v))
//compare.pinMode(11, HIGH, 1.65);
// trigger at threshold values less than 1.65v
//(pin, type, threshold(v))
compare.pinMode(PO_wake, HIGH, 3.65);
/********************************************************
Values greater than threshold will trigger TSI wakeup.
Threshold value is in capacitance. Only one pin can be
used while sleeping.
Teensy 4.0: No Touch Sense
Teensy 3.2/3.6
Touch Sense pins: 0,1,15,16,17,18,19,22,23,25,32,33
Teensy LC
Touch Sense pins: 0,1,3,4,15,16,17,18,19,22,23
********************************************************/
#if !defined(__MK64FX512__) && !defined(__IMXRT1062__)
/* touch.pinMode(0, touchRead(0) + 250); // pin, threshold */
#endif
// teensy audio setup
AudioMemory(2);
dac1.analogReference(EXTERNAL); // 3.3v p2p
pink1.amplitude(2);
//reverb1.reverbTime(0.5);
amp1.gain(0);
}
void loop() {
int who;
static elapsedMillis timer;
btn1.update();
btn2.update();
digitalWrite(led1Pin, PRESSED(btn1));
digitalWrite(led2Pin, PRESSED(btn2));
if (timer == 1000) {
Serial.println("three");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if (timer == 2000) {
Serial.println("two");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if (timer == 3000) {
Serial.println("one");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if (timer > 4000){
Serial.println("zzz");
/* Serial.flush(); */
/* digitalWrite(led1Pin, LOW); */
/* digitalWrite(led2Pin, HIGH); */
/* delay(100); */
/* digitalWrite(led2Pin, LOW); */
delay(10);
/********************************************************
feed the sleep function its wakeup parameters. Then go
to deepSleep.
********************************************************/
#if defined(__IMXRT1062__)
who = Snooze.deepSleep( config_teensy40 );// return module that woke processor
#elif defined(__MK66FX1M0__)
who = Snooze.deepSleep( config_teensy36 );// return module that woke processor
#elif defined(__MK64FX512__)
who = Snooze.deepSleep( config_teensy35 );// return module that woke processor
#elif defined(__MK20DX256__)
config_teensy32 += digital;
who = Snooze.deepSleep( config_teensy32 );// return module that woke processor
config_teensy32 -= digital;
#elif defined(__MK20DX128__)
who = Snooze.deepSleep( config_teensy30 );// return module that woke processor
#elif defined(__MKL26Z64__)
who = Snooze.deepSleep( config_teensyLC );// return module that woke processor
#endif
delay(2000);
Serial.println("Good morning");
if (who == button1Pin) { // pin wakeup source is its pin value
for (int i = 0; i < 1; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == button2Pin) { // pin wakeup source is its pin value
for (int i = 0; i < 2; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 34) { // compare wakeup value
for (int i = 0; i < 3; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 35) { // rtc wakeup value
for (int i = 0; i < 4; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 36) { // lptmr wakeup value
for (int i = 0; i < 5; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 37) { // tsi wakeup value
for (int i = 0; i < 6; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
timer = 0;
}
}