Simple connect liteboard -> rs3231 rtc module

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
wrightkevin
Posts: 2
Joined: Sat Jul 24, 2021 10:18 am

Simple connect liteboard -> rs3231 rtc module

Post by wrightkevin » Sat Jul 24, 2021 10:40 am

Hi,

I am trying to connect a MicroPython Lite board to a ds3231 rtc module.

So far I have performed the following steps:
wire connections from the pyboard lite.

x9 -> scl on the module
x10 -> sda on the module
vcc -> vcc on the module
ground -> ground on the module.

Here is my python code:

Code: Select all

import machine
import ssd1306
from utime import sleep
import utime

from machine import RTC

rtc = RTC()
rtc.datetime((2005, 7, 23, 1, 12, 48, 0, 0)) # set a specific date and time


print(rtc.datetime()) # get date and time



oled = ssd1306.SSD1306_I2C(128,64, machine.I2C(1))

while True:
    oled.fill(0)
   
    dta = rtc.datetime()
    
    oled.text( str(dta), 0, 20)
    
    oled.text( str(dta[2]) + ':' + str(dta[3]) + ':' + str(dta[4]) + ':' + str(dta[5]) \
               + ':' + str(dta[6])
               , 0, 30)



    
    oled.show()
    sleep(5) 
  
Suffice to say it doesn't work. It just loses the current date/time when removed from power. The ds3231 module has a battery connected and the module does light up. I note that there is no mention of the i2c connection details in the code and suspect this might be relevant.

Please advise.

Kevin Wright

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Simple connect liteboard -> rs3231 rtc module

Post by pythoncoder » Sat Jul 24, 2021 1:24 pm

You might want to look at this doc.
Peter Hinch
Index to my micropython libraries.

wrightkevin
Posts: 2
Joined: Sat Jul 24, 2021 10:18 am

Re: Simple connect liteboard -> rs3231 rtc module

Post by wrightkevin » Sat Jul 24, 2021 3:56 pm

Hi Peter,

Thank you very much for that.
When I run the calibrate function, I get:

Pyboard 1.x. Waiting 5 minutes for calibration factor.
Error 26066.3ppm 49604.1mins/year. Cal factor -27323

But I thought I'd press on anyway. When I use your librarys get_time function, that time does seem to survive a power reset. So I guess that gives me what I need. I'm still trying to get my head round should I be reading from the RTC object or just use your class. Anyway, I think I'm good for now.

Thanks again,

Kevin

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Simple connect liteboard -> rs3231 rtc module

Post by pythoncoder » Tue Jul 27, 2021 3:23 pm

The Pyboard Lite does not have a crystal oscillator for the RTC so those error values are to be expected. A Pyboard 1.1 or D with a crystal oscillator can be calibrated to timepiece precision.
Peter Hinch
Index to my micropython libraries.

Post Reply