ADS1115 conversion ownership: read the channel you actually requested

Download and extract the reader ZIP archive (a compressed collection of files). Links labelled “reader ZIP; extract …” download this archive; after extraction, open the named file. It includes the offline article, full-size Portable Network Graphics (PNG) images, editable Scalable Vector Graphics (SVG) diagrams, complete source code, tests and worksheets.

A channel label belongs to the conversion that finished, not simply to the configuration you most recently wrote. Build two distinct voltage inputs and use a driver that drains inherited work before starting its own single conversion.

Verification scope: the delivered acquisition logic has executable host tests using a constructed bus. This is a locally prepared design. No Pico execution, target firmware build, measured accuracy, physical circuit test or WordPress deployment is claimed.

Why changing a channel can produce a convincing wrong answer

An analog-to-digital converter (ADC) turns an input voltage into a number. The ADS1115 contains a multiplexer (MUX), a selector that connects one input pair to the converter. Its result register holds the most recently completed conversion; a register is a small numbered storage location inside the chip. Writing a new selection does not attach a channel name to the old result.

Imagine an old conversion of input 1 is still running when the program requests input 0. A configuration write can succeed while that earlier conversion is unfinished. Reading the result immediately can return an older value, and starting a single shot while the converter is busy does not establish a new shot. The exercise makes this mistake visible with inputs near 1.1 V and 2.2 V, rather than two nearly identical sensor outputs.

Here ownership means that one driver establishes an idle boundary, launches a known conversion and associates a label only with its completion. It is a software invariant under an exclusive-access assumption: no second program, interrupt handler, core, thread or bus controller may reconfigure this ADS1115. A check of configuration bits detects some interference; it cannot detect every concurrent writer that restores the same bits.

Use the exact part and keep its inputs within the supply rails

The design uses Texas Instruments ADS1115IDGST in the DGS, 10-pin Very Thin Shrink Small Outline Package (VSSOP), mounted on an unpowered pin-for-pin adapter with no added pull-ups or regulator. It uses an original Raspberry Pi Pico and MicroPython 1.29.0. An integrated circuit is the semiconductor device inside the package. Inspect the adapter orientation and continuity before applying power; a generic module with an unknown chip, extra resistors or 5 V pull-ups is a different circuit.

The checked manufacturer document is ADS111x data sheet SBAS444E, revised December 2024, especially sections 4, 5.3, 7.4.2 and 8.1. Its current product-page documentation listing did not expose a separate device errata document during this preparation; that is a search result, not a guarantee that none exists.

The programmable gain amplifier (PGA) selects the numerical voltage span. We fix it at ±4.096 V and 128 samples per second (SPS), meaning 128 completed conversions per second in continuous operation. The chip uses an internal voltage reference, not the Pico supply as its conversion reference. The ±4.096 V scale does not permit an input above a 3.3 V supply: each analog pin must remain between ground (GND), the circuit return, and the positive power-supply pin VDD during normal operation. The normal supply range is 2.0–5.5 V. Absolute maximum ratings are damage boundaries, not operating targets; the fixture stays on its 3.3 V rails.

Parts and exact connections

Use one Pico with headers, the exact ADS1115 and adapter, four 1% resistors rated at least 0.125 W (two 1.00 kΩ and two 2.00 kΩ), two 4.70 kΩ pull-up resistors, a 100 nF ceramic capacitor, a breadboard and short wires. A digital multimeter is useful for checking the two voltages but is not needed for the offline tests. Power the Pico through its Universal Serial Bus (USB) connector. Use its 3V3 OUT pin, never VBUS, to power this fixture.

The Inter-Integrated Circuit (I²C) bus carries commands over two shared wires. Serial data (SDA) carries bits, and serial clock (SCL) times them. A pull-up resistor brings an undriven bus wire high; the devices pull it low to signal. General-purpose input/output (GPIO) pins are the Pico’s configurable digital connections. In the table GP0 and GP1 are GPIO names; the physical pin numbers refer to the Pico header.

NC means no connection: that pin is intentionally left open.

