Skip to content

Modules and RTC clock

Modules connect to the ESP32’s I²C bus (SDA = GPIO21, SCL = GPIO22) and are declared in the controller’s expansion modules. The clock and the expanders are wired in parallel on these two lines, powered at 3.3 V.

Module Pins added Use Addresses
PCF8574 8 relays, float switches 0x20–0x27 (0x38–0x3F for a PCF8574A)
PCF8575 16 relays, float switches 0x20–0x27
PCA9685 16 PWM outputs light channels 0x40–0x4F recommended

PCF8574 and PCF8575 share the 0x20–0x27 range: each board needs its own address there.

They let you drive an 8- or 16-relay board with only two ESP32 pins.

Each module has an I²C address, set by its A0, A1 and A2 jumpers:

A2 A1 A0 PCF8574 PCF8574A
0 0 0 0x20 0x38
0 0 1 0x21 0x39
0 1 0 0x22 0x3A
0 1 1 0x23 0x3B
1 0 0 0x24 0x3C
1 0 1 0x25 0x3D
1 1 0 0x26 0x3E
1 1 1 0x27 0x3F

(0 = jumper to GND, 1 = to VCC.) Two modules on the same controller must have different addresses.

Each module gets a number on its controller (“Module 1”, “Module 2”…), which you can change at any time. It’s what the pin picker shows: “Module 2 · pin 5”. Number your modules the way they sit in the enclosure.

The Scan the I²C bus button (Scanner le bus I²C) in the expansion modules lists the addresses the controller sees: declared modules, the clock, the clock’s memory, and undeclared modules (Declare button). It also flags a module that is declared but missing from the bus (wiring or jumpers). The controller’s firmware must already include the I²C bus: declare the clock or a module, flash, then scan. The controller only scans at start-up: after plugging or unplugging a module, use Restart and scan (Redémarrer et scanner), which restarts the controller and scans again once it’s back.

I²C is meant for a short cable (1 to 2 m). To place modules further away:

  • lower the bus frequency in the expansion modules (10 kHz beyond 5 m), then flash;
  • on network cable, put SDA with a ground in one pair and SCL with another ground in another pair;
  • add 2.2 kΩ pull-up resistors to 3.3 V on SDA and SCL, on the ESP32 side;
  • beyond that, use an I²C extender (P82B715, PCA9615);
  • with an extender, power the far end locally (3.3 V) rather than through the cable: too low a voltage at the end of the cable makes the modules fail to start (controller log: Setting up PCA9685 failed!, outputs left floating).

The PCA9685 adds 16 PWM outputs: in a light channel’s pin picker, its channels join the ESP32 GPIOs. It only delivers a signal: connect it to PWM-input LED drivers (or MOSFETs). The module has a single PWM frequency, the one of the lights wired to it (up to 1525 Hz). Avoid addresses 0x68 (clock) and 0x70 (PCA9685 shared address, visible in the scan).

A battery-backed clock keeps time even without a network or server. It’s required for time-based rules and lighting schedules.

Supported models:

  • DS3231 (recommended, very accurate);
  • DS1307;
  • PCF8563;
  • PCF85063.

No address to enter: it’s fixed by the chip (0x68 for DS3231 and DS1307, 0x51 for PCF8563 and PCF85063). Many DS3231 modules also carry a small memory at 0x57: it shows up in the scan, there’s nothing to declare.

At startup, the ESP reads the time from the clock. As soon as it reaches the network, it syncs with Internet time (NTP) and sets the clock right.