n0m1 / sleep_n0m1 Goto Github PK
View Code? Open in Web Editor NEWA library that sets the Arduino into sleep mode for a specified length of time, or until an interrupt
Home Page: http://n0m1.com
A library that sets the Arduino into sleep mode for a specified length of time, or until an interrupt
Home Page: http://n0m1.com
Hello, thanks a lot for your library !
I'm trying to use it and I found a little problem. Maybe you can find the solutions quickly than me.
I use an Arduino Uno with A sigfox modem to send data with a keypad. I use a button to wake my Uno with an interruption on pin 2. I send many datas in the first step of the sketch but after the sleep mode it's impossible to send anything. I have errors with send function. It's like the modem is not reachable. Like the connection is lost forever. A reset of the Arduino is not enough to make it works again. I have to unplug an re-plus the USB.
Have you any idea where the problem come from ?
Arduino: 1.6.11 (Windows 7), Board: "Arduino Nano, ATmega168"
In file included from C:...\Arduino\libraries\Sleep_n0m1examples\Sleep_n0m1_simple\Sleep_n0m1_simple.ino:1:0:
C:...\Arduino\libraries\Sleep_n0m1/Sleep_n0m1.h: In member function 'void Sleep::extStandbyMode()':
C:...\Arduino\libraries\Sleep_n0m1/Sleep_n0m1.h:87:37: error: 'SLEEP_MODE_EXT_STANDBY' was not declared in this scope
void extStandbyMode(){setSleepMode(SLEEP_MODE_EXT_STANDBY);}
^
exit status 1
Error compiling for board Arduino Nano.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I get this error when I verify my code:
C:\Users\Doug\Documents\Arduino\libraries\Sleep_n0m1-master\Sleep_n0m1.cpp: In function 'void sleepHandler()':
C:\Users\Doug\Documents\Arduino\libraries\Sleep_n0m1-master\Sleep_n0m1.cpp:250:6:
warning: 'sleepHandler' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr]
void sleepHandler(void)
^
I'm very new at this, so I apologize if there's something very simple I can do to fix this. I have no idea what this all even means, so any help would be appreciated. Below I'm including the code for my project, which is a laser pointer cat toy designed to turn on every hour to give the kitties something to do while I'm at work.
#include <Servo.h>
#include <Sleep_n0m1.h>
Sleep sleep;
unsigned long sleepTime = 3600000;
Servo tiltservo;
Servo panservo;
int tiltpos = 0;
int panpos = 0;
int wait = 750;
int panmax = 105;
int panmin = 75;
int tiltmax = 105;
int tiltmin = 75;
int x = 0;
const int tilt = 3;
const int pan = 5;
const int lcd = 7;
void setup() {
tiltservo.attach(tilt);
panservo.attach(pan);
pinMode(lcd, OUTPUT);
}
void loop() {
tease();
rest();
}
void tease(){
digitalWrite(lcd, HIGH);
for( int x=25; x>=0; x--){
int scenario = random(0,2);
switch(scenario){
case 0:
buzz();
break;
case 1:
glide();
break;
case 2:
morse();
break;
}
}
tiltservo.write(tiltmin);
panservo.write(panmin);
digitalWrite(lcd, LOW);
delay(2000);
}
void buzz(){
for(int x=5; x>=0; x--){
tiltpos = random(tiltmin, tiltmax);
panpos = random(panmin, panmax);
tiltservo.write(tiltpos);
panservo.write(panpos);
delay(500);
for(int y=10; y>=0; y--){
tiltpos = tiltpos + random(-4,4);
panpos = panpos + random(-4,4);
tiltservo.write(tiltpos);
panservo.write(panpos);
delay(500);
}
}
delay(1500);
}
void glide(){
tiltpos = tiltmin;
panpos= panmin;
int z = tiltmax - tiltmin;
tiltservo.write(tiltpos);
panservo.write(panpos);
delay(50);
for(x = z; x>=0; x--){
tiltpos = tiltpos + 1;
panpos = panpos +1;
tiltservo.write(tiltpos);
panservo.write(panpos);
delay(50);
}
delay(2000);
}
void morse(){
tiltpos = (tiltmin + tiltmax)/2;
panpos = (panmin + panmax)/2;
tiltservo.write(tiltpos);
panservo.write(panpos);
for(int x=10; x>=0; x--){
digitalWrite(lcd, LOW);
delay(500);
digitalWrite(lcd, HIGH);
delay(500);
}
delay(2000);
}
void rest(){
digitalWrite(lcd, LOW);
tiltservo.write(tiltmin);
panservo.write(panmin);
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(sleepTime); //sleep for: sleepTime
}
Seems unlikely that this is faulty, but when I enter "1800 * 1000" for sleepTime I get about 30 seconds instead of 30 minutes. Is there an explanation?
I've made this small code to test "Sleep_n0m1" in the MEGA2560:
#include <Sleep_n0m1.h>
Sleep sleep;
void setup() {
}
void loop() {
delay(3000);
sleep.pwrDownMode(); // 9 mA
sleep.sleepDelay(10000);
}
The problem is that it's working only in the second call to the "sleepDelay" function.
In my code, the board starts drawing ~80 mA, and after 3 secs goes into the first "pwrDownMode" drawing ~60 mA. After 10 secs it wakes up drawing ~80 mA again and after 3 secs goes into the second "pwrDownMode" but now consuming only ~28 mA !!
The code works great except when I monitor for a pin high condition. I changed falling and low to rising and high in the library. Any thoughts?
Thanks!
Hello, trying to keep Arduino in sleep mode until one of the two events have occurred
1 if the desired time has passed , Arduino wakes up does its thing. OR if the time has NOT passed but interrupt pin becomes active Arduino wakes up.
Is this possible?
Thanks for you help.
Hello, i would like to ask something because i have a problem with your library (i guess). I need the arduino to run every 12 hours so on sleep time i write :sleepTime = 43200000; which is 12 hours but in reality it doesnt run every 12 hours but takes more time and its inaccurate. Any ideas what can be the problem?
Thank you.
Maybe it will be nice if the calibration only used some ms of the total sleep instead of replacing the whole first sleep?
Like 1000 ms of the first sleep.
Does FALLING/LOW requires an external oscillator?
How can I wait for a pin to go LOW using the lowest energy?
IF I use:
while (!digitalRead(SENSOR_PIN));{
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(60000);}
It uses about 4-5 mA, but:
sleep.sleepInterrupt(digitalPinToInterrupt(SENSOR_PIN), RISING);
uses <200 uA ... too bad
sleep.sleepInterrupt(digitalPinToInterrupt(SENSOR_PIN), FALLING);
seems to sleep the atmega forever :/
error: 'class Sleep' has no member named 'sleepPinInterrupt'
sleep.sleepPinInterrupt(alarmPin,LOW); //(interrupt Pin Number, interrupt State)
https://create.arduino.cc/editor/cemkaan/ce3fcfa7-0e2f-449c-b01a-c9c9eadb30c8/preview
Hi,
when compiling into Arduino IDE 1.6.12 i'm receiving this warning:
`
In function 'sleepHandler':
C:\Users\user\Documents\Arduino\libraries\Sleep_n0m1\Sleep_n0m1.cpp:250:6: warning: 'sleepHandler' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr]
void sleepHandler(void)
^`
Hi,
can you please add a list of Arduino devices where you can truly say that the library works? A quick look at the code say "Fail on the mega" ?
Regards, Andy
help me please
how to wake up from sleep.sleepDelay(600000); through an interrupt ?
I wrote a program to let Arduino UNO blink for 2 secs, display millis() on an OLED screen, sleep for 5 sec, and then loop it again and again.
However I noticed that except idleMode, in other modes the displayed time difference of 1st loop is about 7 seconds, but in later loops it is about 2 seconds. It seems that millis() didn't count the past time during later sleep periods.
In idleMode, the difference is always about 7 seconds.
I expected it to display same difference since the UNO had only entered the same sleep mode, which should have the same result.
Perhaps the external oscillator is disabled in later sleep times than the 1st time?
Note that I don't have that much knowledge about sleep modes...Just happened to get to know it to save some power for my battery driven device.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.