Skip to content
Discussion options

You must be logged in to vote

Is it this library you're using? balance19/micropython_DS3231: A library to run the DS3231 RTC on Raspberry Pi Pico

That's a really odd way to go about setting the clock. Looks like the library is expecting binary coded decimal.

A couple of routines like this might help:

def bcd(n):
    n = n % 100
    return 16 * (n // 10) + n % 10

def date_to_bytes(sec, minutes, hour, week, day, month, year):
    # week is week of the year, seemingly
    return bytes(
        [bcd(sec), bcd(minutes), bcd(hour), bcd(week),
         bcd(day), bcd(month), bcd(year)]
    )

# example 2022-11-07 21:25:00 (in week 45)
print(date_to_bytes(0, 25, 21, 45, 7, 11, 22))

This returns b'\x00%!E\x07\x11"', which is a…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@PhilTIlson
Comment options

Answer selected by PhilTIlson
Comment options

You must be logged in to vote
2 replies
@scruss
Comment options

@peterhinch
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants