Adafruit ADS1x15 CircuitPython Library

repository·main·Indexed 41 days ago

https://github.com/adafruit/adafruit_circuitpython_ads1x15

CircuitPython library for controlling ADS1x15 series analog-to-digital converters, including the 12-bit ADS1015 and 16-bit ADS1115 models. Supports single-ended and differential analog inputs via I2C.

Tokens
794
Snippets
3
Records
3
Agent score
50%

What's inside ADS1x15

  1. Install the adafruit-circuitpython-ads1x15 driver

    main

    You can install the driver via PyPI on supported GNU/Linux systems like the Raspberry Pi.

    To install for the current user:

    pip3 install adafruit-circuitpython-ads1x15

    To install system-wide:

    sudo pip3 install adafruit-circuitpython-ads1x15

    To install within a virtual environment:

    mkdir project-name && cd project-name
    python3 -m venv .venv
    source .venv/bin/activate
    pip3 install adafruit-circuitpython-ads1x15

    Note: This driver depends on Adafruit CircuitPython and Bus Device. Ensure these dependencies are available on your CircuitPython filesystem, ideally by using the Adafruit library and driver bundle.

    pip3 install adafruit-circuitpython-ads1x15
  2. Verify ADS1x15 functionality with simple test examples

    main

    You can verify that your ADS1x15 device (ADS1015 or ADS1115) is working correctly by running the provided simple test scripts. These scripts are designed to perform basic communication and read values to ensure the hardware and I2C bus are properly configured.

    Depending on your specific chip, use the corresponding example:

    • For ADS1015: examples/ads1x15_ads1015_simpletest.py
    • For ADS1115: examples/ads1x15_ads1115_simpletest.py
    # Example of what a simple test might look like (referencing the included examples)
    # For ADS1015:
    # examples/ads1x15_ads1015_simpletest.py
    
    # For ADS1115:
    # examples/ads1x15_ads1115_simpletest.py
  3. Use the ADS1x15 for single-ended and differential analog input

    main

    The adafruit_ads1x15 library supports both 12-bit (ADS1015) and 16-bit (ADS1115) ADC versions.

    To use the library:

    1. Initialize the I2C bus using board.I2C().
    2. Instantiate the ADC object (e.g., ADS1015(i2c)).
    3. Create an AnalogIn object to read from specific pins.

    Single-ended input: Pass one pin to AnalogIn. Differential input: Pass two pins to AnalogIn to measure the voltage difference between them.

    Use chan.value to get the raw ADC value and chan.voltage to get the calculated voltage.

    import time
    import board
    from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15
    
    # Create the I2C bus
    i2c = board.I2C()
    
    # Create the ADC object using the I2C bus
    ads = ADS1015(i2c)
    
    # Create single-ended input on channel 0
    chan = AnalogIn(ads, ads1x15.Pin.A0)
    
    # To use differential input instead, use:
    # chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1)
    
    print("{:>5}\t{:>5}".format("raw", "v"))
    
    while True:
        print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
        time.sleep(0.5)