Browse Source

DHT22 included

master
Luis Waldhauser 1 year ago
parent
commit
9388f765f4
1 changed files with 39 additions and 29 deletions
  1. 39
    29
      software/roboter/raspy/raspySensors.py

+ 39
- 29
software/roboter/raspy/raspySensors.py View File

@@ -1,38 +1,38 @@
from picamera import PiCamera
#from picamera import PiCamera
import adafruit_dht
import board
import json

class RaspySensors:
'''Class to handle all sensors'''
#Air Temp&Humidity
dht22 = 0

#Earth Humidity


#Brightness Sensor


#PiCamera
camera = PiCamera()

#GPS

#Varaibles
sensorData ={
"Air Temperature" : 0,
"Air Humidity" : 0,
"Earth Humidity" : 0,
"Brightness" : 0
}
image = 0
position = 0

def __init__(self) -> None:
'''Init all Sensors
#Message if Error'''
dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
'''Init all Sensors'''
#Message if Error
#Air Temperature & Humidity
self.dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)

#global Variables
self.sensorData ={
"Air Temperature" : 0,
"Air Humidity" : 0,
"Earth Humidity" : 0,
"Brightness" : 0
}

def readSensors(self):
'''Read all Sensors and return Dictionary with data'''

#read DHT22
#if Error reading Data try again
while True:
try:
self.sensorData["Air Temperature"] = self.dht22.temperature
self.sensorData["Air Humidity"] = self.dht22.humidity
except:
continue
break

return self.sensorData
def takePicture(self):
@@ -41,4 +41,14 @@ class RaspySensors:
def readPosition(self):
'''Read and return Position'''
return self.position
return self.position


#for Testing only
def main():
sensors = RaspySensors()
test = sensors.readSensors()
print("Data:" + json.dumps(test))

if __name__ == "__main__":
main()

Loading…
Cancel
Save