예제 #1
0
#tests buzzer using pin
buzzer(True)
time.sleep(1)
buzzer(False)

#setup LEDs using IO expander
led = PCA9554(line=1, direction=0)
#tests LED using IO expander
led.set()
time.sleep(1)
led.reset()

#clock setup
rtc = RTC() #internal RTC module
i2c = I2C(0, pins=('P22','P21')) #setup i2c interface
ds = DS3231.DS3231(i2c) #establish connection to i2c clock

#setup taps pending list and counter
taps_pending = []
count = 0

#setup scan
py = Pyscan()
nfc = MFRC630(py)
nfc.mfrc630_cmd_init() # Initialise the MFRC630 with some settings

#setup thread lock
sendlock = _thread.allocate_lock()

################# Functions start
예제 #2
0
'''
    DS3231 demo

    Author: shaoziyang
    Date:   2018.3

    http://www.micropython.org.cn
'''
from microbit import *
import DS3231

ds = DS3231.DS3231()

ds.Hour(12)

ds.Time()
ds.Time([12,10,0])

ds.DateTime([2018,3,12,1,22,10,0])

ds.ALARM(12, 20, 10, ds.PER_DISABLE)
ds.ALARM(12, 20, 10, ds.PER_DAY)
ds.ClearALARM()
예제 #3
0
import network, urequests, utime, machine
from machine import RTC, I2C, Pin
import DS3231
#from ssd1306 import SSD1306_I2C

# user data
ssid = "BTXPS1_2.4G"  # wifi router name
pw = "#Pentagrama24968#"  # wifi router password
url = "http://worldtimeapi.org/api/timezone/Europe/Lisbon"  # see http://worldtimeapi.org/timezones
web_query_delay = 60000  # interval time of web JSON query
retry_delay = 5000  # interval time of retry after a failed Web query

# Pin(5) no esp32 => D5
# Pin(4) no esp32 => D4
i2c = I2C(sda=Pin(5), scl=Pin(4))
ds = DS3231.DS3231(i2c)

# initialization

# SSD1306 OLED display
print("Connecting to wifi...")
#oled = SSD1306_I2C(128, 64, I2C(scl=Pin(5), sda=Pin(4)))
#oled.fill(0)
#oled.text("Connecting", 0, 5)
#oled.text(" to wifi...", 0, 15)
#oled.show()

# internal real time clock
rtc = RTC()

# wifi connection
from utils import utils

# init logger
logger_name = 'main_logger'
test_handle = utils(logger_name)
logger = test_handle.init_logger()


# create RTC object
i2c_port  = 1 # set to 0 if using gen 1 pi
i2c_addr  = 0x68
latitude  = 39.7392
longitude = 104.9903
rtc = DS3231.DS3231(logger_name = logger_name,
                    i2c_port    = i2c_port,
                    i2c_addr    = i2c_addr,
                    latitude    = latitude,
                    longitude   = longitude)

# create system monitor object
sys_mon = system_monitor.system_monitor(logger_name = logger_name)

logger.info('Monitoring DS3231 Information')

# Configure RTC
rtc.configure_rtc()


''' Functionality Helper Functions
'''
def configure_rtc():
예제 #5
0
	def __init__(self, sda, scl):
		self.i2c = I2C(sda = Pin(sda), scl=Pin(scl))
		self.rtc = DS3231.DS3231(self.i2c)
예제 #6
0
    def __init__(self, args):
        TxtApplication.__init__(self, args)

        # create the empty main window
        self.w = TxtWindow("TX-Pi HAT")

        self.vbox = QVBoxLayout()
        self.vbox.setSpacing(0)

        self.vbox.addStretch()
        self.hat = TxPiHat()

        # add GPIO area
        if self.hat.ok:
            lbl = QLabel("-- Motors --")
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("smalllabel")
            self.vbox.addWidget(lbl)
        
            self.m1 = MotorWidget(self.hat, "M1")
            self.vbox.addWidget(self.m1)
            self.m2 = MotorWidget(self.hat, "M2")
            self.vbox.addWidget(self.m2)

            self.vbox.addStretch()

            lbl = QLabel("-- Inputs --")
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("smalllabel")
            self.vbox.addWidget(lbl)

            hw = QWidget()            
            hbox = QHBoxLayout()
            hbox.setContentsMargins(0,0,0,0)
            self.i1 = InputWidget("I1")
            hbox.addWidget(self.i1)
            self.i2 = InputWidget("I2")
            hbox.addWidget(self.i2)
            hw.setLayout(hbox)
            self.vbox.addWidget(hw)

            hw = QWidget()            
            hbox = QHBoxLayout()
            hbox.setContentsMargins(0,0,0,0)
            self.i3 = InputWidget("I3")
            hbox.addWidget(self.i3)
            self.i4 = InputWidget("I4")
            hbox.addWidget(self.i4)
            hw.setLayout(hbox)
            self.vbox.addWidget(hw)

            self.timer = QTimer(self)
            self.timer.timeout.connect(self.input_update)
            self.timer.start(100)
        else:
            lbl = QLabel("GPIO setup failed!")
            lbl.setWordWrap(True)
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("smalllabel")
            self.vbox.addWidget(lbl)
            lbl = QLabel(self.hat.err)
            lbl.setWordWrap(True)
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("tinylabel")
            self.vbox.addWidget(lbl)

        self.vbox.addStretch()
        
        # add DS3231 area
        bus = os.getenv('I2C')
        if bus == None: bus = 0   # raspberry PI default
        else:           bus = int(bus)

        try:
            self.ds3231 = DS3231.DS3231(bus, 0x68)
            self.ds3231._read(0)
            self.ds3231.ackPendingAlarm()
        except:
            self.ds3231 = None

        # retry on bus 1
        if not self.ds3231:
            try:
                bus = 1
                self.ds3231 = DS3231.DS3231(bus, 0x68)
                self.ds3231._read(0)
                self.ds3231.ackPendingAlarm()
            except:
                self.ds3231 = None

        if self.ds3231:
            lbl = QLabel("-- DS3231 RTC --")
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("smalllabel")
            self.vbox.addWidget(lbl)

            self.datew = DateTimeWidget("Date")
            self.vbox.addWidget(self.datew)
            
            self.timew = DateTimeWidget("Time")
            self.vbox.addWidget(self.timew)

            self.tempw = DateTimeWidget("Temp.")
            self.vbox.addWidget(self.tempw)

            self.rtimer = QTimer(self)
            self.rtimer.timeout.connect(self.rtc_update)
            self.rtimer.start(500)

            self.set_but = QPushButton("Set from system")
            self.set_but.setStyleSheet("font-size: 24px;")
            self.set_but.clicked.connect(self.on_rtc_set)
            self.vbox.addWidget(self.set_but)

            self.rst_but = QPushButton("Restart in 1 min")
            self.rst_but.setStyleSheet("font-size: 24px;")
            self.rst_but.clicked.connect(self.on_rtc_reboot)
            self.vbox.addWidget(self.rst_but)

        else:
            lbl = QLabel("No DS3231 RTC detected!")
            lbl.setWordWrap(True)
            lbl.setAlignment(Qt.AlignCenter)
            lbl.setObjectName("smalllabel")
            self.vbox.addWidget(lbl)           
            
        self.vbox.addStretch()
        self.w.centralWidget.setLayout(self.vbox)

        self.w.show() 

        self.exec_()