EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #235 background imageLoading...
Page #235 background image
235
Chapter 21 Hygrothermograph DHT11
www.freenove.com
support@freenove.com
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
im port RPi. GPIO as GPIO
im port time
im port Freenove_DHT as DHT
DHTPin = 11 #define the pin of DHT11
def loop():
dht = DHT.DHT(DHTPin) #create a DHT class object
sumCnt = 0 #number of reading times
w hile(True):
sumCnt += 1 #counting number of reading times
chk = dht. readDHT11() #read DHT11 and get a return value. Then determine
whether data read is normal according to the return value.
print ("The sumCnt is : %d, \t chk : %d"%(sumCnt,chk))
if (chk is dht. DHTLIB_OK): #read DHT11 and get a return value. Then
determine whether data read is normal according to the return value.
print("DHT11,OK!")
elif(chk is dht. DHTLIB_ERROR_CHECKSUM): #data check has errors
print("DHTLIB_ERROR_CHECKSUM!!")
elif(chk is dht. DHTLIB_ERROR_TIMEOUT): #reading DHT times out
print("DHTLIB_ERROR_TIMEOUT!")
else: #other errors
print("Other error!")
print("Humidity : %.2f, \t Temperature : %.2f \n"%(dht.humidity,dht.temperature))
time.sleep(2)
if __name__ == '__main__':
p rint ('Program is starting ... ')
try:
loop()

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish