Adding I2C IIC Analog to Digital ADC PGA Converter

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
rkompass
Posts: 66
Joined: Fri Sep 17, 2021 8:25 pm

Re: Adding I2C IIC Analog to Digital ADC PGA Converter

Post by rkompass » Fri Jan 07, 2022 9:41 pm

I forgot a

Code: Select all

sleep_ms(1000)
at the end of the while loop in my last posting.
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 2 as the third argument means that 32768 corresponds to 2.048 volts, the signal is amplified by a factor of 2 before taken to actual internal measurement.
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
takes the amplification factors from an internal table and the stored gain argument and multiplies it with the raw value (which should come from a read()).

----------
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.

soggycashew
Posts: 55
Joined: Sat Sep 18, 2021 10:21 pm

Re: Adding I2C IIC Analog to Digital ADC PGA Converter

Post by soggycashew » Fri Jan 07, 2022 10:02 pm

@rkompass im going to have two in parallel. I wanted to display values on a 4x20 LCD or a waveshare 1.3 which i have both. Thank you for the help, there isnt very much tutorials out there on micropython!

Post Reply