GithubHelp home page GithubHelp logo

seeed-studio / seeed_arduino_rtc Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 7.0 44 KB

When your project needs to be unplugged, how to keep the time counting? This library can help you set up the current time.

License: MIT License

C++ 100.00%
rtc grove grovelibrary ds1307

seeed_arduino_rtc's Introduction

Seeed_Arduino_RTC Build Status

Introduction

Seeed Arduino RTC is a Arduino library for RTC Moudle. At present, samd21 is supported and samd51 has built-in RTC module.

How to install Arduino Library

please refer here.

Usage

#include "RTC_SAMD21.h"
#include "DateTime.h"

RTC_SAMD21 rtc;
void setup()
{
    rtc.begin();

    Serial.begin(115200);

    while (!Serial)
    {
        ;
    }
    
    DateTime now = DateTime(F(__DATE__), F(__TIME__));
    Serial.println("adjust time!");
    rtc.adjust(now);

    now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

}
void loop()
{
    now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

}

API Reference

  • begin(void) : bool
rtc.begin()
  • now(void) : DateTime
DateTime now = rtc.now();
  • adjust(const DateTime) : void
DateTime now = DateTime(F(__DATE__), F(__TIME__));
rtc.adjust(now);
DateTime now = DateTime(2020, 7, 15, 0, 0, 0);
rtc.adjust(now);
  • setAlarm(const DateTime) : void
DateTime alarm = DateTime(2020, 7, 15, 18, 0, 0);
rtc.setAlarm(now);
  • alarm(void) : DateTime
DateTime now = rtc.alarm();
  • disableAlarm(uint8_t) : void
rtc.disableAlarm(0);
  • enableAlarm(uint8_t) : void
rtc.enableAlarm(0);
  • attachInterrupt(rtcCallBack) : void
rtc.attachInterrupt(rtcCallBack);
  • detachInterrupt(void) : void
rtc.detachInterrupt();

License

This software is written by seeed studio
and is licensed under The MIT License. Check License.txt for more information.

Contributing to this software is warmly welcomed. You can do this basically by
forking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.

Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.

seeed_arduino_rtc's People

Contributors

bmcdonnell avatar ciniml avatar jiacheng-lu avatar lakshanthad avatar lynnl4 avatar pillar1989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

seeed_arduino_rtc's Issues

how about adding functions that return the time in the usual formats?

Hi Seeeduino-Team,

I'm thankful that you coded a software RTC for SAMD21 in general.

But I want to post a feature requenst:
How about adding some functions or at least demo-codes that show how to the time-information is transformed into the usual formats like unix-time, epoc etc.?

Seeeduino is a microcontroller-board manufacturer. Providing good support for your boards IMHO seems to be a good investion. If I'm allowed to write an honest comment:

Seeeduino has very good tutorials that show all steps with screenshots etc.
With this library the quality level dropped towards the low end: a minimum of examples and that's all.
best regards Stefan

Why is year limited to 2099?

Please consider either removing the limitation, or explaining the reason for it in the code comments.

If it is a hardware limitation, you might even consider changing the DateTime class to work with the actual year, and making the limitation part of the RTC classes. That would make DateTime more broadly useful.

[Adafruit Matrix Portal][SAMD51] Doesn't Keep Time correctly

Using a SAMD51 board (Matrix Portal from Adafruit) I am using this library to keep time but it somehow seems to be counting time faster than expected,
Steps to reproduce:
Sync Time from NTP
Set the time in the RTC by using adjust time Function,
Set a minute alarm and update the RGB matrix every minute as a part of the interrupt.

Does everything correctly but after keeping the clock running overnight it gets ahead of the actual time by ~10 mins

You can check my code here

I assume something is reusing the timers which are used by RTC which makes them faster? not sure where the issue is.....

__SAMD21__ guard

I'm using v2.0.0 of the library on a MKR WAN 1310. I couldn't compile a sketch (including the example) until I commented out the guard lines lines :
#ifdef __SAMD21__
in both the header files and the cpp files.

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.