Busca en nuestro Blog. Encontrarás múltiples aplicaciones, soluciones, ejemplos de código. Navega utilizando la nube de etiquetas o busca utilizando criterios específicos

Mduino RTC + SD storage


In this post we will teach you how to store the information that is provided by our RTC . 

These links will redirect you to our website where you can find how to program the Mduino RTC and also how to use the SD card. Is very important to have a look to those posts because what we will do is a fusion between the code of the RTC and SD.





In order to work with a micro SD, you must have one Mduino PLC  included in the next families:

Also we will need a micro SD card and a tweezers.

Checking switches

Before proceeding to connect the SD card to the industrial controller, we must check that the SD switch is correctly configured. We must check the communication switches and put the SD switch at OFF position (If your PLC has it) . Also we need to check that  RTC SCL and RTC SDA are set to ON mode to enable I2C wires to the RTC.


When we had programmed the RTC we were sending the information to the Serial Monitor, now we need to send it to the SD. First of all we need to include the libraries of RTC, SD and SPI.
Second step is to create the file where we will store the information. After that we create all the constants, set the bus that communicate the Arduino with the SD card and store all the constants in a new internal variables.

On the following step we open the file of the SD card and store all the information of each variable, the last step consists in close the file, because if you don't do this the storage will never stop.

#include <RTC.h>
#include <SD.h>
#include <SPI.h>

File myFile;

const int YEAR = 2020;
const int MONTH = 2;
const int DAY = 26;
const int HOUR = 12;
const int MINUTE = 20;
const int SECOND = 25;

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

void setup() {
  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() {
  myFile = SD.open("test.txt", FILE_WRITE);
  if (!RTC.read()) {
    Serial.println("Read date error: is time set?");
  } else {
    Serial.print("Time: ");
    Serial.print(" ");
    Serial.print(" (");

¿Quieres más información?

Con la tecnología Open Source, puedes ejecutar tus propias instalaciones.

Rellena el formulario y contactaremos contigo lo más pronto posible.

Enviar  Por favor, completa el formulario correctamente.