> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kode.diy/llms.txt
> Use this file to discover all available pages before exploring further.

# Reloj de tiempo real

> Lleva el control del tiempo en tus proyectos con los RTCs de tu Kode Dot. 

# Características

El Kode Dot integra **dos relojes de tiempo real**, el interno del ESP32-S3 y uno externo.

## Esquema de conexión

El reloj interno del ESP32-S3 se puede usar directamente usando la **documentación de Espressif.**

El reloj externo está conectado al I2C del ESP32-S3 usando estas conexiones:

| RTC externo | ESP32-S3 |
| ----------- | -------- |
| SDA         | GPIO48   |
| SCL         | GPIO47   |
| INTA        | EXP2     |
| INTB        | EXP1     |

<Tip>El reloj externo tiene la dirección 0xD0 en el bus I2C.</Tip>
<Note>Los pines de interrupción están conectados al [expansor de pines](/es/kode-dot/io-expander).</Note>

## Librerías recomendadas

### Arduino

* [kode\_MAX31329](https://github.com/kodediy/kode_MAX31329)

### ESP-IDF

* TBD

## Ejemplo de código

Este código configura el RTC con una fecha y hora específica y luego imprime la hora actual cada segundo.

```cpp rtc_test.ino lines icon="microchip" theme={null}
/**
 * Basic MAX31329 RTC time demo: sets initial time and continuously reads/displays current time.
 * Uses fluent API (rtc.t.year = 2024) for easy time configuration on ESP32-S3.
 * Prints formatted time every second to Serial monitor.
 */
/* ───────── KODE | docs.kode.diy ───────── */

#include <kode_MAX31329.h>
#include "Wire.h"

MAX31329 rtc;

/* Helper function to read and display current time from RTC */
static void printTime()
{
	/* Read time from RTC into rtc.t structure */
	if (!rtc.readTime()) {
		Serial.println("readTime failed");
		return;
	}
	
	/* Format and print time as YYYY-MM-DD HH:MM:SS */
	Serial.printf("%04d-%02d-%02d %02d:%02d:%02d\n", 
		rtc.t.year, rtc.t.month, rtc.t.day, 
		rtc.t.hour, rtc.t.minute, rtc.t.second);
}

void setup()
{
	Serial.begin(115200);
	Serial.println("MAX31329 Time example");
	
    Wire.begin(48,47);

	/* Initialize RTC */
	rtc.begin();

	/* Set initial time using fluent API - November 24, 2024 15:10:00 */
	rtc.t.year = 2024;
	rtc.t.month = 11;
	rtc.t.day = 24;
	rtc.t.hour = 15;
	rtc.t.minute = 10;
	rtc.t.second = 0;
	rtc.t.dayOfWeek = 0; /* 0=Sunday, 1=Monday, ..., 6=Saturday */
	
	/* Write configured time to RTC hardware */
	if (!rtc.writeTime()) {
		Serial.println("writeTime failed");
	}
}

void loop()
{
	delay(1000);    /* Wait 1 second between readings */
	printTime();    /* Display current time */
}
```

## Descarga de ejemplos

Puedes probar los códigos de ejemplo mediante el IDE de Arduino o el IDE de ESP-IDF o descargar los códigos en nuestro drive:

[Ejemplos del RTC](https://drive.google.com/drive/folders/1EHoXhwTg31xQmAzV5kKiH4j0Wmi5bjY9)
