Introducción
En este post aprenderás a probar el RTC (Reloj en Tiempo Real) en el controlador industrial M-Duino PLUS versión Arduino.
Software
Recuerda que el RTC utiliza el protocolo I2C para su comunicación (Comprueba el correcto funcionamiento de los interruptores) - Explicación en el página de ayuda.
//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);
}Sigue cuidadosamente estos pasos y podrás utilizar el RTC en equipos de Industrial Shields (controladores lógicos programables y Panel PCs).
