Ejemplo n.º 1
0
'''
    DS1307 demo

    Author: shaoziyang
    Date:   2018.3

    http://www.micropython.org.cn

'''
import ds1307
from machine import I2C, Pin

i2c = I2C(sda = Pin(5), scl=Pin(4))
ds = ds1307.DS1307(i2c)

ds.datetime()
ds.datetime([2018, 3, 9, 4, 23, 0, 1, 0])

ds.hour()
# reads RFID tags, displays the associated name and time of scan, logs time and ID to a file
# needs ds1307 module from https://github.com/mcauser/micropython-tinyrtc-i2c
# needs mfrc522 from https://github.com/wendlers/micropython-mfrc522

import machine, ds1307, ssd1306, time, mfrc522, os

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))  #set up the I2C
oled = ssd1306.SSD1306_I2C(128, 32, i2c, 0x3c)  #set up the display
ds = ds1307.DS1307(i2c, 0x68)  #set up the TinyRTC

reader = mfrc522.MFRC522(14, 13, 12, 0, 2)
# initiate RC522 reader with the following pins:
# SCK pin 14 (D13), MOSI pin 13 (D11), MISO pin 12 (D12), RST pin 0 (D8), SDA/CS pin 2 (D9)

deck = {
    (136, 4, 110, 155, 121): 'Monica',
    (136, 4, 218, 48, 102): 'Rachel',
    (136, 4, 124, 155, 107): 'Ross',
    (136, 4, 123, 155, 108): 'Chandler',
    (136, 4, 212, 203, 147): 'Phoebe',
    (136, 4, 212, 214, 142): 'Joey'
}
#tuples are uids of the discarded bus tickets with RFID tags, with names marked on them for clocking in and out :)

log = open('log.txt', "a+")  #create a file
log.close()  #close the file


def display(id, timestamp):
    '''clears the display, then displays the id and timestamp in two lines'''
    # needs to stay on for a defined amount of time, then disappear - to be improved
    pin_sda = 21
    pin_sens = 16
else:  # ESP8266
    pin_scl = 5
    pin_sda = 4
    pin_sens = 2

frequency = 100000
width = 64
height = 48
BME280_OSAMPLE_16 = 5

i2c = I2C(scl=Pin(pin_scl), sda=Pin(pin_sda), freq=frequency)
oled = SSD1306_I2C(width, height, i2c)
bme = bme280.BME280(mode=BME280_OSAMPLE_16, i2c=i2c)
rtc = ds1307.DS1307(i2c)

sensor_Pin = Pin(pin_sens, Pin.IN)
dht = DHT22(sensor_Pin)

topic1 = b'TempDHT22'
topic2 = b'HumidDHT22'
topic3 = b'Press'
topic4 = b'LPG'
topic5 = b'CO'
topic6 = b'ME'
topic7 = b'TempBME280'
topic8 = b'Sens_Date'
topic9 = b'Sens_Time'

client_id = hexlify(unique_id())