瀏覽單個文章
dbzwin
Amateur Member
 

加入日期: Feb 2004
文章: 38
請問python讀取DHT22的問題

最近用樹莓派裝上DHT22跟20*4的I2C顯示器
程式寫下面那樣,但是卻只有時間及日期有循環更新
問度跟濕度只會讀取第一次,怎麼會這樣

import RPi.GPIO as GPIO
import Adafruit_DHT
import I2C_LCD_driver
import time

mylcd = I2C_LCD_driver.lcd()
DHT_TYPE = Adafruit_DHT.DHT22
DHT_PIN = 4
humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN)

while True:
mylcd.lcd_display_string("Time: %s" %time.strftime("%H:%M:%S"), 1)
mylcd.lcd_display_string("Date: %s" %time.strftime("%m/%d/%Y"), 2)
mylcd.lcd_display_string("Humidity: %d %%" % humidity, 4)
mylcd.lcd_display_string("temperature: %d C" % temp, 3)
     
      
舊 2017-02-19, 12:06 AM #1
回應時引用此文章
dbzwin離線中