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

Thread: Advice on complicated sleep problems?

  1. #1

    Advice on complicated sleep problems?

    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, which is amazing! But now I'm trying to implement power savings using the Snooze library, and it's not really working as it's supposed to. 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 actual po_wake pin that is configured to listen to on RISING is going high but still no wakeup. And a 3000ms Snooze.timer() is also not working. 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. But 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?

    Thanks for any advice,

  2. #2
    Update: I got the provided Snooze library examples to work, then began adding the features from my sketch & noting how things get broken. For the record, here's what I'm seeing as I'm debugging with Snooze, Bounce2 and TeensyAudio on Teensy 3.2 :

    * Teensy Audio prevents sleep(), and causes deepSleep() to hang. With or without the SnoozeAudio driver. With or without calling the undocumented usingDAC(pin) method of that driver. With or without turning off/on AudioInterrupts() during sleep. (I'm not sure what the SnoozeAudio driver is doing under Teensy 3.2 . Is it for use with the Teensy Audio Library, or just the Teensy Audio Adapter?)

    * The Bounce2 library and the Snooze library appear to be unable to share a pin. If SnoozeDigital is configured to wake on a pin, Bounce will not be able to read that same pin. And that's true whether or not you ever actually sleep the Teensy. (I don't see why Snooze would need to touch any state at all until the moment when it actually goes to sleep, but apparently it does.) I guess Snooze has some ability to attach/detach the digital driver from the SnoozeBlock using overloaded + and - operators, so I'll try more with that.

    * There seem to be situations where either Bounce2 or Snooze (or both together) can jam a pin in an unreadable mode which a program reset will not clear! Only a cold boot fixes it. Makes debugging harder ...

    Anyway, the main problem is that the author of Snooze claims that it works with Teensy Audio, but I'm finding that it doesn't. Can anybody point me at a working combination of Snooze and TeensyAudio running on Teensy 3.2 ?


Posting Permissions

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