Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ Single Ended
.. code-block:: python

import time

import board
import busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create the ADC object using the I2C bus
ads = ADS.ADS1015(i2c)
ads = ADS1015(i2c)

# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# Create differential input between channel 0 and 1
#chan = AnalogIn(ads, ADS.P0, ADS.P1)
# chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1)

print("{:>5}\t{:>5}".format('raw', 'v'))
print("{:>5}\t{:>5}".format("raw", "v"))

while True:
print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
Expand Down
19 changes: 19 additions & 0 deletions adafruit_ads1x15/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries
# SPDX-FileCopyrightText: 2025 Asadullah Shaikh <github.com/pantheraleo-7>
#
# SPDX-License-Identifier: MIT

"""
`adafruit_ads1x15`
====================================================
Support for the ADS1x15 series of analog-to-digital converters.
* Author(s): Carter Nelson
"""

from .ads1015 import ADS1015
from .ads1115 import ADS1115
from .analog_in import AnalogIn

__all__ = ["ADS1015", "ADS1115", "AnalogIn"]
10 changes: 0 additions & 10 deletions adafruit_ads1x15/ads1015.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@
3300: 0x00C0,
}

# Pins
P0 = 0
"""Analog Pin 0"""
P1 = 1
"""Analog Pin 1"""
P2 = 2
"""Analog Pin 2"""
P3 = 3
"""Analog Pin 3"""


class ADS1015(ADS1x15):
"""Class for the ADS1015 12 bit ADC."""
Expand Down
10 changes: 0 additions & 10 deletions adafruit_ads1x15/ads1115.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
860: 0x00E0,
}

# Pins
P0 = 0
"""Analog Pin 0"""
P1 = 1
"""Analog Pin 1"""
P2 = 2
"""Analog Pin 2"""
P3 = 3
"""Analog Pin 3"""


class ADS1115(ADS1x15):
"""Class for the ADS1115 16 bit ADC."""
Expand Down
25 changes: 17 additions & 8 deletions adafruit_ads1x15/ads1x15.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
from typing import Dict, List, Optional

from busio import I2C
from microcontroller import Pin
except ImportError:
# define Pin to avoid the error:
# def read(self, pin: Pin, is_differential: bool = False) -> int:
# NameError: name 'Pin' is not defined
Pin = None
pass

_ADS1X15_DEFAULT_ADDRESS = const(0x48)
_ADS1X15_POINTER_CONVERSION = const(0x00)
Expand All @@ -54,6 +50,19 @@
}


class Pin:
"""An enum-like class representing possible ADC pins."""

A0 = 0
"""Analog Pin 0"""
A1 = 1
"""Analog Pin 1"""
A2 = 2
"""Analog Pin 2"""
A3 = 3
"""Analog Pin 3"""


class Mode:
"""An enum-like class representing possible ADC operating modes."""

Expand Down Expand Up @@ -127,7 +136,7 @@ class ADS1x15:

def __init__(
self,
i2c: I2C,
i2c: "I2C",
gain: float = 1,
data_rate: Optional[int] = None,
mode: int = Mode.SINGLE,
Expand Down Expand Up @@ -312,7 +321,7 @@ def comparator_latch(self, comp_latch: int) -> None:
if self.initialized:
self._write_config()

def read(self, pin: Pin) -> int:
def read(self, pin: Optional[int]) -> int:
"""I2C Interface for ADS1x15-based ADCs reads.

:param ~microcontroller.Pin pin: individual or differential pin.
Expand All @@ -332,7 +341,7 @@ def _conversion_value(self, raw_adc: int) -> int:
"""
raise NotImplementedError("Subclass must implement _conversion_value function!")

def _read(self, pin: Pin) -> int:
def _read(self, pin: Optional[int]) -> int:
"""Perform an ADC read. Returns the signed integer result of the read."""
# Immediately return conversion register result if in CONTINUOUS mode
# and pin has not changed
Expand Down
12 changes: 5 additions & 7 deletions examples/ads1x15_ads1115_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
import time

import board
import busio

import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15 import ADS1115, AnalogIn, ads1x15

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)
ads = ADS1115(i2c)
# you can specify an I2C adress instead of the default 0x48
# ads = ADS.ADS1115(i2c, address=0x49)

# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# Create differential input between channel 0 and 1
# chan = AnalogIn(ads, ADS.P0, ADS.P1)
# chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1)

print("{:>5}\t{:>5}".format("raw", "v"))

Expand Down
23 changes: 9 additions & 14 deletions examples/ads1x15_comparator_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,35 @@
import time

import board
import busio
import countio

import adafruit_ads1x15.ads1015 as ADS

# import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.ads1x15 import Comp_Latch, Comp_Mode, Comp_Polarity, Mode
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create the ADS object
ads = ADS.ADS1015(i2c)
ads = ADS1015(i2c)
# ads = ADS.ADS1115(i2c)

# Create a single-ended channel on Pin 0
# Create a single-ended channel on Pin A0
# Max counts for ADS1015 = 2047
# ADS1115 = 32767
chan = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# Create Interrupt-driven input to track comparator changes
int_pin = countio.Counter(board.GP9, edge=countio.Edge.RISE)

# Set ADC to continuously read new data
ads.mode = Mode.CONTINUOUS
ads.mode = ads1x15.Mode.CONTINUOUS
# Set comparator to assert after 1 ADC conversion
ads.comparator_queue_length = 1
# Set comparator to use traditional threshold instead of window
ads.comparator_mode = Comp_Mode.TRADITIONAL
ads.comparator_mode = ads1x15.Comp_Mode.TRADITIONAL
# Set comparator output to de-assert if readings no longer above threshold
ads.comparator_latch = Comp_Latch.NONLATCHING
ads.comparator_latch = ads1x15.Comp_Latch.NONLATCHING
# Set comparator output to logic LOW when asserted
ads.comparator_polarity = Comp_Polarity.ACTIVE_LOW
ads.comparator_polarity = ads1x15.Comp_Polarity.ACTIVE_LOW
# Gain should be explicitly set to ensure threshold values are calculated correctly
ads.gain = 1
# Set comparator low threshold to 2V
Expand Down
14 changes: 6 additions & 8 deletions examples/ads1x15_fast_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import board
import busio

import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.ads1x15 import Mode
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15

# Data collection setup
RATE = 3300
Expand All @@ -21,18 +19,18 @@
i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000)

# Create the ADC object using the I2C bus
ads = ADS.ADS1015(i2c)
ads = ADS1015(i2c)

# Create single-ended input on channel 0
chan0 = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# ADC Configuration
ads.mode = Mode.CONTINUOUS
ads.mode = ads1x15.Mode.CONTINUOUS
ads.data_rate = RATE

# First ADC channel read in continuous mode configures device
# and waits 2 conversion cycles
_ = chan0.value
_ = chan.value

sample_interval = 1.0 / ads.data_rate

Expand All @@ -51,7 +49,7 @@
pass

# Read conversion value for ADC channel
data[i] = chan0.value
data[i] = chan.value

# Loop timing
time_last_sample = time.monotonic()
Expand Down
13 changes: 5 additions & 8 deletions examples/ads1x15_gain_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
import time

import board
import busio

# import adafruit_ads1x15.ads1015 as ADS
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15 import ADS1115, AnalogIn, ads1x15

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create the ADS object
# ads = ADS.ADS1015(i2c)
ads = ADS.ADS1115(i2c)
ads = ADS1115(i2c)

# Create a single-ended channel on Pin 0
# Create a single-ended channel on Pin A0
# Max counts for ADS1015 = 2047
# ADS1115 = 32767
chan = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# The ADS1015 and ADS1115 both have the same gain options.
#
Expand Down
12 changes: 5 additions & 7 deletions examples/ads1x15_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
import time

import board
import busio

import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15 import ADS1015, AnalogIn, ads1x15

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()

# Create the ADC object using the I2C bus
ads = ADS.ADS1015(i2c)
ads = ADS1015(i2c)

# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)
chan = AnalogIn(ads, ads1x15.Pin.A0)

# Create differential input between channel 0 and 1
# chan = AnalogIn(ads, ADS.P0, ADS.P1)
# chan = AnalogIn(ads, ads1x15.Pin.A0, ads1x15.Pin.A1)

print("{:>5}\t{:>5}".format("raw", "v"))

Expand Down