Skip to content

Instantly share code, notes, and snippets.

@rlatn1234
Last active April 2, 2021 00:59
Show Gist options
  • Save rlatn1234/48889cc6f142d3ff993623e255c3a5d7 to your computer and use it in GitHub Desktop.
Save rlatn1234/48889cc6f142d3ff993623e255c3a5d7 to your computer and use it in GitHub Desktop.
import time,datetime
import adafruit_dht
import board
import sqlite3
import I2C_LCD_Driver
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
mylcd = I2C_LCD_Driver.lcd()
dhtDevice = adafruit_dht.DHT11(board.D4,False)
con = sqlite3.connect("cddl.db")
cur = con.cursor()
#cur.execute("CREATE TABLE cddl(time TEXT,card_data TEXT,temp INTEGER,hum INTEGER)") #disable this on second run
while True:
id ,text = reader.read(timeout=1)
print(text)
if text != None:
mylcd.lcd_clear()
temperature_c = dhtDevice.temperature
humidity = dhtDevice.humidity
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
nowdd = datetime.datetime.now().strftime("%m-%d %H:%M:%S")
cur.execute("INSERT INTO temphum VALUES (?,?,?,?)",(now,text,temperature_c,humidity))
con.commit()
mylcd.lcd_display_string("Card Data : {}".format(text),2)
mylcd.lcd_display_string(nowdd,1)
time.sleep(2)
text=None
elif text == None:
while True:
data = 0
try:
temperature_c = dhtDevice.temperature
humidity = dhtDevice.humidity
nowdd = datetime.datetime.now().strftime("%m-%d %H:%M:%S")
print("[{}] Temp: {:.1f} C Humidity: {}% ".format(nowdd,temperature_c, humidity))
mylcd.lcd_clear()
mylcd.lcd_display_string("T:{}C H:{}".format(temperature_c,humidity),1)
mylcd.lcd_display_string("{}".format(nowdd),2)
id ,text = reader.read(timeout=1)
if (text != None):
break
except RuntimeError as error:
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment