From 27ab20d43a7ebd8722aecf98d86d48b7891b530c Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Tue, 31 Aug 2021 17:08:34 +0100 Subject: [PATCH] Add support for ADS1115 Use the auto-detect feature of the ADS1015 library to support reading the gas sensor via an ADS1115. --- library/enviroplus/gas.py | 8 ++++++-- library/setup.cfg | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/library/enviroplus/gas.py b/library/enviroplus/gas.py index 584317b..f5eb2ab 100644 --- a/library/enviroplus/gas.py +++ b/library/enviroplus/gas.py @@ -41,15 +41,19 @@ def __repr__(self): def setup(): - global adc, _is_setup + global adc, adc_type, _is_setup if _is_setup: return _is_setup = True adc = ads1015.ADS1015(i2c_addr=0x49) + adc_type = adc.detect_chip_type() adc.set_mode('single') adc.set_programmable_gain(MICS6814_GAIN) - adc.set_sample_rate(1600) + if adc_type == 'ADS1115': + adc.set_sample_rate(128) + else: + adc.set_sample_rate(1600) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) diff --git a/library/setup.cfg b/library/setup.cfg index c59250c..598d88c 100644 --- a/library/setup.cfg +++ b/library/setup.cfg @@ -32,7 +32,7 @@ install_requires = pms5003 ltr559 st7735 - ads1015 + ads1015 >= 0.0.7 fonts font-roboto astral