Look for in our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

RTC test on M-Duino PLUS version

Introduction


In this post is showed how to test RTC (Real Time Clock) on M-Duino PLUS version.

Requirements


Ethernet PLC:           MDuino Family Products


Arduino RTC Library:    Arduino RTC Library


Software


* Remember that the RTC uses the I2C protocol for its communication (Check switches for correct operation) - Explanation on the help page.


//RTC library example
// by Industrial Shields

#include <RTC.h>

const int YEAR = 2018;
const int MONTH = 3;
const int DAY = 28;
const int HOUR = 13;
const int MINUTE = 24;
const int SECOND = 25;

//const int TIME = 1522242547;
//UNIX timestamp (spent seconds since Jan 1 1970 00:00:00)

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
  Serial.println("Configuring RTC: ");
  Serial.println();
  RTC.setYear(YEAR);                      //sets year
  RTC.setMonth(MONTH));                   //sets month
  RTC.setMonthDay(DAY);                   //sets day
  RTC.setHour(HOUR);                      //sets hour
  RTC.setMinute(MINUTE);                  //sets minute
  RTC.setSecond(SECOND);                  //sets second
  //RTC.setTime(TIME));                   //sets UNIX timestamp
  if(!RTC.write()){                       //RTC.write writes in the RTC memory all that has been set
    Serial.println("Write date error: Are the switches well placed?"));
  }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  if (!RTC.read()) {
    Serial.println("Read date error: is time set?");
  } else {
    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);
}

By following these steps carefully, you will be able to achieve the use of the RTC using the Industrial Shields equipments.


See also:  MDuino family - RTC help page

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.

Send