Coder Social home page Coder Social logo

adafruit_python_ads1x15's Introduction

DEPRECATED LIBRARY. Adafruit Python ADS1x15

This library has been deprecated! We are leaving this up for historical and research purposes but archiving the repository.

We are now only supporting the use of our CircuitPython libraries for use with Python.

Check out this guide for info on using character LCDs with the CircuitPython library: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15

adafruit_python_ads1x15's People

Contributors

caternuson avatar tdicola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_python_ads1x15's Issues

Error in Intel Edison

I am trying to run this code in Intel Edison with mraa library but it gives me error. Is not the library compatible with Intel Edison (Yocto Linux)?

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Intel Edison Yocto 1.7.3

  • Python version (run python -version or python3 -version): Python 2.7

  • Error message you are receiving, including any Python exception traces:
    root@gozdewbl:~# python ads1115.py
    Traceback (most recent call last):
    File "ads1115.py", line 7, in
    adc = Adafruit_ADS1x15.ADS1115()
    File "/usr/lib/python2.7/site-packages/Adafruit_ADS1x15-1.0.2-py2.7.egg/Adafruit_ADS1x15/ADS1x15.py", line 319, in init
    super(ADS1115, self).init(*args, **kwargs)
    File "/usr/lib/python2.7/site-packages/Adafruit_ADS1x15-1.0.2-py2.7.egg/Adafruit_ADS1x15/ADS1x15.py", line 82, in init
    self._device = i2c.get_i2c_device(address, **kwargs)
    File "/usr/lib/python2.7/site-packages/Adafruit_GPIO/I2C.py", line 63, in get_i2c_device
    busnum = get_default_bus()
    File "/usr/lib/python2.7/site-packages/Adafruit_GPIO/I2C.py", line 55, in get_default_bus
    raise RuntimeError('Could not determine default I2C bus for platform.')
    RuntimeError: Could not determine default I2C bus for platform.

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    import Adafruit_ADS1x15
    import mraa
    import time
    import numpy

led = mraa.Gpio(20)
adc = Adafruit_ADS1x15.ADS1115()

GAIN = 1
value = led.read()
adc0 = adc.read_adc(0, gain=GAIN)
voltage = (adc0 * 0.1875)/1000

while True:
led.write(1)
print "led: ", value
print "voltage: ", voltage
time.sleep(0.50)
led.write(0)
print "led: ", value
print "voltage: ", voltage
time.sleep(0.5)

PyPI improvements

While adding this package to Buildroot I've encountered following issues:

  • package name in JSON file is not the same as in setup.py, i.e. Adafruit-ADS1x15 vs Adafruit_ADS1x15

  • LICENSE file is missing in the PyPI tarball

The same is true for Adafruit_Python_GPIO package.

Voltage value instead of 16/15 bit Raw Values

Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi 3 with Raspbian operating system

Python version (run python -version or python3 -version): Python 2.7.13

Error message you are receiving, including any Python exception traces:

There is no error. I get the raw ADC values. What I am really interested in is getting the Voltage values i.e. Each raw value corresponds to which voltage value?

List the steps to reproduce the problem below (if possible attach code or commands
to run):
Run any of the Example sketches.

Sample time delay insufficient for normal tolerance

The time delay between i2c write and read operations is insufficient to cover the natural part to part variation of ADS1x15 devices. The consequence of this is that some parts return the previous reading whenever queried. This issue only becomes apparent if the gain value changes between two conversions as the value returned will be correct for the previous gain setting.

Currently a delay of (1.0/data_rate + 0.0001) is used. The datasheet for the ADC states that the sample rate varies up to +/-10%. So, to avoid this potential issue the delay should be changed to (1.0/(0.9*data_rate))

ADS1x15_CONFIG_GAIN gain=2/3 gives unexpected results

In line 34 of Adafruit_Python_ADS1x15/ADS1x15.py at 733d179bfca9aff1a8357dea3a2b12108e3801e9 · adafruit/Adafruit_Python_ADS1x15, dictionary keys are suspect:

ADS1x15_CONFIG_GAIN = {
    2/3: 0x0000,
    1:   0x0200,
    2:   0x0400,
    4:   0x0600,
    8:   0x0800,
    16:  0x0A00
}

This gives unexpected values of the ‘2/3’ key no matter what python version is used.

Python 2:

