kopia lustrzana https://github.com/peterhinch/micropython-samples
Minor changes to portable DS3231.
rodzic
618a181fc4
commit
1e1b2a23ed
|
@ -1,9 +1,8 @@
|
|||
# Portable driver for DS3231 precison real time clock.
|
||||
# ds3231_port.py Portable driver for DS3231 precison real time clock.
|
||||
# Adapted from WiPy driver at https://github.com/scudderfish/uDS3231
|
||||
# Includes routine to calibrate the Pyboard's RTC from the DS3231
|
||||
# delta method now operates to 1mS precision
|
||||
# precison of calibration further improved by timing Pyboard RTC transition
|
||||
# Adapted by Peter Hinch, Feb 2017
|
||||
|
||||
# Author: Peter Hinch
|
||||
# Copyright Peter Hinch 2018 Released under the MIT license.
|
||||
|
||||
import utime
|
||||
import machine
|
||||
|
|
|
@ -1,30 +1,39 @@
|
|||
# ds3231_port_test
|
||||
# Test of portable driver for DS3231 precision RTC chip
|
||||
# Test/demo of portable driver for DS3231 precision RTC chip
|
||||
|
||||
# Author: Peter Hinch
|
||||
# Copyright Peter Hinch 2018 Released under the MIT license
|
||||
|
||||
from machine import Pin, I2C
|
||||
import utime
|
||||
import sys
|
||||
from ds3231_port import DS3231
|
||||
# Pyboard test
|
||||
|
||||
# A Pyboard test
|
||||
#from pyb import RTC
|
||||
#rtc = RTC()
|
||||
#rtc.datetime((2018, 1, 1, 1, 12, 0, 0, 0)) # Force incorrect setting
|
||||
|
||||
# In case pullups are absent.
|
||||
#scl_pin = Pin('X2', pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
#sda_pin = Pin('X1', pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
scl_pin = Pin(19, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
sda_pin = Pin(18, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
# mode and pull are specified in case pullups are absent.
|
||||
# The pin ID's are arbitrary.
|
||||
if sys.platform == 'pyboard':
|
||||
scl_pin = Pin('X2', pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
sda_pin = Pin('X1', pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
else: # I tested on ESP32
|
||||
scl_pin = Pin(19, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
sda_pin = Pin(18, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
|
||||
|
||||
i2c = I2C(-1, scl=scl_pin, sda=sda_pin)
|
||||
ds3231 = DS3231(i2c)
|
||||
|
||||
print('Initial values')
|
||||
print('DS3231 time:', ds3231.get_time())
|
||||
print('RTC time:', utime.localtime())
|
||||
print('RTC time: ', utime.localtime())
|
||||
|
||||
print('Setting DS3231 from RTC')
|
||||
ds3231.save_time() # Set DS3231 from RTC
|
||||
print('DS3231 time:', ds3231.get_time())
|
||||
print('RTC time:', utime.localtime())
|
||||
print('RTC time: ', utime.localtime())
|
||||
|
||||
print('Running RTC test for 2 mins')
|
||||
print('RTC leads DS3231 by', ds3231.rtc_test(120, True), 'ppm')
|
||||
|
|
Ładowanie…
Reference in New Issue