How To Instantiate A Class; Interpreting i2c Results


2 posts
by BobCochran » Mon Jan 21, 2013 11:11 pm
Greetings,

I'm playing with the Adafruit ADS1115 Analog to Digital converter breakout board ( http://www.adafruit.com/products/1085 ). I'm also using the Adafruit-Raspberry-Pi-Python-Code collection from their github repository.

In this is an element named "ads1015_example.py" which runs some example code, printing the values of Channels 0 and 1 for the ADS1015 chip. It reads like this, in part:

Code: Select all
#!/usr/bin/python
from Adafruit_ADS1x15 import ADS1x15
# Initialise the ADC using the default mode (IC = ADS1015, default address)
adc = ADS1x15()


I changed it to this because I want to specify the ADS1115, not the default of ADS1015:

Code: Select all
# Initialise the ADC using the default mode (IC = ADS1115)
adc = ADS1x15(ic=0x01)


My question is whether the above is the correct way to supply instantiate the ADS1x15 class?

It looks like this, in part:

Code: Select all
 # IC Identifiers
  __IC_ADS1015                      = 0x00
  __IC_ADS1115                      = 0x01
...
...
 # Constructor
  def __init__(self, address=0x48, ic=__IC_ADS1015, debug=False):
    self.i2c = Adafruit_I2C(address)
    self.address = address
    self.debug = debug


I'm getting results that look a little strange to my novice eyes:

Code: Select all
pi@raspberrypi1 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15 $ sudo python ads1115_example.py
Channel 0 = 53.172 V
Channel 1 = 53.172 V
pi@raspberrypi1 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15 $ sudo python ads1115_example.py
Channel 0 = 53.172 V
Channel 1 = 53.172 V
pi@raspberrypi1 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15 $ sudo python ads1115_example.py
Channel 0 = 53.172 V
Channel 1 = 53.172 V
pi@raspberrypi1 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15 $ sudo python ads1115_example.py
Channel 0 = 53.172 V
Channel 1 = 53.172 V
pi@raspberrypi1 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15 $ sudo python ads1115_example.py
Channel 0 = 33.789 V
Channel 1 = 33.789 V


Thanks

Bob

Posts: 27
Joined: Sat Dec 29, 2012 2:51 am
Location: Greenbelt, Maryland, USA
by -rst- » Wed Jan 23, 2013 2:33 pm
Looks to me the correct way to instantiate the object ...provided that the default address is the one you want to use.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 900
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland