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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #[ ]TODO 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. "Plant ID": 0,
  22. "Action ID": 0
  23. }
  24. def readSensors(self):
  25. '''Read all Sensors and return Dictionary with data'''
  26. #read DHT22
  27. #if Error reading Data try again
  28. while True:
  29. try:
  30. self.sensorData["Air Temperature [°C]"] = self.dht22.temperature
  31. self.sensorData["Air Humidity [%]"] = self.dht22.humidity
  32. except:
  33. continue
  34. break
  35. #read TSL2561
  36. self.sensorData["Brightness [Lux]"] = round(self.tsl2561.lux, 2)
  37. return self.sensorData
  38. #[ ]TODO - take picture function
  39. def takePicture(self):
  40. '''Take picture and return image'''
  41. return self.image
  42. #[ ]TODO
  43. def readPosition(self):
  44. '''Read and return Position'''
  45. return self.position
  46. #[ ]TODO
  47. def readBattery(self):
  48. '''Read and return battery of ev3'''
  49. return self.battery
  50. #for Testing only
  51. def main():
  52. sensors = RaspySensors()
  53. test = sensors.readSensors()
  54. print("Data:" + json.dumps(test))
  55. if __name__ == "__main__":
  56. main()