Module ADS1x15 :: Class ADS1x15
[hide private]
[frames] | no frames]

Class ADS1x15

source code

object --+
         |
        ADS1x15

Base functionality for ADS1x15 analog to digital converters.

Instance Methods [hide private]
 
__init__(self, address=ADS1x15_DEFAULT_ADDRESS, busnum=1)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_data_rate_default(self)
Retrieve the default data rate for this ADC (in samples per second).
source code
 
_data_rate_config(self, data_rate)
Subclasses should override this function and return a 16-bit value that can be OR'ed with the config register to set the specified data rate.
source code
 
_conversion_value(self, low, high)
Subclasses should override this function that takes the low and high byte of a conversion result and returns a signed integer value.
source code
 
_read(self, mux, gain, data_rate, mode)
Perform an ADC read with the provided mux, gain, data_rate, and mode values.
source code
 
_read_comparator(self, mux, gain, data_rate, mode, high_threshold, low_threshold, active_low, traditional, latching, num_readings)
Perform an ADC read with the provided mux, gain, data_rate, and mode values and with the comparator enabled as specified.
source code
 
read_adc(self, channel, gain=1, data_rate=None)
Read a single ADC channel and return the ADC value as a signed integer result.
source code
 
read_adc_difference(self, differential, gain=1, data_rate=None)
Read the difference between two ADC channels and return the ADC value as a signed integer result.
source code
 
start_adc(self, channel, gain=1, data_rate=None)
Start continuous ADC conversions on the specified channel (0-3).
source code
 
start_adc_difference(self, differential, gain=1, data_rate=None)
Start continuous ADC conversions between two ADC channels.
source code
 
start_adc_comparator(self, channel, high_threshold, low_threshold, gain=1, data_rate=None, active_low=True, traditional=True, latching=False, num_readings=1)
Start continuous ADC conversions on the specified channel (0-3) with the comparator enabled.
source code
 
start_adc_difference_comparator(self, differential, high_threshold, low_threshold, gain=1, data_rate=None, active_low=True, traditional=True, latching=False, num_readings=1)
Start continuous ADC conversions between two channels with the comparator enabled.
source code
 
stop_adc(self)
Stop all continuous ADC conversions (either normal or difference mode).
source code
 
get_last_result(self)
Read the last conversion result when in continuous conversion mode.
source code
 
readList(self, register, length)
Read a length number of bytes from the specified register.
source code
 
writeList(self, register, data)
Write bytes to the specified register.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, address=ADS1x15_DEFAULT_ADDRESS, busnum=1)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_data_rate_default(self)

source code 

Retrieve the default data rate for this ADC (in samples per second). Should be implemented by subclasses.

_data_rate_config(self, data_rate)

source code 

Subclasses should override this function and return a 16-bit value that can be OR'ed with the config register to set the specified data rate. If a value of None is specified then a default data_rate setting should be returned. If an invalid or unsupported data_rate is provided then an exception should be thrown.

_read(self, mux, gain, data_rate, mode)

source code 

Perform an ADC read with the provided mux, gain, data_rate, and mode values. Returns the signed integer result of the read.

_read_comparator(self, mux, gain, data_rate, mode, high_threshold, low_threshold, active_low, traditional, latching, num_readings)

source code 

Perform an ADC read with the provided mux, gain, data_rate, and mode values and with the comparator enabled as specified. Returns the signed integer result of the read.

read_adc(self, channel, gain=1, data_rate=None)

source code 
Read a single ADC channel and return the ADC value as a signed integer
result.  Channel must be a value within 0-3.
You can also pass in an optional data_rate parameter that controls
the ADC conversion time (in samples/second). Each chip has a different
set of allowed data rate values, see datasheet Table 9 config register
DR bit values.
ADS1015: 128, 250, 490, 920, 1600(default), 2400, 3300
ADS1115: 8, 16, 32, 64, 128 (default), 250, 475, 860
Each returned value will be a 12 or 16 bit signed integer value depending on the
ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
Gain of 1 for reading voltages from 0 to 4.09V.
Or pick a different gain to change the range of voltages that are read:
- 2/3 = +/-6.144V
-   1 = +/-4.096V
-   2 = +/-2.048V
-   4 = +/-1.024V
-   8 = +/-0.512V
-  16 = +/-0.256V
See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.

