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.5KB

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