Comments (8)
Setting the Alarm to a day of the week works. You specified the mask as 3 in your example above, which denotes "day of week", but then you used the construct "DateTime(0,0,3,0,0,0)" I think you did something you didn't expect
DateTime xxx(0, 0, 3, 0, 0, 0);
Serial.print("Day of Week ");
Serial.println(xxx.dayOfTheWeek());
returns day "1" Which I believe you probably didn't want. You should enter a valid date as input for the DateTime() function and the the MCP7940.setAlarm() will take the DOW from that date and set the alarm accordingly.
from mcp7940.
That means if you call MCP7940.setAlarm(0,3,2019,02,01,0,0,0));
then it will set alarm 0 to trigger on a Friday.
from mcp7940.
Hello, SV-Zanshin,
Your solution works!!! thank you very much!!
from mcp7940.
No worries, glad you are having some success with the library!
from mcp7940.
Hello Zanshin,
Is it also possible to do a wake up after 10 or 30 seconds? How can i program that?
Kind regards,
Wim
from mcp7940.
from mcp7940.
Hello Zanshin,
is it possible to use the MCP7940 to interrupt the arduino mega by interrupt? and so yes, what am i doing wrong in the code below?
Kind regards,
Wim
#include <MCP7940.h> // Include the MCP7940 RTC library
/***************************************************************************************************
** Declare all program constants and enumerated types **
/
const uint32_t SERIAL_SPEED{9600}; ///< Set the baud rate for Serial I/O
const uint8_t LED_PIN{13}; ///< Arduino built-in LED pin number
const uint8_t SPRINTF_BUFFER_SIZE{32}; ///< Buffer size for sprintf()
const uint8_t ALARM1_INTERVAL{15}; ///< Interval seconds for alarm
const byte interruptPin = 82;
boolean mfpPinTriggered = false;
/! ///< Enumeration of MCP7940 alarm types /
enum alarmTypes {
matchSeconds,
matchMinutes,
matchHours,
matchDayOfWeek,
matchDayOfMonth,
Unused1,
Unused2,
matchAll,
Unknown
};
/
** Declare global variables and instantiate classes **
***************************************************************************************************/
MCP7940_Class MCP7940; ///< Create instance of the MCP7940M
char inputBuffer[SPRINTF_BUFFER_SIZE]; ///< Buffer for sprintf() / sscanf()
void rtcMFP()
{
mfpPinTriggered = true;
Serial.println(F(" #INTRTC#"));//delay(50);
}
void setup() {
attachInterrupt(digitalPinToInterrupt(2), rtcMFP, RISING);// (recommended)
//attachInterrupt(82, rtcMFP, RISING);//interrupt for rtc Alarm
/*!
@brief Arduino method called once upon start or restart.
*/
Serial.begin(SERIAL_SPEED); // Start serial port at specified Baud rate
#ifdef AVR_ATmega32U4 // If this is a 32U4 processor, then wait 3 seconds for the serial
// interface to initialize
delay(3000);
#endif
Serial.print(F("\nStarting SetAlarms program\n"));
Serial.print(F("- Compiled with c++ version "));
Serial.print(F(VERSION)); // Show compiler information
Serial.print(F("\n- On "));
Serial.print(F(DATE));
Serial.print(F(" at "));
Serial.print(F(TIME));
Serial.print(F("\n"));
while (!MCP7940.begin()) // Loop until the RTC communications are established
{
Serial.println(F("Unable to find MCP7940. Checking again in 3s."));
delay(3000);
} // of loop until device is located
Serial.println(F("MCP7940 initialized."));
while (!MCP7940.deviceStatus()) // Turn oscillator on if necessary
{
Serial.println(F("Oscillator is off, turning it on."));
bool deviceStatus = MCP7940.deviceStart(); // Start oscillator and return state
if (!deviceStatus) // If it didn't start
{
Serial.println(F("Oscillator did not start, trying again."));
delay(1000);
} // of if-then oscillator didn't start
} // of while the oscillator is of
Serial.println("Setting MCP7940M to date/time of library compile");
MCP7940.adjust(); // Use compile date/time to set clock
Serial.print("Date/Time set to ");
DateTime now = MCP7940.now(); // get the current time
// Use sprintf() to pretty print date/time with leading zeroes
sprintf(inputBuffer, "%04d-%02d-%02d %02d:%02d:%02d", now.year(), now.month(), now.day(),
now.hour(), now.minute(), now.second());
Serial.println(inputBuffer);
Serial.println("Setting alarm 0 for every minute at 0 seconds.");
MCP7940.setAlarm(0, matchSeconds, now - TimeSpan(0, 0, 0, now.second()),
true); // Match once a minute at 0 seconds
Serial.print("Setting alarm 1 to go off at ");
now = now + TimeSpan(0, 0, 0, ALARM1_INTERVAL); // Add interval to current time
sprintf(inputBuffer, "%04d-%02d-%02d %02d:%02d:%02d", now.year(), now.month(), now.day(),
now.hour(), now.minute(), now.second());
Serial.println(inputBuffer);
MCP7940.setAlarm(1, matchAll, now, true); // Set alarm to go off then
pinMode(LED_PIN, OUTPUT); // Declare built-in LED as output
} // of method setup()
void loop() {
/*!
@brief Arduino method called after setup() which loops forever
*/
static uint8_t secs;
DateTime now = MCP7940.now(); // get the current time
if (secs != now.second()) // Output if seconds have changed
{
sprintf(inputBuffer, "%04d-%02d-%02d %02d:%02d:%02d", now.year(), now.month(), now.day(),
now.hour(), now.minute(), now.second());
//Serial.print(inputBuffer);
secs = now.second(); // Set the counter for later comparision
if (MCP7940.isAlarm(0)) // When alarm 0 is triggered
{
Serial.print(" Alarm0");Serial.println(inputBuffer);
MCP7940.clearAlarm(0);
} // of if Alarm 0 has been triggered
if (MCP7940.isAlarm(1)) // When alarm 0 is triggered
{
Serial.print(" Alarm1 resetting to go off next at ");
now = now + TimeSpan(0, 0, 0, ALARM1_INTERVAL); // Add interval to current time
sprintf(inputBuffer, "%04d-%02d-%02d %02d:%02d:%02d", now.year(), now.month(), now.day(),
now.hour(), now.minute(), now.second());
Serial.println(inputBuffer);
MCP7940.setAlarm(1, matchAll, now, true); // Set alarm to go off in 10s again
} // of if Alarm 0 has been triggered
//Serial.println();
} // of if the seconds have changed
} // of method loop()
from mcp7940.
@wimvanderneut - yes, you can use the MCP7940 for interrupts. Check out the example example, Square Wave, to see see how a simple interrupt is used there. That can be adapted as you want.
from mcp7940.
Related Issues (20)
- Change comments & documentation to doxygen format HOT 2
- Observation about calibrate... HOT 3
- ppm out of range HOT 2
- Battery backup not working if power to micro-controller is cut HOT 3
- Cancel a setAlarm HOT 7
- ATmega328PB & MiniCore incompatible?? HOT 3
- How to obtain power failure date/hour HOT 1
- hello guys, HOT 17
- Change source code formatting to adhere to standards HOT 1
- Add a new example program for MCP7940N power fail HOT 1
- Optimize c++ code HOT 1
- Add a regression test example program HOT 1
- How can i get number of seconds since Epoch HOT 3
- DateTime(0) doesn't resolve correctly to the epoch HOT 5
- Question about int8_t MCP7940_Class::calibrate(const int8_t newTrim)... HOT 4
- Working with ESP chips HOT 4
- RPI2040 using Wire1 instead of Wire
- readRAM has wrong return type
- Wire.begin() is not called if ESP8266 is not defined
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 mcp7940.