- coding=utf-8# This is a sample Python script.#实测土壤湿度 最大值为3193(最干),最小值1510(最湿)#实测亮度 最大值为3000(最暗) ,最小值为20(最亮)#使用adc0检测土壤湿度,value0是湿度值#使用adc1检测亮度,value1是光线强度值
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 ADCimport utime as timeprint("-------------------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("光线很暗")
版权声明
本站仅做备份收录,仅供研究与教学参考之用。
读者将信息用于其他用途的,全部法律及连带责任由读者自行承担,本站不承担任何责任。









评论