29_environmentDetection.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. #version : 2023.12.31
  3. #language : ch
  4. import sys
  5. import time
  6. from maix import display,image,camera
  7. sys.path.append('/root/')
  8. from CocoPi import AHT20
  9. image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
  10. class v83x_ADC():
  11. def __init__(self, addr=b"0x05070080") -> None:
  12. self.addr = addr
  13. self.path = "/sys/class/sunxi_dump/dump"
  14. self.file = open(self.path, "wb+")
  15. self.last = self.value()
  16. def __del__(self):
  17. try:
  18. if self.file:
  19. self.file.close()
  20. del self.file
  21. except Exception as e:
  22. pass
  23. def value(self):
  24. self.file.write(b"0x05070080")
  25. self.file.seek(0)
  26. return int(self.file.read()[:-1], 16)
  27. v831_adc0 = v83x_ADC()
  28. aht20 = AHT20(2) #创建温湿度传感器对象
  29. def aht20Test():
  30. global aht20,img_backdrop
  31. from maix import display
  32. h=round(aht20.get_humidity(),2)+10.00
  33. t=round(aht20.get_temperature()-15,2)
  34. img_backdrop.draw_string(16, 108, "原始湿度值:"+str(h)+"RH%", scale = 1.0,color = (0, 255, 0), thickness = 1)
  35. img_backdrop.draw_string(16, 132, "原始温度值:"+str(t)+"℃", scale = 1.0,color = (0, 255, 0), thickness = 1)
  36. camera.camera.config(size=(320, 240))
  37. img_backdrop = image.new(size=(320, 240),color = (15,21,46),mode = "RGB")
  38. while True:
  39. img_backdrop.clear()
  40. img_backdrop = image.new(size=(320, 240),color = (15,21,46),mode = "RGB")
  41. aht20Test()
  42. v=v831_adc0.value()
  43. img_backdrop.draw_string(16, 84, "原始光照强度值:"+str(v), scale = 1.0,color = (0, 255, 0), thickness = 1)
  44. img_backdrop.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
  45. display.show(img_backdrop)
  46. time.sleep(0.5)