Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 01 16:35
    Makuna updated the wiki
  • Jul 01 16:29
    Makuna closed #125
  • Jul 01 16:29
    Makuna labeled #125
  • Jul 01 10:47
    pilnikov edited #125
  • Jul 01 10:47
    pilnikov edited #125
  • Jul 01 10:43
    pilnikov edited #125
  • Jul 01 10:26
    pilnikov opened #125
  • May 28 02:30
    brewmanz edited #124
  • May 28 02:29
    brewmanz opened #124
  • Apr 06 22:03
    seamusdemora opened #123
  • Jan 20 22:57
    hofben updated the wiki
  • Jan 05 18:24
    Makuna closed #122
  • Jan 05 13:22
    coreydaley opened #122
  • Sep 29 2020 21:20
    Makuna unlabeled #110
  • Sep 29 2020 21:20
    Makuna closed #110
  • Sep 29 2020 21:15

    Makuna on master

    enable travis build using platf… (compare)

  • Sep 29 2020 21:15
    Makuna closed #116
  • Sep 23 2020 20:22
    Makuna closed #120
  • Sep 23 2020 20:22
    Makuna updated the wiki
  • Sep 23 2020 20:13
    Makuna updated the wiki
Michael Miller
@Makuna
What do you mean 100ms accuracy? That time is accurate to within 100ms at the end of the day/week or you need time values that contain less than a second readings. If this is an assignment, unfortunately I outlined the answer for you, part of learning is researching and LEARNING.
And yes, the DS3231 can be configured to trigger the sqaurewave at 1hz.
traptw1thin
@traptw1thin
I need time stamp values that contain less than second readings. I realize I need to research stuff and learn it, that's why I'm asking questions.
Nothing that I have found online yet has given me a clue how to actually do the ISR thing.
Michael Miller
@Makuna
Do you know what ISR stands for? There are plenty examples around and but I doubt something exactly to your problem.
traptw1thin
@traptw1thin
So far I have this laid out...hopefully I get the code formatting right for this:

int sqwPin = 2;
bool flag = false;

void setup() {
// bunch of setup stuff.....
// ..........
//........
    // never assume the Rtc was last configured by you, so
    // just clear them to your needed state
    Rtc.Enable32kHzPin(false);
    pinMode(sqwPin, INPUT_PULLUP);
    Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); 
    Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
    int secondInterrupt = digitalPinToInterrupt(sqwPin);
    attachInterrupt(secondInterrupt, rtc_interrupt, RISING);
}
void loop() {
// currently the loop just gets the time and prints it to serial, 
// it does not do anything with the interrupt yet. 
// That's what I'm unsure of....assuming the rest of this works. 
}
void rtc_interrupt(void)
{
    flag = true;
}
I guess I don't know how to use the backticks for this platform? figured it out
ok, adding more to above code snippet as I accidentally hit normal enter, so that's not all I have hold on ok, that's all I have
traptw1thin
@traptw1thin
I can't test the interrupt right now because my DS3231 doesn't have a pin for SQW so I need to go to a real soldering station and connect to pin 3 with a soldered connection.

But, if the code to setup the interrupt works and actually causes a 1 Hz signal on the SQW pin of the DS3231, and causes the Mega2560 to react to the interrupt...What I don't know is what to do with the interrupt once it's setup.

To answer your question, no I don't know what ISR stands for but I found plenty of stuff online talking about how to do it which is how I put together the code I put above. I assume the I is interrupt, but I couldn't find what the acronym actually stood for.

traptw1thin
@traptw1thin
and the void rtc_interrupt(void) came from a post I found but what they do in response to flag being set is just make an LED flash on and off and I know that's not what I want to do. I'm guessing something to do with counting the millis() since calling GetDateTime()? but not sure the most accurate way to do that or if that's even a correct assumption.
Ok, finally found ISR (Interrupt Service Routine) so yes I know what it is, just didn't know the name and don't have very much experience with it. I have only used one once before
bobcroft
@bobcroft
@traptw1thin just do a Google search on 'using interrupts on Arduino' there will be lots of examples on using interrupts, ISR's etc. Michael has virtually provided the answer you seek. Write some practice code to understand interrupts and then apply that to your assignment.
traptw1thin
@traptw1thin
Yes, that's how I got the code I came up with above, but I don't know what he meant by tracking the ms in the code
Michael Miller
@Makuna
@traptw1thin You already mentioned the solution, but you don't realize it. Look at the millis() arduino API.
kokyuen
@kokyuen
Hi, with DS3231, how to get alarm time settings? so we retrieve and show the next alarm time. Thanks.
Michael Miller
@Makuna
@kokyuen The sample/example DS3231_Alarms demonstrates the use of setting the two alarms and using interrupt to monitor the alarm trigger. Just call Rtc.GetAlarmOne() or Rtc.GetAlarmTwo() to retrieve the alarm information. You can poll for the alarm instead of using an interrupt by calling the Rtc.LatchAlarmsTriggeredFlags() but doing this often means keeping the RTC is a high power state.
        // this gives us which alarms triggered and
        // then allows for others to trigger again
        DS3231AlarmFlag flag = Rtc.LatchAlarmsTriggeredFlags();

        if (flag & DS3231AlarmFlag_Alarm1)
        {
            Serial.println("alarm one triggered");
        }
        if (flag & DS3231AlarmFlag_Alarm2)
        {
            Serial.println("alarm two triggered");
        }
