Comments (7)
Great, thanks mate. Have a nice weekend. Cheers
from deepsleepscheduler.
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.
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.
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.
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.
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
? OrSLEEP_MODE_EXT_STANDBY
? The same waySLEEP_MODE_PWR_SAVE
is notSLEEP_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.
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)
- Does not compile for DigiSpark Pro (AtTiny167) HOT 6
- Documentation on used sleep mode HOT 5
- NTP Daily task HOT 3
- Debounce Example HOT 1
- MIN_WAIT_TIME_FOR_SLEEP HOT 3
- Compiler warnings HOT 5
- swap SLEEP_MODE at run time? HOT 3
- Error printing to Serial Monitor HOT 3
- External Interrupt HOT 7
- add scheduleOnce() HOT 7
- Does not compile on DOIT ESP32 DEVKIT V1 HOT 1
- multiple definition of '****' HOT 1
- ESP8266 resetting HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepsleepscheduler.