Beispiel #1
0
def sync_rtc():
    rtc_power_pin = Pin(config.RTC_POWER_PIN, Pin.OUT)
    rtc_power_pin.on()
    i2c = I2C(scl=Pin(config.RTC_SCL_PIN), sda=Pin(config.RTC_SDA_PIN))
    ext_rtc = DS3231(i2c)
    ext_rtc.get_time(set_rtc=True)
    rtc_power_pin.off()
Beispiel #2
0
    def __init__(self):
        try:
            i2c = I2C(scl=I2C_RTC_SCL_PIN, sda=I2C_RTC_SDA_PIN)
            self.rtc = DS3231(i2c)
        except:
            self.rtc = None

        self.set_clock()
        start_time()
        start_new_thread(self.refresh, ())
Beispiel #3
0
# Receiver code for Cawthron Institute's mussel farm accelerometer chain
# Author: Kevin Tang
from machine import I2C, Pin, SPI, UART, WDT
from lis3dh import LIS3DH, LIS3DH_I2C, RANGE_2_G, DATARATE_10_HZ, STANDARD_GRAVITY
from pyb import ADC, RTC
from ds3231_port import DS3231
import time
import os
import sys
import math
if sys.platform == 'pyboard':
    # Initialising pins
    thermistor = pyb.ADC('Y12')
    tx_enable = Pin('X20', Pin.OUT)
    # Initialising I2C
    i2c = I2C(1)
    rtc_i2c = I2C(2)
    ds3231 = DS3231(rtc_i2c)
    # Initialising UART
    uart = UART(4, 115200)  # Pins X1 and X2
    uart.init(115200, bits=8, parity=None, stop=1,
              timeout=0)  # Non-blocking UART
else:
    print('Incompatible board detected, please connect pyboard')
ID = 0  # Receiver ID (0-9). MAKE SURE TO CHANGE
accelerometer = LIS3DH_I2C(i2c, int1=None)
# Date initialisation
rtc = RTC()
timeCheck = ds3231.get_time()  # Gets current time
rtc.datetime(
Beispiel #4
0
# Datalogger code for Cawthron Institute's mussel farm accelerometer chain
# Author: Kevin Tang
"""
DEFAULT SETTINGS
MODE = DATA_RATE_1HZ
BAUD RATE: 9600
UART DATA FRAME: bits=8, parity=None, stop=1, timeout=1000
WDT TIMEOUT: 3000ms
1 HZ SLEEP: 30s
2 HZ SLEEP: 10s
"""
from machine import Pin, I2C, SPI, UART, WDT
from ds3231_port import DS3231
from pyb import RTC
import utime
import time
import sys
import os
# Timeout values
global SLEEP_1HZ
global SLEEP_2HZ
SLEEP_1HZ = 30
SLEEP_2HZ = 10
# Modes
global DATA_RATE_1HZ
global DATA_RATE_2HZ
global MODE
DATA_RATE_1HZ = 'one'
DATA_RATE_2HZ = 'two'
MODE = DATA_RATE_1HZ  # Choose modes here (DATA_RATE_1HZ or DATA_RATE_2HZ)
Beispiel #5
0
# Pot qui pense - CREPP 2019
# GPL V3.0
# www.crepp.org - [email protected]

import machine
from ds3231_port import DS3231

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
ds = DS3231(i2c)


def test():
    print(ds.get_time())


def save_datetime(an, mo, jo, h, mn):
    #print(h, mn)
    rtc = machine.RTC()
    rtc.datetime((an, mo, jo, 6, h, mn, 0, 0))  # 6:dimanche
    print(rtc.datetime())
    ds.save_time()  # ecriture et sauvegarde de l'heure


def get_next():
    # quantité de minutes jusqu'a la prochaine heure
    try:
        t = ds.get_time()
    except OSError:
        t[4] = 0
    mn = 60 - t[4]
    if mn <= 10:
Beispiel #6
0
from ds3231_port import DS3231

# 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.
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('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')
Beispiel #7
0
# Receiver code for Cawthron Institute's mussel farm accelerometer chain
# Author: Kevin Tang
"""
DEFAULT VALUES
MODE: 1 HZ
BAUD RATE: 9600
DATA FRAME: bits=8, parity=None, stop=1, timeout=0
WDT TIMEOUT: 3000ms
ACCELEROMETER RANGE: 2G
ACCELEROMETER FREQUENCY: 10HZ
"""
from machine import I2C, Pin, SPI, UART, WDT
from lis3dh import LIS3DH, LIS3DH_I2C, RANGE_2_G, DATARATE_10_HZ, STANDARD_GRAVITY
from pyb import ADC, RTC
from ds3231_port import DS3231
import time
import os
import sys
import math
global ID
global timer
ID = 0 # Receiver ID (0-9). MAKE SURE TO CHANGE
timer = 1 # By default, sleep value is set to 1s (1 Hz mode)
# Enable Watchdog timer if using battery
global TIMEOUT_VALUE
TIMEOUT_VALUE = 3000
if pyb.Pin.board.USB_VBUS.value() == 0:
  wdt = WDT(timeout = TIMEOUT_VALUE) # enable with a timeout of 3 seconds
if sys.platform == 'pyboard':
  # Initialising pins
Beispiel #8
0
 def save_time(self):
     from ds3231_port import DS3231
     ds3231 = DS3231(self.i2c)
     ds3231.save_time()
Beispiel #9
0
 def get_time(self, set_rtc=False):
     from ds3231_port import DS3231
     ds3231 = DS3231(self.i2c)
     ds3231.get_time(set_rtc=set_rtc)
Beispiel #10
0
 def setup(self, i2c):
     ds3231 = DS3231(i2c)
     ds3231.get_time(set_rtc=True)
     self.ds3231 = ds3231
     self.workScheduler.schedule_work()
Beispiel #11
0
# Datalogger code for Cawthron Institute's mussel farm accelerometer chain
# Author: Kevin Tang
from machine import Pin, I2C, SPI, UART, WDT
from ds3231_port import DS3231
from pyb import RTC
import utime
import time
import sys
import os
if sys.platform == 'pyboard':
    # Pin connections
    tx_enable = Pin('X20', mode=Pin.OUT)
    # RTC initialisation
    i2c = I2C(1)
    ds3231 = DS3231(i2c)
    # UART initialisation
    uart = UART(4, 115200)  # Pins X1 and X2
    uart.init(115200, bits=8, parity=None, stop=1,
              timeout=500)  # Non-blocking UART
else:
    print('Incompatible system detected, please connect a pyboard')
# Date initialisation
rtc = RTC()
timeCheck = ds3231.get_time()  # Gets current time
rtc.datetime(
    (timeCheck[0], timeCheck[1], timeCheck[2], timeCheck[6], timeCheck[3],
     timeCheck[4], timeCheck[5], 0))  # Syncs RTC clock to local time
"""
# Sets up RTC clock, uncomment to manually set the clock (NOTE: DAY OF WEEK AND TIME ZONE IS NOT WORKING)
rtc.datetime((2020, 1, 22, 3, 15, 14, 50, 0))  # Comment out if already programmed