Forum Controladores/PLC

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?

Avatar
Amir

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);

}

Avatar
Descartar
3 Respuestas
1
Avatar
Albert Prieto
Best Answer

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



Avatar
Descartar
0
Best Answer

Thank you Amir. It is very useful for me.

Avatar
Descartar
0
Avatar
Amir
Best Answer

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.

 


Avatar
Descartar