read_adc_difference(self, differential, gain=1, data_rate=None)

source code 

Read the difference between two ADC channels and return the ADC value as a signed integer result. Differential must be one of:

  • 0 = Channel 0 minus channel 1
  • 1 = Channel 0 minus channel 3
  • 2 = Channel 1 minus channel 3
  • 3 = Channel 2 minus channel 3

start_adc(self, channel, gain=1, data_rate=None)

source code 
Start continuous ADC conversions on the specified channel (0-3). Will
return an initial conversion result, then call the get_last_result()
function to read the most recent conversion result. Call stop_adc() to
stop conversions.
You can also pass in an optional data_rate parameter that controls
the ADC conversion time (in samples/second). Each chip has a different
set of allowed data rate values, see datasheet Table 9 config register
DR bit values.
ADS1015: 128, 250, 490, 920, 1600(default), 2400, 3300
ADS1115: 8, 16, 32, 64, 128 (default), 250, 475, 860
Each returned value will be a 12 or 16 bit signed integer value depending on the
ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
Gain of 1 for reading voltages from 0 to 4.09V.
Or pick a different gain to change the range of voltages that are read:
- 2/3 = +/-6.144V
-   1 = +/-4.096V
-   2 = +/-2.048V
-   4 = +/-1.024V
-   8 = +/-0.512V
-  16 = +/-0.256V
See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.

start_adc_difference(self, differential, gain=1, data_rate=None)

source code 

Start continuous ADC conversions between two ADC channels. Differential must be one of:

  • 0 = Channel 0 minus channel 1
  • 1 = Channel 0 minus channel 3
  • 2 = Channel 1 minus channel 3
  • 3 = Channel 2 minus channel 3

Will return an initial conversion result, then call the get_last_result() function continuously to read the most recent conversion result. Call stop_adc() to stop conversions.

start_adc_comparator(self, channel, high_threshold, low_threshold, gain=1, data_rate=None, active_low=True, traditional=True, latching=False, num_readings=1)

source code 

Start continuous ADC conversions on the specified channel (0-3) with the comparator enabled. When enabled, the comparator checks if the ADC value is within the high_threshold & low_threshold value (both should be signed 16-bit integers) and trigger the ALERT pin. The behavior can be controlled by the following parameters:

  • active_low: Boolean that indicates if ALERT is pulled low or high when active/triggered. Default is true, active low.
  • traditional: Boolean that indicates if the comparator is in traditional mode where it fires when the value is within the threshold, or in window mode where it fires when the value is _outside_ the threshold range. Default is true, traditional mode.
  • latching: Boolean that indicates if the alert should be held until get_last_result() is called to read the value and clear the alert. Default is false, non-latching.
  • num_readings: The number of readings that match the comparator before triggering the alert. Can be 1, 2, or 4. Default is 1.

Will return an initial conversion result, then call the get_last_result() function continuously to read the most recent conversion result. Call stop_adc() to stop conversions.

start_adc_difference_comparator(self, differential, high_threshold, low_threshold, gain=1, data_rate=None, active_low=True, traditional=True, latching=False, num_readings=1)

source code 

Start continuous ADC conversions between two channels with the comparator enabled. See start_adc_difference for valid differential parameter values and their meaning. When enabled the comparator to will check if the ADC value is within the high_threshold & low_threshold value (both should be signed 16-bit integers) and trigger the ALERT pin. The behavior can be controlled by the following parameters:

  • active_low: Boolean that indicates if ALERT is pulled low or high when active/triggered. Default is true, active low.
  • traditional: Boolean that indicates if the comparator is in traditional mode where it fires when the value is within the threshold, or in window mode where it fires when the value is _outside_ the threshold range. Default is true, traditional mode.
  • latching: Boolean that indicates if the alert should be held until get_last_result() is called to read the value and clear the alert. Default is false, non-latching.
  • num_readings: The number of readings that match the comparator before triggering the alert. Can be 1, 2, or 4. Default is 1.

Will return an initial conversion result, then call the get_last_result() function continuously to read the most recent conversion result. Call stop_adc() to stop conversions.

get_last_result(self)

source code 

Read the last conversion result when in continuous conversion mode. Will return a signed integer value.

readList(self, register, length)

source code 

Read a length number of bytes from the specified register. Results will be returned as a bytearray.