(Reposting, because i posted in the wrong place before. Oops.)
Hello! I'm working on a project that embeds a Teensy 3.2 which is doing quite a lot .. it's running Teensy Audio, sending MIDI over USB, providing some debug over USB serial, and talking to an IMU/accelerometer chip over I2c. All of that works, amazingly.
But now I'm trying to implement power savings using the Snooze library, and it's not really working as it's supposed to. I want to sleep when a pin goes low, then wake on the spin rising and/or any button press. Depending on the configs I've tried, the sleep() method either doesn't go to sleep properly or doesn't wake up properly. For debugging purposes I have managed to get it to wake on one button press, but only by disabling that button for the rest of the app. The pin that Snooze.digital is configured to listen to on RISING is going high, but still no wakeup. I also tried a 3000ms Snooze.timer() for wakeup, and that didn't work either. Something is screwy.
I wonder if the things I'm trying to do are even allowed:
-- I need to wake up on any button press, so I'm running SnoozeDigital.pinmode() on the same two pins that are already attached to the Bounce2 library. Is that allowed? When I do that, it seems that Snooze always detects a button press and wakes immediately. Do I need to somehow detach Bounce2 and attach Snooze before sleeping, and then switch back on wakeup?
-- I am using the digital, usbserial and audio drivers. usbserial is supposed to let the teensy play well with USB serial during sleep & wake. But actually serial output from the teensy hangs after wake. (Although the computer does detect a USB serial device.) Do I need to reset the serial port somehow after sleeping? Does the fact that I'm also sending USB MIDI events mean that I need to do something different here, or is that also managed by usbserial ?
-- The IMU chip is generating interrupts when new data arrives. Do I need to disable interrupts before sleep? Teensy Audio uses interrupts too, and maybe Bounce2 does, I'm not sure. Does Snooze use interrupts in some way that might be incompatible with my situation?
-- The pin I'm trying to be woken by, PO_wake, puts out 2.5v, not the full 3.3v. When the teensy is awake & the pin is high, the Teensy reads it as logic-high, no problem ... is there some reason why that would behave differently during sleep? I suppose I could read the pin in ADC mode instead, but can I trigger Snooze with an analog pin?
Here's the relevant bits of not-working sleep code so far, extracted from a much larger file:
Much obliged for any advice,
-mykle-
Hello! I'm working on a project that embeds a Teensy 3.2 which is doing quite a lot .. it's running Teensy Audio, sending MIDI over USB, providing some debug over USB serial, and talking to an IMU/accelerometer chip over I2c. All of that works, amazingly.
But now I'm trying to implement power savings using the Snooze library, and it's not really working as it's supposed to. I want to sleep when a pin goes low, then wake on the spin rising and/or any button press. Depending on the configs I've tried, the sleep() method either doesn't go to sleep properly or doesn't wake up properly. For debugging purposes I have managed to get it to wake on one button press, but only by disabling that button for the rest of the app. The pin that Snooze.digital is configured to listen to on RISING is going high, but still no wakeup. I also tried a 3000ms Snooze.timer() for wakeup, and that didn't work either. Something is screwy.
I wonder if the things I'm trying to do are even allowed:
-- I need to wake up on any button press, so I'm running SnoozeDigital.pinmode() on the same two pins that are already attached to the Bounce2 library. Is that allowed? When I do that, it seems that Snooze always detects a button press and wakes immediately. Do I need to somehow detach Bounce2 and attach Snooze before sleeping, and then switch back on wakeup?
-- I am using the digital, usbserial and audio drivers. usbserial is supposed to let the teensy play well with USB serial during sleep & wake. But actually serial output from the teensy hangs after wake. (Although the computer does detect a USB serial device.) Do I need to reset the serial port somehow after sleeping? Does the fact that I'm also sending USB MIDI events mean that I need to do something different here, or is that also managed by usbserial ?
-- The IMU chip is generating interrupts when new data arrives. Do I need to disable interrupts before sleep? Teensy Audio uses interrupts too, and maybe Bounce2 does, I'm not sure. Does Snooze use interrupts in some way that might be incompatible with my situation?
-- The pin I'm trying to be woken by, PO_wake, puts out 2.5v, not the full 3.3v. When the teensy is awake & the pin is high, the Teensy reads it as logic-high, no problem ... is there some reason why that would behave differently during sleep? I suppose I could read the pin in ADC mode instead, but can I trigger Snooze with an analog pin?
Here's the relevant bits of not-working sleep code so far, extracted from a much larger file:
Code:
// in outer block:
SnoozeDigital s_digital;
SnoozeUSBSerial s_usbserial;
SnoozeAudio s_audio;
SnoozeBlock s_config(s_digital, s_usbserial, s_audio);
Bounce btn1 = Bounce();
// in setup():
pinMode(button1Pin, INPUT_PULLUP); // sw1
s_digital.pinMode(button1Pin, INPUT_PULLUP, RISING); // wake on btn 1 press
pinMode(PO_wake, INPUT);
s_digital.pinMode(PO_wake, INPUT, RISING); // wake on PO_wake pin voltage
btn1.attach(button1Pin);
btn1.interval(debounceLen);
// in main loop:
sleepPinState = digitalRead(PO_wake);
sleepState = sleepPinState;
if (sleepState) {
// do misc ...
} else {
// sleep until PO_wake goes high or btn1 is pressed:
Serial.println("zzzzz.");
delay(1);
Snooze.sleep(s_config);
Serial.println("good morning!");
awakeTime = 0;
}
Much obliged for any advice,
-mykle-