Connection Exact endpoints and purpose
3V3 Pico physical 36 (3V3 OUT) → ADS1115 pin 8 VDD; also the top of both dividers and both bus pull-ups.
GND Pico physical 38 → ADS1115 pin 3; divider bottoms, capacitor return, pin 1 ADDR, pins 6 AIN2 and 7 AIN3 all join ground.
SDA Pico GP0 physical 1 → ADS1115 pin 9; R5 4.70 kΩ from this net to 3V3.
SCL Pico GP1 physical 2 → ADS1115 pin 10; R6 4.70 kΩ from this net to 3V3.
A0 divider 3V3 → R1 2.00 kΩ → A0 → R2 1.00 kΩ → GND. A0 → ADS1115 pin 4 AIN0.
A1 divider 3V3 → R3 1.00 kΩ → A1 → R4 2.00 kΩ → GND. A1 → ADS1115 pin 5 AIN1.
C1 100 nF directly between ADS1115 pins 8 and 3, close to the device.
Unused output Pin 2 ALERT/RDY is no connection (NC); comparator output is disabled in software.

ADDR is the address-selection input. Grounding it selects seven-bit address 0x48; the prefix 0x denotes hexadecimal notation. Do not shift this address before passing it to MicroPython. The names A0 and A1 in this fixture denote divider nets, not Pico analog pins. NC means no connection; the disabled ALERT/RDY output is intentionally left open.

Exact ADS1115IDGST pin connections, two 1.1 and 2.2 volt divider inputs, Pico bus and supply support — reader ZIP; extract assets/ads1115-two-level-fixture.png
Original functional schematic. Matching named ports join the same net; ground symbols share ground. Values at the dividers are calculated, not measured. Editable original — reader ZIP; extract assets/ads1115-two-level-fixture.svg · Full size — reader ZIP; extract assets/ads1115-two-level-fixture.png

Calculate the two levels before reading them

A voltage divider is two series resistors with an output at their junction. Ignoring converter loading, Vout = Vsupply × Rbottom / (Rtop + Rbottom). At an assumed 3.300 V, A0 = 3.300 × 1/3 = 1.100 V, and A1 = 3.300 × 2/3 = 2.200 V. Each branch draws 3.300/3000 = 1.10 mA. The largest resistor dissipation is (1.10 mA)² × 2000 Ω = 2.42 mW, well below the chosen rating.

The source resistance seen at either junction is Rtop in parallel with Rbottom: 2 kΩ × 1 kΩ / 3 kΩ = 667 Ω. The converter’s switched input draws charge during conversion, so a divider is not a precision reference and this estimate is not a complete settling model. Use short wires; compare measured input voltages with codes rather than claiming every supply is exactly 3.300 V. Resistor tolerance, input loading, noise and the ADC’s errors all contribute. Supply drift changes these inputs because the ADC uses its own internal reference.

The least significant bit (LSB), the smallest code increment, represents 4.096/32768 = 125 μV at this range. The ideal codes are 8800 and 17600. The signed 16-bit result uses two’s complement: values with bit 15 set represent negative numbers. Single-ended inputs near ground can have a small negative code from offset and noise; negative code alone does not justify applying a negative voltage to a pin.

At 3.3 V, a low bus wire sinks approximately 3.3/4700 = 0.70 mA. With an assumed total bus capacitance of 100 pF, the approximate 30–70% rise time is 0.8473 × 4700 × 100 pF = 0.398 μs. That supports the selected 100 kHz bus in this assumed short-wire fixture; the capacitance was not measured. Extra module pull-ups change the load and must be included.

The acquisition boundary in the delivered driver

The operational status (OS) bit starts one conversion when written as 1 while the chip is idle. When read, 0 means converting and 1 means idle. MODE selects continuous or single-shot operation. A single shot performs one conversion and returns to the low-power idle state. The driver does the following for every channel:

  1. Write the requested configuration with MODE=1 and OS=0. This requests no new conversion and prevents subsequent continuous conversions. Wait for idle; discard the inherited result without reading it as a sample.
  2. Write the same configuration with OS=1. Require at least one observed busy status followed by idle, with matching lower configuration bits. This establishes the launched shot’s ownership.
  3. Require a 10 ms minimum interval as an additional guard, then read the result only after the status conditions have passed. Return its channel and a monotonically increasing successful-sample sequence number.

