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是光线强度值
board.json
{
"name": "haas506",
"version": "1.0.0",
"io": {
"ADC0": {
"type": "ADC",
"port": 0,
"sampling": 12000000
},
"ADC1": {
"type": "ADC",
"port": 1,
"sampling": 12000000
},
"serial1": {
"type": "UART",
"port": 0,
"dataWidth": 8,
"baudRate": 115200,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
},
"serial2": {
"type": "UART",
"port": 1,
"dataWidth": 8,
"baudRate": 9600,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
},
"serial3": {
"type": "UART",
"port": 2,
"dataWidth": 8,
"baudRate": 115200,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
}
},
"debugLevel": "ERROR",
"repl": "enable",
"replPort": 0
}
main.py
# coding=utf-8
# This is a sample Python script.
#实测土壤湿度 最大值为3193(最干),最小值1510(最湿)
#实测亮度 最大值为3000(最暗) ,最小值为20(最亮)
#使用adc0检测土壤湿度,value0是湿度值
#使用adc1检测亮度,value1是光线强度值
from driver import ADC
import utime as time
print("-------------------start adc test--------------------")
adc0 = ADC()
adc0.open("ADC0")
adc1=ADC()
adc1.open("ADC1")
while True:
time.sleep(1)
value0=adc0.read()
value1=adc1.read()
print(' 土壤湿度:',value0,'光照强度:',value1)
#获取到湿度数据 和光照强度数据后,执行相应的操作
#如当土壤湿度很低时,提醒浇水
if value0<1600:
print("土壤很湿")
elif value0>3000:
print("土壤很干")
if value1<50:
print("光线很足")
elif value1>2900:
print("光线很暗")