>>> ADS1x15_CONFIG_GAIN
{0: 0, 1: 512, 2: 1024, 4: 1536, 8: 2048, 16: 2560}

Python 3:

>>> ADS1x15_CONFIG_GAIN
{0.6666666666666666: 0, 1: 512, 2: 1024, 4: 1536, 8: 2048, 16: 2560}

Maybe make the keys strings?

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspbian GNU/Linux 9 (stretch)

  • Python version (run python -version or python3 -version): Python 3.5.3

  • Error message you are receiving, including any Python exception traces: divide by zero error

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run): related to using gain=2/3

Raspberry Pi 3 ADS1115 - Remote I/O error

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi 3 with Raspbian operating system

  • Python version (run python -version or python3 -version): Python 2.7.13

  • Error message you are receiving, including any Python exception traces:

pi@raspberrypi:~/Adafruit_Python_ADS1x15/examples $ python simpletest.py
Reading ADS1x15 values, press Ctrl-C to quit...
|      0 |      1 |      2 |      3 |
-------------------------------------
Traceback (most recent call last):
  File "simpletest.py", line 42, in <module>
    values[i] = adc.read_adc(i, gain=GAIN)
  File "build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py", line 192, in read_adc
  File "build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py", line 128, in _read
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 128, in writeList
  File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 274, in write_i2c_block_data
IOError: [Errno 121] Remote I/O error
  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
To install the library from source (recommended) run the following commands on a Raspberry Pi or other Debian-based OS system:

sudo apt-get install git build-essential python-dev
cd ~
git clone https://github.com/adafruit/Adafruit_Python_ADS1x15.git
cd Adafruit_Python_ADS1x15
sudo python setup.py install

ADS1115 with changed address

adc = ADS1015(address=0x49, busnum=1)
works, but I have a ADS1115 and get

adc = Adafruit_ADS1x15.ADS1115(address=0x49, busnum=1)
NameError: name 'Adafruit_ADS1x15' is not defined

Kernel = Linux 4.9.35-v7+

~/Adafruit_Python_ADS1x15$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to Adafruit_ADS1x15.egg-info/requires.txt
writing Adafruit_ADS1x15.egg-info/PKG-INFO
writing top-level names to Adafruit_ADS1x15.egg-info/top_level.txt
writing dependency_links to Adafruit_ADS1x15.egg-info/dependency_links.txt
reading manifest file 'Adafruit_ADS1x15.egg-info/SOURCES.txt'
writing manifest file 'Adafruit_ADS1x15.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/Adafruit_ADS1x15
copying build/lib.linux-armv7l-2.7/Adafruit_ADS1x15/ADS1x15.py -> build/bdist.linux-armv7l/egg/Adafruit_ADS1x15
copying build/lib.linux-armv7l-2.7/Adafruit_ADS1x15/__init__.py -> build/bdist.linux-armv7l/egg/Adafruit_ADS1x15
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py to ADS1x15.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/__init__.py to __init__.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_ADS1x15.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_ADS1x15.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_ADS1x15.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_ADS1x15.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_ADS1x15.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/Adafruit_ADS1x15-1.0.2-py2.7.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing Adafruit_ADS1x15-1.0.2-py2.7.egg
Removing /usr/local/lib/python2.7/dist-packages/Adafruit_ADS1x15-1.0.2-py2.7.egg
Copying Adafruit_ADS1x15-1.0.2-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adafruit-ADS1x15 1.0.2 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/Adafruit_ADS1x15-1.0.2-py2.7.egg
Processing dependencies for Adafruit-ADS1x15==1.0.2
Searching for Adafruit-GPIO==1.0.3
Best match: Adafruit-GPIO 1.0.3
Processing Adafruit_GPIO-1.0.3-py2.7.egg
Adafruit-GPIO 1.0.3 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.3-py2.7.egg
Searching for spidev==3.2
Best match: spidev 3.2
Processing spidev-3.2-py2.7-linux-armv7l.egg
spidev 3.2 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/spidev-3.2-py2.7-linux-armv7l.egg
Searching for Adafruit-PureIO==0.2.1
Best match: Adafruit-PureIO 0.2.1
Processing Adafruit_PureIO-0.2.1-py2.7.egg
Adafruit-PureIO 0.2.1 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/Adafruit_PureIO-0.2.1-py2.7.egg
Finished processing dependencies for Adafruit-ADS1x15==1.0.2

