From acf515be195c701e6eda535b904a82fd8e74dd8a Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Thu, 7 Nov 2019 15:12:22 +0100
Subject: [PATCH] Remove driver ADS1115 using I2Cdev library
---
tasmota/my_user_config.h | 1 -
tasmota/tasmota_post.h | 1 -
tasmota/xsns_12_ads1115.ino | 6 +-
tasmota/xsns_12_ads1115_i2cdev.ino | 155 -----------------------------
4 files changed, 3 insertions(+), 160 deletions(-)
delete mode 100644 tasmota/xsns_12_ads1115_i2cdev.ino
diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h
index 590ab02c4..7a72693d8 100644
--- a/tasmota/my_user_config.h
+++ b/tasmota/my_user_config.h
@@ -380,7 +380,6 @@
#define USE_VEML6070_RSET 270000 // VEML6070, Rset in Ohm used on PCB board, default 270K = 270000ohm, range for this sensor: 220K ... 1Meg
#define USE_VEML6070_SHOW_RAW // VEML6070, shows the raw value of UV-A
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
-// #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
// #define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h
index c3830c8e0..4206c1926 100644
--- a/tasmota/tasmota_post.h
+++ b/tasmota/tasmota_post.h
@@ -126,7 +126,6 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
#define USE_BH1750 // Add I2C code for BH1750 sensor (+0k5 code)
#define USE_VEML6070 // Add I2C code for VEML6070 sensor (+0k5 code)
#define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
-//#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
#define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
//#define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
diff --git a/tasmota/xsns_12_ads1115.ino b/tasmota/xsns_12_ads1115.ino
index dbea9c3b1..66406cff0 100644
--- a/tasmota/xsns_12_ads1115.ino
+++ b/tasmota/xsns_12_ads1115.ino
@@ -238,9 +238,6 @@ bool Xsns12(uint8_t function)
bool result = false;
switch (function) {
- case FUNC_INIT:
- Ads1115Detect();
- break;
case FUNC_JSON_APPEND:
Ads1115Show(1);
break;
@@ -249,6 +246,9 @@ bool Xsns12(uint8_t function)
Ads1115Show(0);
break;
#endif // USE_WEBSERVER
+ case FUNC_INIT:
+ Ads1115Detect();
+ break;
}
return result;
}
diff --git a/tasmota/xsns_12_ads1115_i2cdev.ino b/tasmota/xsns_12_ads1115_i2cdev.ino
deleted file mode 100644
index 77a4268e6..000000000
--- a/tasmota/xsns_12_ads1115_i2cdev.ino
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- xsns_12_ads1115.ino - ADS1x15 A/D Converter support for Tasmota
-
- Copyright (C) 2019 Stefan Bode and Theo Arends
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifdef USE_I2C
-#ifdef USE_ADS1115_I2CDEV
-/*********************************************************************************************\
- * ADS1115 - 4 channel 16BIT A/D converter
- *
- * Required library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/ADS1115
- *
- * I2C Address: 0x48, 0x49, 0x4A or 0x4B
- *
- * The ADC input range (or gain) can be changed via the following
- * functions, but be careful never to exceed VDD +0.3V max, or to
- * exceed the upper and lower limits if you adjust the input range!
- * Setting these values incorrectly may destroy your ADC!
- * ADS1015 ADS1115
- * ------- -------
- * ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
- * ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
- * ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
- * ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
- * ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
- * ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
-\*********************************************************************************************/
-
-#define XSNS_12 12
-#define XI2C_13 13 // See I2CDEVICES.md
-
-#include
-
-ADS1115 adc0;
-
-uint8_t ads1115_type = 0;
-uint8_t ads1115_address;
-uint8_t ads1115_addresses[] = {
- ADS1115_ADDRESS_ADDR_GND, // address pin low (GND)
- ADS1115_ADDRESS_ADDR_VDD, // address pin high (VCC)
- ADS1115_ADDRESS_ADDR_SDA, // address pin tied to SDA pin
- ADS1115_ADDRESS_ADDR_SCL // address pin tied to SCL pin
-};
-
-int16_t Ads1115GetConversion(uint8_t channel)
-{
- switch (channel) {
- case 0:
- adc0.getConversionP0GND();
- break;
- case 1:
- adc0.getConversionP1GND();
- break;
- case 2:
- adc0.getConversionP2GND();
- break;
- case 3:
- adc0.getConversionP3GND();
- break;
- }
-}
-
-/********************************************************************************************/
-
-void Ads1115Detect(void)
-{
- if (ads1115_type) {
- return;
- }
-
- for (uint32_t i = 0; i < sizeof(ads1115_addresses); i++) {
- ads1115_address = ads1115_addresses[i];
- ADS1115 adc0(ads1115_address);
- if (adc0.testConnection()) {
- adc0.initialize();
- adc0.setGain(ADS1115_PGA_6P144); // Set the gain (PGA) +/-6.144V
- adc0.setRate(ADS1115_RATE_860);
- adc0.setMode(ADS1115_MODE_CONTINUOUS);
- ads1115_type = 1;
- AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "ADS1115", ads1115_address);
- break;
- }
- }
-}
-
-void Ads1115Show(bool json)
-{
- if (ads1115_type) {
-
- uint8_t dsxflg = 0;
- for (uint32_t i = 0; i < 4; i++) {
- int16_t adc_value = Ads1115GetConversion(i);
-
- if (json) {
- if (!dsxflg ) {
- ResponseAppend_P(PSTR(",\"ADS1115\":{"));
- }
- ResponseAppend_P(PSTR("%s\"A%d\":%d"), (dsxflg) ? "," : "", i, adc_value);
- dsxflg++;
-#ifdef USE_WEBSERVER
- } else {
- WSContentSend_PD(HTTP_SNS_ANALOG, "ADS1115", i, adc_value);
-#endif // USE_WEBSERVER
- }
- }
- if (json) {
- if (dsxflg) {
- ResponseJsonEnd();
- }
- }
- }
-}
-
-/*********************************************************************************************\
- * Interface
-\*********************************************************************************************/
-
-bool Xsns12(uint8_t function)
-{
- if (!I2cEnabled(XI2C_13)) { return false; }
-
- bool result = false;
-
- switch (function) {
- case FUNC_PREP_BEFORE_TELEPERIOD:
- Ads1115Detect();
- break;
- case FUNC_JSON_APPEND:
- Ads1115Show(1);
- break;
-#ifdef USE_WEBSERVER
- case FUNC_WEB_SENSOR:
- Ads1115Show(0);
- break;
-#endif // USE_WEBSERVER
- }
- return result;
-}
-
-#endif // USE_ADS1115_I2CDEV
-#endif // USE_I2C