repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

raspySensors.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #from picamera import PiCamera
  2. import adafruit_dht
  3. import board
  4. import json
  5. class RaspySensors:
  6. '''Class to handle all sensors'''
  7. def __init__(self) -> None:
  8. '''Init all Sensors'''
  9. #Message if Error
  10. #Air Temperature & Humidity
  11. self.dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
  12. #global Variables
  13. self.sensorData ={
  14. "Air Temperature" : 0,
  15. "Air Humidity" : 0,
  16. "Earth Humidity" : 0,
  17. "Brightness" : 0
  18. }
  19. def readSensors(self):
  20. '''Read all Sensors and return Dictionary with data'''
  21. #read DHT22
  22. #if Error reading Data try again
  23. while True:
  24. try:
  25. self.sensorData["Air Temperature"] = self.dht22.temperature
  26. self.sensorData["Air Humidity"] = self.dht22.humidity
  27. except:
  28. continue
  29. break
  30. return self.sensorData
  31. def takePicture(self):
  32. '''Take picture and return image'''
  33. return self.image
  34. def readPosition(self):
  35. '''Read and return Position'''
  36. return self.position
  37. #for Testing only
  38. def main():
  39. sensors = RaspySensors()
  40. test = sensors.readSensors()
  41. print("Data:" + json.dumps(test))
  42. if __name__ == "__main__":
  43. main()