kokyuen
@kokyuen
@Makuna Thanks for the help, explanation and suggestions. I will implement these codes, thanks again.
kokyuen
@kokyuen
@Makuna What is return from Rtc.GetAlarmOne() or Rtc.GetAlarmTwo()? I am trying to Serial or lcd print the hour, minute and second information from Alarm 1 and the hour and minute information from Alarm 2. Kindly advise, thanks.
Michael Miller
@Makuna
@kokyuen The Wiki is your friend
kokyuen
@kokyuen
Thanks for the link. I will check it up.
JohnBelding
@JohnBelding
I am testing your DS3231 library on my ESP8266 and it is working as intended. I have hooked the SQW pin up to the D4 (GPIO2) and both alarms are working. I would like to determine what the alarms are set at and have used your Rtc.GetAlarmOne() but haven't figured out how to print the result to the serial monitor. I don't see any syntax for printing and have looked at the Wiki info. I would appreciate it if you could provide the two lines of code for getting the Alarm info and printing it out. In addition, I have been attempting to use deepsleep(0) on the ESP8266 and have that working, but can't figure how to wire it to use the DS3231 alarms to reset the chip. I was also looking for a way to clear the alarms, but can't find it. Your help would be appreciated. John B.
Michael Miller
@Makuna
@JohnBelding The Wiki for DS3231 is the best place to start.
The DS3231AlarmOne and DS3231AlarmTwo are two classes returned by the GetAlarmOne() and GetAlarmTwo(). They both expose methods to access the values and flags from the alarms.
Michael Miller
@Makuna
I don't know a means to "clear" an alarm once it set. But note that the ouput squarewave pin can be disabled see SetSquareWavePin
Michael Miller
@Makuna
Also note, that once an alarm has fired, it will not fire again until the LatchAlarmsTriggeredFlags is called.
It seems like they could be disabled but its not documented specifically to work this way and I haven't exposed it.
JohnBelding
@JohnBelding
Thanks for the responses. In your DS3231_Alarm example I think the bool Alarmed() code resets the alarm since my alarms continue to fire. You do call the LatchAlarmsTriggeredFlags in that function. I looked at the "access the values and flags" and still can't figure out how to print the retrieved alarm info. What I mean by "clearing" the alarms can be handled by the SetSquareWavePin (set to None) routine since I really just want to turn the alarms off. Any help on waking up the ESP8266 from ESP.deepsleep(0) with the DS3231 SQW output? Thanks again, John B.
Michael Miller
@Makuna
How are you trying to print them out now?
Waking the Esp8266 is a detail I am not an expert on; I would suggest asking this the esp8266/arduino gitter channel.
JohnBelding
@JohnBelding
I use this code: DS3231AlarmOne alarm1 = Rtc.GetAlarmOne();
printDateTime(alarm1);
but get a compile error. I was really hoping you could help with the deepsleep problem, but will go to the gitter channel. I have literally spent days trying to get an answer off the web, but I'll keep looking. It just seems like a problem that would have been solved years ago. Thanks for your help, John B.
Michael Miller
@Makuna
I am unsure why you would think printDateTime would take a DS3231AlarmOne class when it takes an RtcDateTime class. They are not the same; even the alarm one and alarm two classes are not the same.
Look inside the printDataTIme function and see what it does, and mimic it using the methods exposed off the alarm classes.
JohnBelding
@JohnBelding
I just don't know enough about the code to do it correctly. Looked on gitter and still no joy about deepsleep. John B.
DARINEL RUIZ
@DarinelRuizA_twitter
Can anybody help me!?
I USE THE CODE OF DS1302_simple, but I get the following error:
10:40:55.633 -> RTC lost confidence in the DateTime!
10:40:55.734 -> 00/00/2000 00:00:00
10:40:55.734 -> RTC lost confidence in the DateTime!
10:40:55.834 -> 00/00/2000 00:00:00
10:40:55.834 -> RTC lost confidence in the DateTime!
10:40:55.935 -> 00/00/2000 00:00:00
10:40:55.935 -> RTC lost confidence in the DateTime!
hel me, please!
Michael Miller
@Makuna
@DarinelRuizA_twitter This is usually a connection problem. Make sure the correct pins are connected to the module in the right way. Also, make sure the GND is connected between them.
Also, make sure you actually have a DS2302 ;-)
Alex Pilnikov
@pilnikov

I am trying to do this
static RtcDS1302<ThreeWire> ds1302;
static ThreeWire
myTWire;

define dio 9

define clk 10

define cs 11

void setup
{
myTWire = new ThreeWire(dio, clk, cs); // IO, SCLK, CE
ds1302 = new RtcDS1302<ThreeWire> (myTWire);
}

