Code: Select all
sleep_ms(1000)
How many ADS1115s do you want to use in parallel, b.t.w.?
The read() function gives you a 16 bit value read from the ADC in the sense that a positive voltage ranges from 1..32767 and a negative voltage from -1..-32768. To interpret it you have to take the gain set for the adjustable gain amplifier into account. A gain code 1 is set in the instantiation of the ADC object:
Code: Select all
adc0 = ADS1115(i2c2, 0x48, 1) # Gain = 1, 32768 ^⁼ 4.096 v
A 3 as the third argument means that 32768 corresponds to 1.024 volts, the signal is amplified by a factor of 4 before taken to actual internal measurement.
...
The maximum is 5, 32768 the corresponds to 0.256 volts, the signal is amplified by 16.
The raw_to_v() function:
Code: Select all
def raw_to_v(self, raw):
v_p_b = _GAINS_V[self.gain] / 32767
return raw * v_p_b
----------
To continue from here you should know of the range of possible voltages you moisture sensors may deliver to decide for a gain setting. If the voltages differ only very little it should be better to set a higher gain.
The gain setting determines the resolution.
With gain setting 1 (i.e. gain = 1) you can discriminate (theoretically, ignoring noise in the measurement) voltage differences of 4.096/32768 = 0.125 millivolts.
With gain setting 5 (i.e. gain = 16) you can discriminate (theoretically, ignoring noise in the measurement) voltage differences of 0.256 /32768 = 7.81 microvolts.
So higher gains make your measurements more sensitive, at the cost of allowing only for smaller overall input range.