working with threads

Hello, thank you for your attention, this code is working great:

 import Adafruit_ADS1x15
 import time
 import threading
 from threading import Timer
 import RPi.GPIO as GPIO

 pin_activar_voltaje = 10

 GPIO.setwarnings(False)
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(pin_activar_voltaje,GPIO.OUT)

 adc_multi = Adafruit_ADS1x15.ADS1115(address=0x4B)

 while(1):
     GPIO.output(pin_activar_voltaje, True)
     temp = adc_multi.read_adc(0)
     print("voltaje_0: " + str(temp))
     GPIO.output(pin_activar_voltaje, False)
     leer_entradas = 0
     time.sleep(1)

But if you want to do the same with a thread, the result of adc_multi.read_adc (0) is 0 in many cases:

 import Adafruit_ADS1x15
 import time
 import threading
 from threading import Timer
 import RPi.GPIO as GPIO

 pin_activar_voltaje = 10

 GPIO.setwarnings(False)
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(pin_activar_voltaje,GPIO.OUT)

 adc_multi = Adafruit_ADS1x15.ADS1115(address=0x4B)

 def leer_entradas_analogas():
     GPIO.output(pin_activar_voltaje, True)
     temp = adc_multi.read_adc(0)
     print("voltaje_0: " + str(temp))
     GPIO.output(pin_activar_voltaje, False)
     leer_entradas = 0

     timer_leer_entradas_analogas = threading.Timer(1,leer_entradas_analogas)
     timer_leer_entradas_analogas.setDaemon(True)
     timer_leer_entradas_analogas.start()

 timer_leer_entradas_analogas = threading.Timer(1,leer_entradas_analogas)
 timer_leer_entradas_analogas.setDaemon(True)
 timer_leer_entradas_analogas.start()

 while(1):
     pass

I would like, if possible a little help, thanks

This library should be deprecated.

To be replaced by Adafruit_CircuitPython_ADS1x15 and Blinka.

For historical reference, my take on the outstanding Issues and PRs:

Issues:

  • Sample time delay insufficient for normal tolerance - fixed in new lib
  • working with threads - might reappear in new form on blinka boards
  • PyPI improvements - fixed with new process
  • ADS1x15_CONFIG_GAIN gain=2/3 gives unexpected results - should be OK in Python3
  • Comparator mode doesn't work for ADS1015 - feature not in new lib yet
  • Error in Intel Edison - blinka would need to add support
  • Can't install with pip - fixed with new process

PRs:

  • Single Ended Input Example & README Update - fixed in new lib

Can't install with pip

I want to install this lib for Python 3, so I tried pip3 install --user adafruit-ads1x15, but it didn't work. I also tried with pip install --user adafruit-ads1x15, but it doesn't work either.

First I got this error:

Collecting adafruit-ads1x15
Using cached Adafruit_ADS1x15-1.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-rrh89a59/adafruit-ads1x15/setup.py", line 1, in <module>
    from ez_setup import use_setuptools
ImportError: No module named 'ez_setup'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrh89a59/adafruit-ads1x15/

So I installed ez-setup with pip, but then I got this error:

Collecting adafruit-ads1x15
Using cached Adafruit_ADS1x15-1.0.1.tar.gz
Complete output from command python setup.py egg_info:
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz
Extracting in /tmp/tmpxysjf7rj
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.5/site-packages/ez_setup.py", line 143, in use_setuptools
    raise ImportError
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-ozskf5n2/adafruit-ads1x15/setup.py", line 2, in <module>
    use_setuptools()
  File "/home/pi/.local/lib/python3.5/site-packages/ez_setup.py", line 145, in use_setuptools
    return _do_download(version, download_base, to_dir, download_delay)
  File "/home/pi/.local/lib/python3.5/site-packages/ez_setup.py", line 125, in _do_download
    _build_egg(egg, tarball, to_dir)
  File "/home/pi/.local/lib/python3.5/site-packages/ez_setup.py", line 99, in _build_egg
    _extractall(tar)
  File "/home/pi/.local/lib/python3.5/site-packages/ez_setup.py", line 467, in _extractall
    self.chown(tarinfo, dirpath)
TypeError: chown() missing 1 required positional argument: 'numeric_owner'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ozskf5n2/adafruit-ads1x15/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.