1. dht11 라이브러리 추가
2. lcd.py 개발
import lcddriver as lcd
from time import time
from time import sleep
from datetime import datetime
import sys
import odroid_wiringpi as wpi
import odroid_dht11 as dht11
wpi.wiringPiSetup()
lcd_bus = 1
dht_pin = 7
led_pin = 4
fan_pin = 5
GPIO_HIGH = 1
GPIO_LOW = 0
GPIO_IN = 0
GPIO_OUT = 1
# init lcd
lcd = lcd.lcd(lcd_bus)
temp = 0
humi = 0
#lcd.display_string("2022-05-31 11:22:33", 1)
#lcd.display_string("LED ON, FAN ON", 1)
#lcd.display_string("TEMP 14 C, HUD 90 %", 2)
def displayGpio():
ledStr = "OFF";
fanStr = "OFF";
ledStatus = wpi.digitalRead(led_pin)
if ledStatus == 1:
ledStr = "ON";
fanStatus = wpi.digitalRead(fan_pin)
if fanStatus == 1:
fanStr = "ON";
print("LED :",ledStr)
print("FAN :",fanStr)
lcd.display_string("LED %-3s FAN %-3s" % (ledStr, fanStr), 1)
def displayDht11():
global temp
global humi
# read data using pin 14
instance = dht11.DHT11(pin = dht_pin)
result = instance.read()
if result.is_valid():
temp = int(result.temperature)
humi = int(result.humidity)
print("TEMP :",temp)
print("HUMI :",humi)
lcd.display_string("TEMP %-2dC HUMI %-2d%%" % (temp, humi), 2)
while True:
try:
displayGpio()
displayDht11()
timeString = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
lcd.display_string(timeString, 4)
sleep(1)
except:
print("error")
3. 구동 쉘 개발 lcd.sh
#~/bin/sh
pkill -9 -f "python3 /sw/lcd/lcd.py"
cd /sw/lcd
nohup python3 /sw/lcd/lcd.py &
4. 구현 결과