In compliance with high industry standards

Browse 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

Industrial automation with industrial PLC controller

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

Odoo text and image block

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


See also:  MDuino family - RTC help page

Looking for your ideal PLC?

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

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


Industrial PLC controller comparison >>

Do you want more information?

Just fill the form!

Tell me more!