0

I have been using the Jeelib Sleepy functionality for several years now to achieve low power states on the Arduino ATmega328/1280/2560 boards, specifically the LoseSomeTime functionality.

I want to get my Teensy 2 to go into a similar low power state, so I tried a very simple sketch that simply put the device to sleep, flashed an LED, and posted some Serial messages. I did need to comment out a few lines in Jeelib:

// adjust the milli ticks, since we will have missed several
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny45__)
    extern volatile unsigned long millis_timer_millis;
    millis_timer_millis += msecs - msleft;
#else
    extern volatile unsigned long timer0_millis;
    timer0_millis += msecs - msleft;
#endif

This had to be done as the delay() and millis() functions on the Teensy use different variable names for the adjustment, and it was the quickest way of solving the problem. LoseSomeTime works on the ATmega328 hardware with this change.

I found that although the LoseSomeTime function did sleep for a period, the Serial functionality stopped working entirely - no messages were being printed at all. I have encountered this before on ATmega328 hardware because the microcontroller has gone to sleep before the serial buffer was flushed. I added a number of delay()s after the Serial.writes and also tried using Serial.flush() to make sure the buffer was empty.

LoseSomeTime requires setting an interrupt on the watchdog timer, but I can't see how this would impact Serial operation.

4
  • 2
    You explicitly mention Teensy 2 for this issue, does it mean you have tried on other boards and did not encounter that problem? It looks so in your question, but it's not 100% clear on that point. It could be useful to mention a list of boards on which the same sketch works or doesn't work, in case you could test on different plqtforms.
    – jfpoilpret
    Feb 20 '14 at 22:13
  • Not a problem on any ATmega328, ATmega1280, ATmega2560 boards. I haven't tried on a Teensy 2++. I know it won't work with any of the ARM boards. Feb 20 '14 at 22:18
  • Does it have anything to do that serial is based on interrupts now? Could that affect it? I've never used the library though or the Teensy 2, so I don't know much about this situation, but I might look into it if I have time. Mar 4 '14 at 2:39
  • I think both an Uno and Teensy use interrupts for serial, don't they? At least since v1 of the IDE. Mar 4 '14 at 11:39
0

This is a problem with the Teensy boards - or more correctly that the Jeelib Sleepy library does not support the Teensy boards.

You will need to modify the library to make it work for Teensy boards. Or you could use another low power/sleep library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.