Giter Site home page Giter Site logo

Comments (7)

PRosenb avatar PRosenb commented on July 22, 2024 1

Great, thanks mate. Have a nice weekend. Cheers

from deepsleepscheduler.

PRosenb avatar PRosenb commented on July 22, 2024

Hi @scottkelso,
nice are you using my library.

Are you running it on Arduino Uno?

I think it has to do with the sleep mode the CPU is put by DeepSleepScheduler.
You can configure what sleep mode is entered when the CPU is idle by defining the constant
SLEEP_MODE before you include DeepSleepScheduler.h.

Please see documentation for details.

The default SLEEP_MODE is POWER_DOWN where not all interrupts are active. Please see documentation of the CPU on page 48.

You can quickly check if it's caused by that by setting SLEEP_MODE to SLEEP_MODE_IDLE:
#define SLEEP_MODE SLEEP_MODE_IDLE

How did you go?

from deepsleepscheduler.

scottkelso avatar scottkelso commented on July 22, 2024

Thanks for the quick reply @PRosenb !

I'm running an Elegoo Mega 2560 and have since checked its datasheet.

Setting #define SLEEP_MODE SLEEP_MODE_IDLE as you suggested has allowed the interrupt to execute, which seems interesting as the datasheet p50 would suggest that the SLEEP_MODE_PWR_DOWN should still allow wake-up sources from INT7:0 and Pin Change, as I was doing with digitalPinToInterrupt(2).

In this mode, the external Oscillator is stopped, while the external interrupts, the 2-wire Serial Interface, and the Watchdog continue operating (if enabled). Only an External Reset, a Watchdog Reset, a Brown-out Reset, 2-wire Serial Interface address match, an external level interrupt on INT7:4, an external interrupt on INT3:0, or a pin change interrupt can wake up the MCU.

Is there any way to extend the library to apply other sleep modes allowed by ATMEGA2560?

from deepsleepscheduler.

PRosenb avatar PRosenb commented on July 22, 2024

There is no extension needed, you can set any sleep mode with
#define SLEEP_MODE <any supported sleep mode by the CPU>

I remember that I also had some troubles with interrupts not firing and think it helped to use this library.
https://github.com/GreyGnome/EnableInterrupt

from deepsleepscheduler.

scottkelso avatar scottkelso commented on July 22, 2024

Oh very cool. I will try some more things out this weekend and post anything I find out here. Thanks for the help!

from deepsleepscheduler.

scottkelso avatar scottkelso commented on July 22, 2024

I have since had a chance to try some other sleep modes, however IDLE still seems to be the only mode which is allowing an interrupt on digitalPinToInterrupt(2)

#define SLEEP_MODE SLEEP_MODE_IDLE              // Interrupt works
#define SLEEP_MODE SLEEP_MODE_PWR_SAVE          // Interrupt doesn't works
#define SLEEP_MODE SLEEP_MODE_PWR_DOWN          // Interrupt doesn't works

As a less important side note: I am unsure where these SLEEP_MODE options are defined. I know based on my board's datasheet that it also supports modes like standby and ADCNRM, but I can't find any documentation on the wording of the variable. E.g. SLEEP_MODE_EXTENDED_STANDBY? Or SLEEP_MODE_EXT_STANDBY? The same way SLEEP_MODE_PWR_SAVE is not SLEEP_MODE_POWER_SAVE.

I have also tried using EnableInterrupt with no change. E.g. change attachInterrupt to enableInterrupt, and then remove detachInterrupt's according to EnableInterrupt's Debounce example. Interrupt still only fires on SLEEP_MODE_IDLE.

void measure_rotation ()  {
  if (digitalRead(CLK_PIN))
    rotationdirection = digitalRead(DT_PIN);
  else
    rotationdirection = !digitalRead(DT_PIN);
  TurnDetected = true;
  ...
  // attachInterrupt(CLK_PIN, isr, FALLING);
}

void isr() {
  scheduler.scheduleOnce(measure_rotation);
  //  // detach interrupt to prevent executing it multiple
  //  // times when touching more than once.
  //  detachInterrupt(digitalPinToInterrupt(CLK_PIN));
}

void setup() {
  Serial.begin(9600);
  ...
  pinMode(CLK_PIN,INPUT);
  pinMode(DT_PIN,INPUT);  
  pinMode(SW_PIN,INPUT_PULLUP);
  enableInterrupt(CLK_PIN, isr, FALLING);
  // attachInterrupt(CLK_PIN, isr, FALLING);
  ...
}

void loop() {
  scheduler.execute();
}

The only other thing I can think of to try is other pins other than 2 (which I will do soon).

from deepsleepscheduler.

PRosenb avatar PRosenb commented on July 22, 2024

Mmmm.. The example ScheduleFromInterrupt uses SLEEP_MODE_PWR_DOWN and works on my Arduino Uno.
Could you try that one?

from deepsleepscheduler.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.