Get and Set time with DS3231 Plus set Alarm

One more small success.
I found this code to scan the I2C bus for devices.
However you need to know what GPIO pins the device uses.
The Core Electronics page says to use Pin 9 and 10 GPIO 6 SDA and GPIO 7 SCL where the Wave Share Wiki says to use SDA 20 and SCL 21
Turns out Waveshare is correct.
This bus scan code correctly finds the device.
Link Here

import machine
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

print('Scan i2c bus...')
devices = i2c.scan()

if len(devices) == 0:
    print("No i2c device !")
    print('i2c devices found:',len(devices))

    for device in devices:
       print("Decimal address: ",device," | Hexa address: ",hex(device))


Scan i2c bus...
i2c devices found: 1
Decimal address:  104  | Hexa address:  0x68

Hi David,

Thanks for pointing out the error on our product page. It looks like there may have been a new revision and we still have up an old image.

We will have a look into it.

1 Like

Hi Aaron,
That message is a long way down the thread. I wasn’t really expecting you guys to spot it. Well done. As it turned out I was using the settings (mostly) from Waveshare. But they have way too much fluff on their page.:cowboy_hat_face:

Here is my work in progress in case someone else wants to take up where I left off. The routines to set the pico from the DS3231 and to set the DS3231 from the pico are working fine, just include the code and if the pico time is correct set the DS3231 time once. From then on each time the pico starts up set the time from the DS3231.
Have a look at the examples in the “main” section at the bottom. I added a routine to list all the device settings to the screen in binary but didn’t get very far figuring out if something was obviously wrong that was stopping the alarm from waking up the pico. (3.1 KB)