def inputValue(): try: #sensor dust = PMS7003() # Baud Rate Speed = 9600 # UART / USB Serial USB0 = '/dev/ttyUSB0' UART = '/dev/ttyAMA0' # USE PORT SERIAL_PORT = USB0 #serial setting ser = serial.Serial(SERIAL_PORT, Speed, timeout=1) buffer = ser.read(1024) if (dust.protocol_chk(buffer)): data = dust.unpack_data(buffer) pm10 = data[dust.DUST_PM10_0_ATM] pm2_5 = data[dust.DUST_PM2_5_ATM] # if pm10 >= 151 or pm2_5 >= 76: # setMsg = 2 #매우나쁨 빨강 # elif pm10 >= 81 or pm2_5 >= 36: # setMsg = 1 #나쁨 노랑 # else: # setMsg = 0 #좋음 초록 if pm10 >= 25 or pm2_5 >= 20: situation = 3 #매우나쁨 빨강 elif pm10 >= 21 or pm2_5 >= 15: situation = 2 #나쁨 노랑 elif pm10 >= 17 or pm2_5 >= 10: situation = 1 #좋음 초록 else: situation = 0 #꺼짐 else: print("data read Err") situation = -1 pm2_5 = -1 pm10 = -1 setMsg = [1, situation, -1, pm2_5, pm10] return setMsg except: GPIO.output(red, 1) GPIO.output(green, 1) GPIO.output(blue, 1) GPIO.output(POWER, 0) # GPIO.cleanup() finally: ser.close()
DUST_AIR_1_0 = indicates the number of particles with diameter beyond 1.0 um in 0.1 L of air. DUST_AIR_2_5 = indicates the number of particles with diameter beyond 2.5 um in 0.1 L of air. DUST_AIR_5_0 = indicates the number of particles with diameter beyond 5.0 um in 0.1 L of air. DUST_AIR_10_0 = indicates the number of particles with diameter beyond 10 um in 0.1 L of air. RESERVEDF = Data13 Reserved high 8 bits RESERVEDB = Data13 Reserved low 8 bits CHECKSUM = Checksum code # CF=1 should be used in the factory environment """ import serial from PMS7003 import PMS7003 from datetime import datetime dust = PMS7003() # Baud Rate Speed = 9600 # UART / USB Serial USB0 = '/dev/ttyUSB0' UART = '/dev/ttyAMA0' # USE PORT SERIAL_PORT = USB0 #serial setting ser = serial.Serial(SERIAL_PORT, Speed, timeout=1) from datetime import datetime import time
from threading import Thread import time import serial from PMS7003 import PMS7003 import RPi.GPIO as GPIO import lcd_i2c as lcd from configparser import ConfigParser # 전원 power_state = 0 powersw = Button(26) # 팬 버튼 24핀 fansw = Button(24) #먼지센서 오브젝트 dustlib = PMS7003() # 시리얼 Speed = 9600 SERIAL_PORT = '/dev/ttyUSB0' # 팬 조절 fan_pwm = PWMOutputDevice(12) fan_pin1 = DigitalOutputDevice(5) fan_pin2 = DigitalOutputDevice(6) ON = 1 OFF = 0 # 팬속 FULL = 1.0 MID = 0.65 SLOW = 0.3