An inherited 8 SPS conversion can take about 1/(8 × 0.9) = 138.9 ms using the data-sheet rate variation, so draining gets a 200 ms software deadline. A new 128 SPS shot has nominal duration 7.8125 ms; the slow-rate calculation gives 8.681 ms, plus start-up, typically about 25 μs. The 10 ms guard and 30 ms completion deadline are engineering choices for this polling lesson, not a new manufacturer worst-case start-up specification. Both deadlines require a functioning bus and advancing clock.

The driver deliberately refuses a value if scheduling delays cause it to miss the entire busy interval. It can discard a valid completed result in that case; it does not silently relabel a stale one. A failed transaction, short read, changed configuration or deadline raises a fault, never a numeric fallback. The next call repeats the drain sequence, so a late result from a timed-out shot is discarded. MicroPython’s I²C operation timeout is separate: an OS deadline cannot interrupt a bus call that has not returned.

Constructed inherited AIN1 conversion completes before the owned AIN0 conversion starts; result identity changes only at completion
Constructed timing example, not a measured trace. The brief idle/start-up pulse is drawn wider for visibility and is not to scale; status polling and the minimum return guard are explained in the text. Editable original — reader ZIP; extract assets/conversion-ownership-timing.svg · Full size

Run the complete Pico program

Install the original-Pico MicroPython 1.29.0 release from the official Pico firmware page. Copy code/ads1115_owned.py to the board as ads1115_owned.py and code/main.py as main.py. The machine module controls board hardware; it cannot run on ordinary desktop Python. The following are both complete required files.

ads1115_owned.py

"""Exclusive ADS1115 single-shot owner, fixed +/-4.096 V, 128 samples/s.
Target: original Raspberry Pi Pico, MicroPython 1.29.0. Also host-testable.
One caller, one instance, no other writers to this address. Not thread-safe.
"""
class ConversionTimeout(Exception): pass
class OwnershipError(Exception): pass

def signed16(raw):
    return raw-65536 if raw & 0x8000 else raw

class RealClock:
    def ticks_ms(self):
        from time import ticks_ms
        return ticks_ms()
    def ticks_diff(self,a,b):
        from time import ticks_diff
        return ticks_diff(a,b)
    def sleep_ms(self,n):
        from time import sleep_ms
        sleep_ms(n)

class ADS1115:
    def __init__(self,bus,address=0x48,clock=None):
        self.bus=bus; self.address=address
        self.clock=clock if clock is not None else RealClock()
        self._active=False; self.sequence=0
    def _write(self,cfg):
        self.bus.writeto_mem(self.address,1,bytes((cfg>>8,cfg&255)))
    def _read(self,reg):
        b=self.bus.readfrom_mem(self.address,reg,2)
        if len(b)!=2: raise OSError('short ADS1115 read')
        return (b[0]<<8)|b[1]
    def _ready(self,cfg,limit_ms,min_ms=0,require_busy=False):
        start=self.clock.ticks_ms(); saw_busy=False
        while True:
            c=self._read(1)
            if c & 0x7fff != cfg & 0x7fff:
                raise OwnershipError('configuration changed; discard sample')
            if not c&0x8000: saw_busy=True
            elapsed=self.clock.ticks_diff(self.clock.ticks_ms(),start)
            if elapsed>=limit_ms: raise ConversionTimeout('ADS1115 busy or no confirmed result')
            if elapsed>=min_ms and c&0x8000 and (saw_busy or not require_busy): return
            self.clock.sleep_ms(1)
    def read(self,channel):
        if type(channel) is not int or not 0<=channel<=3: raise ValueError('channel 0..3 required')
        if self._active: raise OwnershipError('acquisition already active')
        self._active=True
        try:
            # OS=0 requests no conversion. MODE=1 stops future continuous shots.
            # Any already-running shot may still belong to the previous config.
            cfg=((4+channel)<<12)|0x0200|0x0100|0x0080|0x0003
            self._write(cfg)
            self._ready(cfg,200)  # drains an inherited slow (8 samples/s) shot
            self._write(cfg|0x8000)
            # A 10 ms guard exceeds 1/(128*0.9) s = 8.681 ms plus
            # the typical 25 us start-up. Still require OS=1; guard alone
            # is never evidence of completion. Require observed busy then ready.
            # A missed busy interval fails closed, without a numeric sample.
            self._ready(cfg,30,10,True)
            raw=signed16(self._read(0))
            self.sequence+=1
            return {'sequence':self.sequence,'channel':channel,
                    'raw':raw,'volts':raw*(4.096/32768)}
        finally:
            self._active=False

