先上图,就图里这款水质检测,用树莓派3/4的话,要配个温度检测作为温度校正,以及一个adc 元器件。我选ds18b20和ads1115。
再把模拟数据计算过程放一下:
温度检测元器件在农历钟那里提过,就是同款。此处先测个温度,为了拿当前的温度修正数。得到当前温度26.75,减去它的默认温度25度,得到1.75。温度修正常数 = 1+0.02*1.75 = 1.035;
接下来是换算电压的办法,针对ads1115,选择增益是1的情况,用下面的小程序测得bits在989~991之间晃,所以就取个990。
- import Adafruit_ADS1x15
- # 增益
- # 2/3 = +/-6.144V
- # 1 = +/-4.096V
- # 2 = +/-2.048V
- # 4 = +/-1.024V
- # 8 = +/-0.512V
- # 16 = +/-0.256V
-
- GAIN = 1
- adc1 = Adafruit_ADS1x15.ADS1115(address=0x48)
- while True:
- #
- # A0 = Channel 0 minus channel 1
- # A1 = Channel 0 minus channel 3
- # A2 = Channel 1 minus channel 3
- # A3 = Channel 2 minus channel 3
- # data_rate=128 为每秒返回样本数 最高为860
- print(adc1.read_adc(0, gain=GAIN, data_rate=128))
电压公式参考:
(990*4.096)/32767 = 0.1238V
继续根据datasheet往下算电压修正值:
电压修正值 = 1.035*0.1238v = 0.128v
再算TDS修正计算值:66.71*(0.128)^3 - 127.93*(0.128)^2 + 428.7 * 0.128 = 52.92ppm
神数弄不懂,就搞搞常数吧!