And I get the following ...............

In file included from Z:\ardu\sketch\Test\test_ds1302\test_ds1302.ino:1:0:
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h: In member function 'RtcDateTime RtcDS1302<T_WIRE_METHOD>::GetDateTime()':
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h:173:61: error: 'THREEWIRE_READFLAG' was not declared in this scope
_wire.beginTransmission(DS1302_REG_TIMEDATE_BURST | THREEWIRE_READFLAG);
^~~~~~
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h: In member function 'uint8_t RtcDS1302<T_WIRE_METHOD>::GetMemory(uint8_t, uint8_t)':
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h:238:56: error: 'THREEWIRE_READFLAG' was not declared in this scope
_wire.beginTransmission(DS1302_REG_RAM_BURST | THREEWIRE_READFLAG);
^~~~~~
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h: In member function 'uint8_t RtcDS1302<T_WIRE_METHOD>::getReg(uint8_t)':
Z:\ardu\sketch\libraries\Rtc_by_Makuna\src/RtcDS1302.h:258:46: error: 'THREEWIRE_READFLAG' was not declared in this scope
_wire.beginTransmission(regAddress | THREEWIRE_READFLAG);
^~~~~~
Z:\ardu\sketch\Test\test_ds1302\test_ds1302.ino: At global scope:
test_ds1302:4:18: error: 'ThreeWire' was not declared in this scope
static RtcDS1302
ds1302;
^~~
test_ds1302:4:27: error: template argument 1 is invalid
static RtcDS1302 ds1302;
^
test_ds1302:5:8: error: 'ThreeWire' does not name a type
static ThreeWire
myTWire;
^
~~
Z:\ardu\sketch\Test\test_ds1302\test_ds1302.ino: In function 'void setup()':
test_ds1302:9:1: error: 'myTWire' was not declared in this scope
myTWire = new ThreeWire(9, 10, 11); // IO, SCLK, CE
^~~
test_ds1302:9:15: error: expected type-specifier before 'ThreeWire'
myTWire = new ThreeWire(9, 10, 11); // IO, SCLK, CE
^~~
test_ds1302:10:24: error: 'ThreeWire' was not declared in this scope
ds1302 = new RtcDS1302 (myTWire);
^
~~
test_ds1302:10:33: error: template argument 1 is invalid
ds1302 = new RtcDS1302 (myTWire);
^
Using library Rtc_by_Makuna version 2.3.5 from: Z:\ardu\sketch\libraries\Rtc_by_Makuna
exit status 1
'ThreeWire' was not declared in this scope

//------------------------------------------------------------------------------------------
How to properly initialize the Threewire object using the "new" operator ??
Best regards, Alex :)

moved from github
Michael Miller
@Makuna
@pilnikov Please wrap code in the markup for code, standalone line at the top and bottom with three single left quotes. There is a button in the lower right of this pane -> here that describes markup.

RtcDS1302 is a template class. At the top of your code you define the global correctly but not as a dynamic variable.

static RtcDS1302<ThreeWire> ds1302; // not dynamic, instanced already
static RtcDS1302<ThreeWire>* pDs1302; // dynamic, must call new to allocate an instance

The type of ds1302 is RtcDS1302<ThreeWire>
Where the error happens, your are not creating a RtcDS1302<ThreeWire>, you are asking it to create just a RtcDS1302.

Michael Miller
@Makuna
pDs1302 = new RtcDS1302<ThreeWire>( myTWire );
You have issues with your dynamic variables (pointers) and I suggest go read up on them.
In your given case, not sure why you are using new and instead just follow the pattern from the examples and make them all globals.
Alex Pilnikov
@pilnikov
I am trying to make a device where the GPIO can be set by the user, so the GPIO for ThreeWire cannot be statically declared.
Lestro
@PJLC
Is there a way to get directly minutes into a byte variable?
Michael Miller
@Makuna
From every example they demonstrate how to access and print the minutes.
byte minutes = dt.Minute(); // returns the minutes from the date time
Lestro
@PJLC
@Makuna Thank you for your reply.
I did red and ran the examples before asking and also I did try that and of course it worked, but the thing is that it only works if I retrieve the time variable inside the function as in your examples but I couldn't get it from other function.
I'm trying to get the separated hours, minutes, etc. to do time calculation operations.
Is it possible to do something like: tmin = Rtc.GetDateTime(minute()); ?
Michael Miller
@Makuna
Not sure why you want to do that. Rtc.GetDateTime() returns the date and time object (see wiki here). That returned object contains the minutes along with hours and all the other time related numbers. It exposes the ability to do increment time by seconds already.
You can't just get the hours from the RTC through my API.
Michael Miller
@Makuna
You need to remember that time continues to pass, you get a snapshot of time by calling GetDateTime(), if you called the RTC to get individual elements, then you could get unrelated time values. Consider that at 2:59:59 you called get minutes, it would return 59, but then you called get hours, it could return 3 if you were slow.