1.将土壤湿度 的vcc、gnd、Ao分别接入到haas506的3.3v、gnd、和ADC0上
2.将光敏模块的vcc、gnd、Ao分别接入到haas506的3.3v、gnd、和ADC1上

coding=utf-8
# This is a sample Python script.
#实测土壤湿度 最大值为3193(最干),最小值1510(最湿)
#实测亮度 最大值为3000(最暗) ,最小值为20(最亮)
#使用adc0检测土壤湿度,value0是湿度值
#使用adc1检测亮度,value1是光线强度值

1.JPG2.jpg3.jpg4.jpg
board.json

  1. {
  2. "name": "haas506",
  3. "version": "1.0.0",
  4. "io": {
  5. "ADC0": {
  6. "type": "ADC",
  7. "port": 0,
  8. "sampling": 12000000
  9. },
  10. "ADC1": {
  11. "type": "ADC",
  12. "port": 1,
  13. "sampling": 12000000
  14. },
  15. "serial1": {
  16. "type": "UART",
  17. "port": 0,
  18. "dataWidth": 8,
  19. "baudRate": 115200,
  20. "stopBits": 1,
  21. "flowControl": "disable",
  22. "parity": "none",
  23. "timeout": 1000
  24. },
  25. "serial2": {
  26. "type": "UART",
  27. "port": 1,
  28. "dataWidth": 8,
  29. "baudRate": 9600,
  30. "stopBits": 1,
  31. "flowControl": "disable",
  32. "parity": "none",
  33. "timeout": 1000
  34. },
  35. "serial3": {
  36. "type": "UART",
  37. "port": 2,
  38. "dataWidth": 8,
  39. "baudRate": 115200,
  40. "stopBits": 1,
  41. "flowControl": "disable",
  42. "parity": "none",
  43. "timeout": 1000
  44. }
  45. },
  46. "debugLevel": "ERROR",
  47. "repl": "enable",
  48. "replPort": 0
  49. }

main.py

  1. # coding=utf-8
  2. # This is a sample Python script.
  3. #实测土壤湿度 最大值为3193(最干),最小值1510(最湿)
  4. #实测亮度 最大值为3000(最暗) ,最小值为20(最亮)
  5. #使用adc0检测土壤湿度,value0是湿度值
  6. #使用adc1检测亮度,value1是光线强度值
  7. from driver import ADC
  8. import utime as time
  9. print("-------------------start adc test--------------------")
  10. adc0 = ADC()
  11. adc0.open("ADC0")
  12. adc1=ADC()
  13. adc1.open("ADC1")
  14. while True:
  15. time.sleep(1)
  16. value0=adc0.read()
  17. value1=adc1.read()
  18. print(' 土壤湿度:',value0,'光照强度:',value1)
  19. #获取到湿度数据 和光照强度数据后,执行相应的操作
  20. #如当土壤湿度很低时,提醒浇水
  21. if value0<1600:
  22. print("土壤很湿")
  23. elif value0>3000:
  24. print("土壤很干")
  25. if value1<50:
  26. print("光线很足")
  27. elif value1>2900:
  28. print("光线很暗")