main.py

"""Copy this and ads1115_owned.py to an original Pico running MicroPython 1.29.0."""
from machine import Pin,I2C
from time import sleep_ms
from ads1115_owned import ADS1115,ConversionTimeout,OwnershipError

bus=I2C(0,sda=Pin(0),scl=Pin(1),freq=100000,timeout=50000)
adc=ADS1115(bus)
print('sequence,channel,raw,volts')
try:
    while True:
        for channel in (0,1):
            try:
                r=adc.read(channel)
                print('%d,%d,%d,%.6f' % (r['sequence'],r['channel'],r['raw'],r['volts']))
            except (OSError,ConversionTimeout,OwnershipError) as e:
                print('FAULT channel=%d: %s; no numeric sample' % (channel,e))
                sleep_ms(250)
        sleep_ms(500)
except KeyboardInterrupt:
    print('Stopped; converter left in single-shot mode.')

Bench procedure and fault controls

  1. Disconnect USB. Check the adapter’s pin 1 mark, 3V3/GND continuity and absence of a supply short. Verify both divider resistor orders. Attach the capacitor and pull-ups.
  2. Connect USB. Measure supply, A0 and A1 relative to the same ground with the multimeter set for direct-current voltage. Keep its red lead in the voltage socket. Record the actual values in the blank worksheet — reader ZIP; extract data/bench-observations.csv.
  3. Start the program. Expect alternating channel labels and levels close to the measured inputs; values above are predictions. Compare raw × 125 μV with each input measurement.
  4. Stop the program, remove power, exchange the two divider signal wires at pins 4 and 5, then restore power. The two channel voltages should exchange while labels continue to alternate. Reversing resistor order is a separate test; change one thing at a time.
  5. Stop and power down before removing SDA. On restart the bus should report a fault rather than print a replacement voltage. Restore wiring with power off. Never use an intentional rail short as a fault control.

The bench experiment validates a particular assembly only when you actually perform it. It does not reproduce every internal race. Use the offline suite to force an inherited slow shot, a late completion and ignored start request reproducibly without manipulating a powered breadboard.

Reproduce the software checks without a board

From the extracted reader directory, run:

python3 -m unittest discover -s code -p 'test_*.py' -v
python3 code/run_constructed.py

The 18 tests exercise the actual delivered acquisition driver through code/fake_ads1115.py. The fake preserves an in-flight channel when configuration changes, ignores a busy start request, retains the old result until completion and injects stuck/bus/configuration faults. It is a constructed state machine, not a transistor, analog-settling or electrical bus simulation. The demonstrator output is marked CONSTRUCTED and is saved separately from the blank bench sheet.

Challenge: a successful write, a wrong label

An AIN1 conversion has 70 ms left. You write AIN0, MODE=1 and OS=1, wait 10 ms and label the next register read AIN0. Is the label defensible?

Answer

No. The shot in flight can still use the previous selection, and OS=1 while busy does not launch the owned shot. Drain to idle, start again from idle and confirm the new conversion before reading. The configuration register alone does not say which input produced the conversion register’s current number.

Sources, files and what remains unverified

Read the source index — reader ZIP; extract source-index.html for exact manufacturer sections, the official Pico pinout and runtime documentation. This reader includes Hypertext Markup Language (HTML) article and preview files, Portable Network Graphics (PNG) images, editable Scalable Vector Graphics (SVG) originals, full code, a blank comma-separated values (CSV) worksheet and host evidence. README.txt — reader ZIP; extract README.txt lists case-sensitive paths. New terminology is proposed for the coordinated Circuitpedia workflow; no dictionary deployment is implied.

Physical measurements, target execution/build, browser layout acceptance and native post state remain separate gates. There is no article canonical URL or Facebook delivery in this local package.

📡Broadcast the signal — amplify the connection.

Leave a Reply