Approved content

The content below is provided by a partner.

keble6/pxt-DS3231 1.0.1 GitHub

DS3231-extension

This extension supports the DS3231 (see product page) and provides several functions for setting and reading:

NOTE: The DS3231 chip allows alarm 1 to have seconds set, in addition to minutes, hours etc. This extension does NOT (yet) provide for that. In other words, both alarms can have minutes, hours etc set ONLY.

Also, functions are provided for handling the alarms:

Supported targets

More on the functions

Example code

Set an alarm:

DS3231.setAlarm(alarmNum.A1,mode.Minute,0,0,alarmHour,alarmMinute)

Record (over USB) a temperature measurement:

serial.writeLine("Temperature: " + TwosCompToDec(DS3231.temperatureUpper()) + "." + Math.floor(DS3231.temperatureLower() / 64) * 25)

The DS3231 RTC board

This is assumed to have an i2c address of 0x68.

I used this one. It has a holder for a button cell for battery backup.

How to use the interrupt

You can set one or both alarms in several different modes. To avoid having to poll the RTC to detect an alarm you would normally:

Testing

I connected the 3V, GND, SCL and SCK pins to the corresponding microbit pins. The DS3231 board’s interrupt (SQW) pin was connected to the microbit’s P0 pin. The photos below show the board and the microbit.

test.ts

Set time and alarm registers in “all” bit combinations, read back and verify

functional.ts

Functional tests - read temperature, then set and wait for alarms. Clear interrupts.

DS3231=github:keble6/pxt-DS3231#v1.0.1