RTC test on M-Duino PLUS version

Industrial automation with industrial PLC controller
December 10, 2018 by
RTC test on M-Duino PLUS version
Alejandro Jabalquinto

Introduction

In this post, you will learn how to test RTC (Real Time Clock) on M-Duino PLUS industrial controller Arduino version.

See products >>

Requirements

  • Ethernet PLC Arduino - M-Duino Family Products   See >>

  • Arduino RTC Library  See >>

Software

Remember that the RTC uses the I2C protocol for its communication (Check switches for correct operation)

//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 Industrial Shields equipment (programmable logic controllers and Panel PCs).

Search in our Blog

RTC test on M-Duino PLUS version
Alejandro Jabalquinto December 10, 2018
Share this post
Archive

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>