Real Time Clock - VIPnytt/Frekvens GitHub Wiki

ā° Real-Time Clock

A Real-Time Clock (RTC) module keeps accurate time, even without internet access.

Most common RTC modules with I²C will work. Good starting points include the DS3231 (e.g. this) and the DS1307 (e.g. this).

āœ… Supported types

šŸ“Œ Schematics

DS1307 schema

ā”Œā”€ā”€ā”€ā”€ā”€ā”
│ VCC ā”œā”€ +5 V DC
│ GND ā”œā”€ 0 V DC
|     |
│ SCL ā”œā”€ I²C SCL
│ SDA ā”œā”€ I²C SDA
ā””ā”€ā”€ā”€ā”€ā”€ā”˜

DS3231 schema

ā”Œā”€ā”€ā”€ā”€ā”€ā”
│ VCC ā”œā”€ +3.3 V DC
│ GND ā”œā”€ 0 V DC
|     |
│ SCL ā”œā”€ I²C SCL
│ SDA ā”œā”€ I²C SDA
|     |
│ INT ā”œā”€ RTC INT
ā””ā”€ā”€ā”€ā”€ā”€ā”˜

DS3232 schema

ā”Œā”€ā”€ā”€ā”€ā”€ā”
│ VCC ā”œā”€ +3.3 V DC
│ GND ā”œā”€ 0 V DC
|     |
│ SCL ā”œā”€ I²C SCL
│ SDA ā”œā”€ I²C SDA
|     |
│ INT ā”œā”€ RTC INT
ā””ā”€ā”€ā”€ā”€ā”€ā”˜

PCF8563 schema

ā”Œā”€ā”€ā”€ā”€ā”€ā”
│ VCC ā”œā”€ +3.3 V DC
│ GND ā”œā”€ 0 V DC
|     |
│ SCL ā”œā”€ I²C SCL
│ SDA ā”œā”€ I²C SDA
|     |
│ INT ā”œā”€ RTC INT
ā””ā”€ā”€ā”€ā”€ā”€ā”˜

ESP32 schema

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│           VIN ā”œā”€ +5 V DC
│           3V3 ā”œā”€ +3.3 V DC
│           GND ā”œā”€ 0 V DC
│               │
│           SCL ā”œā”€ I²C SCL
│           SDA ā”œā”€ I²C SDA
│               │
│ Digital input ā”œā”€ RTC INT
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Logic level shifter schema

   0 V DC ────────┬──────── 0 V DC
+3.3 V DC ────┐   │   ā”Œā”€ā”€ā”€ā”€ +5 V DC
           ā”Œā”€ā”€ā”“ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”“ā”€ā”€ā”
           │ VCC GND VCC │
 I²C SCL  ─┤ A1  ──►  B1 ā”œā”€ I²C SCL
 I²C SDA  ─┤ A2  ◄─►  B2 ā”œā”€ I²C SDA
 RTC INT  ─┤ A3  ◄──  B3 ā”œā”€ RTC INT
           ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

ā†”ļø Logic level shifter

Most RTC modules are 3.3 V compatible, but some variants use higher logic levels (e.g. 5 V). In those cases, a logic level shifter is required to ensure safe communication with the ESP32. Make sure it is suited for I²C signals, like TXS0104E (e.g. this).

šŸ”§ Configuration

I²C SCL

Serial clock for I²C communication.

Any I²C SCL pin can be used.

Configure in secrets.h:

#define PIN_SCL 1 // I²C SCL

I²C SDA

Bidirectional data line for I²C.

Any I²C SDA pin can be used.

Configure in secrets.h:

#define PIN_SDA 2 // I²C SDA

RTC INT

Interrupt signal from the RTC module.

Optional to connect.

Any digital input pin that are also RTC-capable can be used.

Configure in secrets.h:

#define PIN_INT 3 // RTC INT

🧩 Extension

Using the RTC extension, the clock will automatically sync during during startup.

Check out the RTC extension for more info.

šŸ“ Templates

DS1307

Configure in secrets.h:

#define RTC_DS1307

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA

[!IMPORTANT] Logic level shifter required.

[!WARNING] Incompatible with IKEA Frekvens due to the lack of a 5 V power supply.

DS3231

Configure in secrets.h:

#define RTC_DS3231

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

DS3232

Configure in secrets.h:

#define RTC_DS3232

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

PCF8563

Configure in secrets.h:

#define RTC_PCF8563

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

šŸ”— Resources

External links for deeper exploration — provided for reference only and with no formal connection to this project.