Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

How to configure RTC in the included example?

By
Amir
on 8/4/20, 12:49 PM 81 views

I can't find any documentation on how to use the RTC.h Library.

I am trying to use the RTC Library Example that is included when M-Duino board family is added.


This is my code:

// RTC library example

// by Industrial Shields


#include <RTC.h>

byte seconds = 0;

byte minutes = 50;

byte hours = 12;


/* Change these values to set the current initial date */

byte day = 4;

byte month = 8;

byte year = 20;


////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {

  Serial.begin(9600L);


  RTC.setHour(hours);

  RTC.setMinute(minutes);

  RTC.setSecond(seconds);

  // Set the date

  RTC.setMonthDay(day);

  RTC.setMonth(month);

  RTC.setYear(year);

}


////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

 // if (!RTC.read()) {

 //   Serial.println("Read date error: is time set?");

 // } else {

 RTC.read();

    Serial.print("Time: ");

    Serial.print(RTC.getYear());

    Serial.print("-");

    Serial.print(RTC.getMonth());

    Serial.print("-");

    Serial.print(RTC.getMonthDay());

    Serial.print(" ");

    Serial.print(RTC.getHour());

    Serial.print(":");

    Serial.print(RTC.getMinute());

    Serial.print(":");

    Serial.print(RTC.getSecond());

    Serial.print(" (");

    Serial.print(RTC.getTime());

    Serial.println(")");

  


  delay(1000);

}


1
Industrial Shields Forum user

Albert Prieto

--Albert Prieto--

1000000029
| 0 0 0
España
--Albert Prieto--
Albert Prieto
On 8/10/20, 10:39 AM

Hi Amir, have you configured the switch on the M-Duino PLC? see an example of use on the link below:

https://www.industrialshields.com/technical-features-industrial-m-duino-plc-arduino-ethernet-57aar-ios-analog-digital-relay-plus#specialt





0
Amir
On 8/10/20, 11:08 AM

Yes, the switches were set to RTC.

The link you provided still does not show how to set the time. Just how to read it.



I ended up using a different library and a different example code to set up the RTC.

If anyone reading this in the future is trying to accomplish the same thing, heres what I did:

Install the Grove - RTC DS1307 Library by Seeed Studio. In my case I used Version 1.0.0. 

Use the example provided by that library, called "SetTimeAndDisplay", change the date and time to the current date, and upload the sketch.

Once the RTC is set, as long as the RTC battery is not removed, you wont have to set it again. you can either continue to use the Grove - RTC DS1307 library, or switch to use the one provided by Industrial Shields.

 



Keep Informed

About This Community

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together. Read Guidelines

Question tools

12 follower(s)

Stats

Asked: 8/4/20, 12:49 PM
Seen: 81 times
Last updated: 8/10/20, 11:08 AM