Ejemplo n.º 1
0
def test():
    NSAMPLES = 10
    a = DS3231()
    for t in (5, 10, 20, 40):
        values = array('f', (0 for z in range(NSAMPLES)))
        print('t = {:2d}'.format(t), end='')
        for x in range(NSAMPLES):
            cal = a.getcal(t)
            values[x] = cal
            print('{:5d}'.format(cal), end='')
        avg = sum(values) / NSAMPLES
        sd2 = sum([(v - avg)**2 for v in values]) / NSAMPLES
        sd = sd2**0.5
        print('  avg {:5.1f} sd {:5.1f}'.format(avg, sd))
# If powering the DS3231 from a Pyboard D 3V3 output:
if uos.uname().machine.split(' ')[0][:4] == 'PYBD':
    Pin.board.EN_3V3.value(1)

# A Pyboard test
#from pyb import RTC
#rtc = RTC()
#rtc.datetime((2018, 1, 1, 1, 12, 0, 0, 0))  # Force incorrect setting

# mode and pull are specified in case pullups are absent.
# The pin ID's are arbitrary.
scl_pin = Pin("PB6", pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
sda_pin = Pin("PB7", 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('Setting DS3231 from RTC')
ds3231.save_time()  # Set DS3231 from RTC
print('DS3231 time:', ds3231.get_time())
print('RTC time:   ', utime.localtime())

print('Running RTC test for 2 mins')
print('RTC leads DS3231 by', ds3231.rtc_test(120, True), 'ppm')

Ejemplo n.º 3
0
from ds3231 import DS3231
from gps import *
from sat import *
from common import *
import stm

schedule = [0, 3, 6, 9, 11, 12, 15, 18, 21]
transmit = [11]
# max number of loops in ms
positiontimeout = 60 * 1000
# use fix type of this quality (is FIX really 4?) HARDCODED NOW
FIXQUALITY = '4'
# minimum Iridium strength to use
MINIRIDIUM = 2
#Get the current time
print("AWAKE!")
extrtc = DS3231()

(YY, MM, DD, hh, mm, ss, wday, n1) = extrtc.get_time()
print(extrtc.get_time())

pin = pyb.Pin.board.A0
pin.init(mode=pyb.Pin.IN, pull=pyb.Pin.PULL_DOWN)
# In this mode pin has pulldown enabled
stm.mem32[stm.PWR + stm.PWR_CR] |= 4  # set CWUF to clear WUF in PWR_CSR
stm.mem32[stm.PWR + stm.PWR_CSR] |= 0x100  # Enable wakeup

extrtc.clearalarm()
extrtc.testalarm()
print("Waiting for sleep...")
print("type pyb.standby() to sleep (you have 20secs until wake)")
Ejemplo n.º 4
0
#HTML页面
html = """
<html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <head> <title>TPYBoard v201</title> </head>
    <body>
        <h1>TPYBaord 家庭气象站</h1><br />
        <p>时间:{}</p>
        <p>温度:{}</p>
        <p>湿度:{}</p>
    </body>
</html>
"""

#------------------------DS3231----------------------------------#
ds = DS3231(2)  #设置DS3231为I2C2接口,对应SCL-Y9,SDA-Y10
#初始日期和时间,设置一次即可
#ds.DATE([19,7,27])   #设置初始日期年、月、日
#ds.TIME([14,50,0])   #设置初始时间时、分、秒
#------------------------DHT11----------------------------------#
d = DHT11('X12')


def updateDisplay():

    DATE = [str(i) for i in ds.DATE()]  #将返回的时间数据int转str
    TIME = [str(i) for i in ds.TIME()]
    time = '-'.join(DATE) + ' ' + ':'.join(TIME)  #读取日期和时间,拼接成正常的时间格式
    data = d.read_data()  #读取温湿度的值
    return time, data
Ejemplo n.º 5
0
def date():
    extrtc = DS3231()
    print(extrtc.get_time())
Ejemplo n.º 6
0
# main.py -- put your code here!
import pyb
from ds3231 import DS3231
ds = DS3231(1)
#设置日期
ds.DATE([19, 04, 01])
#设置时间
ds.TIME([15, 10, 10])
#延时5秒查看效果
pyb.delay(5000)
#读取秒并打印
print(ds.sec())
#读取日期
print(ds.DATE())
#读取时间
print(ds.TIME())

#读取温度
print(ds.TEMP())
Ejemplo n.º 7
0
from machine import Pin, I2C
from ds3231 import DS3231

time_module = DS3231(I2C(sda=Pin(21), scl=Pin(22)))


def now():
    return time_module.DateTime()


def set_datetime(year, month, day, hour, minute, second):
    time_module.Year(year)
    time_module.Month(month)
    time_module.Day(day)
    time_module.Hour(hour)
    time_module.Minute(minute)
    time_module.Second(second)
Ejemplo n.º 8
0
import pycom
import machine
from machine import Timer, Pin, PWM
import utime
from ds3231 import DS3231
from network import WLAN

pycom.heartbeat(False)

VERSION = '0.7.0'

ertc = DS3231(0, (Pin.module.P21, Pin.module.P20))
print(ertc.get_time())
#print(ertc.save_time())

######################
#  External RTC
#######################

# Synced RTC with pool.ntp.org
# Sync had a difference of 2 hours to local time
# Lib -> ds3231.py to change the value of the hours

# def setup_rtc():
#     rtc = machine.RTC()
#     rtc.ntp_sync("pool.ntp.org")
#     while not rtc.synced():
#         utime.sleep_ms(100)
#         print("nope")
#     print('RTC now synced: {}'.format(ertc.get_time()))
#
Ejemplo n.º 9
0
'''
Created on 2018Äê1ÔÂ15ÈÕ

@author: Administrator
'''

import machine
import time
from ds3231 import DS3231

ds = DS3231()
ds.DATE([17, 9, 1])
ds.TIME([10, 10, 10])

while True:
    print('Date:', ds.DATE())
    print('Time:', ds.TIME())
    print('TEMP:', ds.TEMP())
    time.sleep(5)
Ejemplo n.º 10
0
 def ertc(self):
     if not self._ertc:
         _logger.debug("Initializing external RTC")
         from ds3231 import DS3231
         self._ertc = DS3231(0, pins=self._i2c_pins_names)
     return self._ertc
Ejemplo n.º 11
0
from ds3231 import DS3231
import board
import busio
import time

if __name__ == '__main__':
    i2c = busio.I2C(board.SCL, board.SDA)
    clock = DS3231(i2c)

    while True:
        t = clock.datetime
        #print(f'{clock.datetime()}')
        print("{}:{:02}:{:02}\n".format(t.tm_hour, t.tm_min, t.tm_sec))
        time.sleep(1)
Ejemplo n.º 12
0
WIFI_FILE = 'wifi.txt'

# How long it takes for the LEDs to reach full brightness
SUNRISE_LENGTH = 1800
# For how long the brightness increases mildly
LOW_THRESHOLD = SUNRISE_LENGTH / 2
LOW_THRESHOLD_DUTY = 30
# For how long the light stays on after the alarm
# goes off
KEEP_LIGHT_ON = SUNRISE_LENGTH / 2

MAX_DUTY = 1023
DUTY_DIFF = MAX_DUTY - LOW_THRESHOLD_DUTY

i2c = I2C(sda=Pin(4), scl=Pin(16))
DS = DS3231(i2c)
LED = PWM(Pin(17, Pin.OUT), freq=70, duty=0)

with open(TIME_FILE, 'r') as infile:
    t = infile.read().splitlines()
    ALARM_HOURS, ALARM_MINUTES, ALARM_SECONDS = int(t[0]), int(t[1]), int(t[2])


def seconds_until_alarm(alarm_hours, alarm_minutes, alarm_seconds):
    """Calculates the number of seconds until alarm goes off"""
    hours = DS.hour()
    mins = DS.minute()
    secs = DS.second()
    until_alarm = 0
    # Special-case when the current time is already after the alarm
    if hours > alarm_hours or (hours == alarm_hours and mins > alarm_minutes) or \
Ejemplo n.º 13
0
#import urequests as requests
import urequests
import json
import time
from machine import SPI, Pin  #导入SPI、Pin库
import ssd1306  #导入OLED显示屏驱动库
from ds3231 import DS3231  #导入DS3231时钟模块库
from machine import Timer  #导入Timer库

#-----------------------DS3231模块-----------------------#
ds = DS3231()  #ds3231初始化
NOW_DATE = ''
#-----------------------OLED显示屏-----------------------#
#SPI接口对应的引脚定义
spi = SPI(baudrate=10000000,
          polarity=1,
          phase=0,
          sck=Pin(12, Pin.OUT),
          mosi=Pin(13, Pin.OUT),
          miso=Pin(2))
#OLED显示屏的设置,128宽 64高 spi对象 DC接的G15 RES接的G16 CS接的G5
display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(15), Pin(16), Pin(5))
display.poweron()  #打开显示屏
display.init_display()  #初始化显示
display.text('Waiting.....', 1, 1)  #显示的内容,x坐标,y坐标
display.show()  #进行显示


def getNetTime():
    url = 'http://quan.suning.com/getSysTime.do'
    res = urequests.get(url).text