Skip to content

Interface change for #17 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 3, 2018
Merged
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
36 changes: 17 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,29 @@ Single Ended

.. code-block:: python

import board
import busio
from adafruit_ads1x15.single_ended import ADS1015
import time
import board
import busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

i2c = busio.I2C(board.SCL, board.SDA)
adc = ADS1015(i2c)
while True:
# channel 0
print(adc[0].value, adc[0].volts)
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

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

.. code-block:: python
# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)

import board
import busio
from adafruit_ads1x15.differential import ADS1015
# Create differential input between channel 0 and 1
#chan = AnalogIn(ads, ADS.P0, ADS.P1)

i2c = busio.I2C(board.SCL, board.SDA)
adc = ADS1015(i2c)
while True:
# channel 0 - channel 1
print(adc[(0,1)].value, adc[(0,1)].volts)
print("{:>5}\t{:>5}".format('raw', 'v'))

while True:
print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
time.sleep(0.5)

Contributing
============
Expand Down
233 changes: 0 additions & 233 deletions adafruit_ads1x15/adafruit_ads1x15.py

This file was deleted.

76 changes: 76 additions & 0 deletions adafruit_ads1x15/ads1015.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Carter Nelson for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`ads1015`
====================================================

CircuitPython driver for ADS1015 ADCs.

* Author(s): Carter Nelson
"""
import struct
from .ads1x15 import ADS1x15

# Data sample rates
_ADS1015_CONFIG_DR = {
128: 0x0000,
250: 0x0020,
490: 0x0040,
920: 0x0060,
1600: 0x0080,
2400: 0x00A0,
3300: 0x00C0
}

# Pins
P0 = 0
P1 = 1
P2 = 2
P3 = 3

class ADS1015(ADS1x15):
"""Class for the ADS1015 12 bit ADC."""

@property
def bits(self):
"""The ADC bit resolution."""
return 12

@property
def rates(self):
"""Possible data rate settings."""
r = list(_ADS1015_CONFIG_DR.keys())
r.sort()
return r

@property
def rate_config(self):
"""Rate configuration masks."""
return _ADS1015_CONFIG_DR

def _data_rate_default(self):
return 1600

def _conversion_value(self, raw_adc):
raw_adc = raw_adc.to_bytes(2, "big")
value = struct.unpack(">h", raw_adc)[0]
return value >> 4
Loading