Using the DS3231 Real Time Clock from MicroPython

If you ever have a need to connect a DS3231 Real Time Clock device to an ESP32 running MicroPython then I have just the blog post for you.

All you have to do is download the driver from here:

https://github.com/adafruit/Adafruit-uRTC

I then used Thonny to copy the driver file onto my MicroPython device and then I could use it in my program.

Don’t use the one from upip (which is usually a neat way to install libraries onto your MicroPython devices) because it is at version 1.0 which contains some statements that don’t compile. Once you’ve got this running you can now create MicroPython powered devices that can keep track of time.

Note that if you are using one of the DOIT ESP32 boards (these are very cheap and easy to get hold of) you will need to use pins 22 and 21 for the I2C interface:

i2c = I2C(-1, scl=Pin(22), sda=Pin(21))