From 80625962c123429fa7273f72dcc1ed92152ce4db Mon Sep 17 00:00:00 2001 From: "Wolfgang (Wolle) Ewald" Date: Tue, 19 Dec 2023 21:09:10 +0100 Subject: [PATCH] Add files via upload --- src/ADS1015_WE.h | 34 +++++++++++++++++ src/ADS1115_WE.cpp | 92 +++++++++++++++++++++++++++++++--------------- src/ADS1115_WE.h | 72 +++++++++++++++++++++++++++--------- 3 files changed, 152 insertions(+), 46 deletions(-) create mode 100644 src/ADS1015_WE.h diff --git a/src/ADS1015_WE.h b/src/ADS1015_WE.h new file mode 100644 index 0000000..054b4b1 --- /dev/null +++ b/src/ADS1015_WE.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * + * This is a library for the ADS1115 and ADS1015 A/D Converter + * + * You'll find several example sketches which should enable you to use the library. + * + * You are free to use it, change it or build on it. In case you like it, it would + * be cool if you give it a star. + * + * If you find bugs, please inform me! + * + * Written by Wolfgang (Wolle) Ewald + * https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English) + * https://wolles-elektronikkiste.de/ads1115 (German) + * + * + ******************************************************************************/ + +#ifndef ADS1015_WE_H +#define ADS1015_WE_H +#include + +#if ARDUINO < 100 +#include +#else +#include +#endif + +class ADS1015_WE : public ADS1115_WE { + public: + using ADS1115_WE::ADS1115_WE; +}; + +#endif diff --git a/src/ADS1115_WE.cpp b/src/ADS1115_WE.cpp index 6e98902..0eb18e5 100644 --- a/src/ADS1115_WE.cpp +++ b/src/ADS1115_WE.cpp @@ -1,5 +1,5 @@ /***************************************** -* This is a library for the ADS1115 A/D Converter +* This is a library for the ADS1115 and ADS1015 A/D Converter * * You'll find an example which should enable you to use the library. * @@ -28,7 +28,9 @@ void ADS1115_WE::reset(){ #endif } -bool ADS1115_WE::init(){ +bool ADS1115_WE::init(bool ads1015){ + useADS1015 = ads1015; + #ifndef USE_TINY_WIRE_M_ _wire->beginTransmission(i2cAddress); uint8_t success = _wire->endTransmission(); @@ -194,35 +196,65 @@ void ADS1115_WE::setPermanentAutoRangeMode(bool autoMode){ autoRangeMode = false; } } - + void ADS1115_WE::delayAccToRate(convRate cr){ - switch(cr){ - case ADS1115_8_SPS: - delay(130); - break; - case ADS1115_16_SPS: - delay(65); - break; - case ADS1115_32_SPS: - delay(32); - break; - case ADS1115_64_SPS: - delay(16); - break; - case ADS1115_128_SPS: - delay(8); - break; - case ADS1115_250_SPS: - delay(4); - break; - case ADS1115_475_SPS: - delay(3); - break; - case ADS1115_860_SPS: - delay(2); - break; + if(!useADS1015){ + switch(cr){ + case ADS1115_8_SPS: + delay(130); + break; + case ADS1115_16_SPS: + delay(65); + break; + case ADS1115_32_SPS: + delay(32); + break; + case ADS1115_64_SPS: + delay(16); + break; + case ADS1115_128_SPS: + delay(8); + break; + case ADS1115_250_SPS: + delay(4); + break; + case ADS1115_475_SPS: + delay(3); + break; + case ADS1115_860_SPS: + delay(2); + break; + } } -} + else{ + switch(cr){ + case ADS1015_128_SPS: + delay(8); + break; + case ADS1015_250_SPS: + delay(5); + break; + case ADS1015_490_SPS: + delay(2); + break; + case ADS1015_920_SPS: + delay(1); + break; + case ADS1015_1600_SPS: + delayMicroseconds(675); + break; + case ADS1015_2400_SPS: + delayMicroseconds(450); + break; + case ADS1015_3300_SPS: + delayMicroseconds(330); + break; + case ADS1015_3300_SPS_2: + delayMicroseconds(330); + break; + } + } +} void ADS1115_WE::setCompareChannels(ADS1115_MUX mux){ uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG); @@ -255,11 +287,13 @@ bool ADS1115_WE::isBusy(){ return (!(currentConfReg>>15) & 1); } + void ADS1115_WE::startSingleMeasurement(){ uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG); currentConfReg |= (1 << 15); writeRegister(ADS1115_CONFIG_REG, currentConfReg); } + float ADS1115_WE::getResult_V(){ float result = getResult_mV(); diff --git a/src/ADS1115_WE.h b/src/ADS1115_WE.h index 6a1014e..681edb0 100644 --- a/src/ADS1115_WE.h +++ b/src/ADS1115_WE.h @@ -1,6 +1,6 @@ /****************************************************************************** * - * This is a library for the ADS1115 A/D Converter + * This is a library for the ADS1115 and ADS1015 A/D Converter * * You'll find several example sketches which should enable you to use the library. * @@ -37,39 +37,58 @@ typedef enum ADS1115_COMP_QUE { ADS1115_ASSERT_AFTER_1 = 0x0000, ADS1115_ASSERT_AFTER_2 = 0x0001, ADS1115_ASSERT_AFTER_4 = 0x0002, - ADS1115_DISABLE_ALERT = 0x0003 + ADS1115_DISABLE_ALERT = 0x0003, + ADS1015_ASSERT_AFTER_1 = ADS1115_ASSERT_AFTER_1, + ADS1015_ASSERT_AFTER_2 = ADS1115_ASSERT_AFTER_2, + ADS1015_ASSERT_AFTER_4 = ADS1115_ASSERT_AFTER_4, + ADS1015_DISABLE_ALERT = ADS1115_DISABLE_ALERT } compQue; typedef enum ADS1115_LATCH { ADS1115_LATCH_DISABLED = 0x0000, ADS1115_LATCH_ENABLED = 0x0004, + ADS1015_LATCH_DISABLED = ADS1115_LATCH_DISABLED, + ADS1015_LATCH_ENABLED = ADS1115_LATCH_ENABLED } latch; typedef enum ADS1115_ALERT_POL { ADS1115_ACT_LOW = 0x0000, - ADS1115_ACT_HIGH = 0x0008 + ADS1115_ACT_HIGH = 0x0008, + ADS1015_ACT_LOW = ADS1115_ACT_LOW, + ADS1015_ACT_HIGH = ADS1115_ACT_HIGH } alertPol; typedef enum ADS1115_COMP_MODE{ ADS1115_MAX_LIMIT = 0x0000, - ADS1115_WINDOW = 0x0010 + ADS1115_WINDOW = 0x0010, + ADS1015_MAX_LIMIT = ADS1115_MAX_LIMIT, + ADS1015_WINDOW = ADS1115_WINDOW } compMode; typedef enum ADS1115_CONV_RATE{ - ADS1115_8_SPS = 0x0000, - ADS1115_16_SPS = 0x0020, - ADS1115_32_SPS = 0x0040, - ADS1115_64_SPS = 0x0060, - ADS1115_128_SPS = 0x0080, - ADS1115_250_SPS = 0x00A0, - ADS1115_475_SPS = 0x00C0, - ADS1115_860_SPS = 0x00E0 + ADS1115_8_SPS = 0x0000, + ADS1115_16_SPS = 0x0020, + ADS1115_32_SPS = 0x0040, + ADS1115_64_SPS = 0x0060, + ADS1115_128_SPS = 0x0080, + ADS1115_250_SPS = 0x00A0, + ADS1115_475_SPS = 0x00C0, + ADS1115_860_SPS = 0x00E0, + ADS1015_128_SPS = ADS1115_8_SPS, + ADS1015_250_SPS = ADS1115_16_SPS, + ADS1015_490_SPS = ADS1115_32_SPS, + ADS1015_920_SPS = ADS1115_64_SPS, + ADS1015_1600_SPS = ADS1115_128_SPS, + ADS1015_2400_SPS = ADS1115_250_SPS, + ADS1015_3300_SPS = ADS1115_475_SPS, + ADS1015_3300_SPS_2 = ADS1115_860_SPS } convRate; typedef enum ADS1115_MEASURE_MODE{ - ADS1115_CONTINOUS = 0x0000, // keeping misspelled enum for backwards compatibility. ADS1115_CONTINUOUS = 0x0000, - ADS1115_SINGLE = 0x0100 + ADS1115_SINGLE = 0x0100, + ADS1015_CONTINUOUS = ADS1115_CONTINUOUS, + ADS1015_SINGLE = ADS1115_SINGLE } measureMode; typedef enum ADS1115_RANGE{ @@ -79,6 +98,12 @@ typedef enum ADS1115_RANGE{ ADS1115_RANGE_1024 = 0x0600, ADS1115_RANGE_0512 = 0x0800, ADS1115_RANGE_0256 = 0x0A00, + ADS1015_RANGE_6144 = ADS1115_RANGE_6144, + ADS1015_RANGE_4096 = ADS1115_RANGE_4096, + ADS1015_RANGE_2048 = ADS1115_RANGE_2048, + ADS1015_RANGE_1024 = ADS1115_RANGE_1024, + ADS1015_RANGE_0512 = ADS1115_RANGE_0512, + ADS1015_RANGE_0256 = ADS1115_RANGE_0256 } range; typedef enum ADS1115_MUX{ @@ -89,13 +114,25 @@ typedef enum ADS1115_MUX{ ADS1115_COMP_0_GND = 0x4000, ADS1115_COMP_1_GND = 0x5000, ADS1115_COMP_2_GND = 0x6000, - ADS1115_COMP_3_GND = 0x7000 + ADS1115_COMP_3_GND = 0x7000, + ADS1015_COMP_0_1 = ADS1115_COMP_0_1, + ADS1015_COMP_0_3 = ADS1115_COMP_0_3, + ADS1015_COMP_1_3 = ADS1115_COMP_1_3, + ADS1015_COMP_2_3 = ADS1115_COMP_2_3, + ADS1015_COMP_0_GND = ADS1115_COMP_0_GND, + ADS1015_COMP_1_GND = ADS1115_COMP_1_GND, + ADS1015_COMP_2_GND = ADS1115_COMP_2_GND, + ADS1015_COMP_3_GND = ADS1115_COMP_3_GND } mux; + #define ADS1115_COMP_INC 0x1000 // increment to next channel +#define ADS1015_MUX ADS1115_MUX typedef enum ADS1115_STATUS_OR_START{ ADS1115_BUSY = 0x0000, - ADS1115_START_ISREADY = 0x8000 + ADS1115_START_ISREADY = 0x8000, + ADS1015_BUSY = ADS1115_BUSY, + ADS1015_START_ISREADY = ADS1115_START_ISREADY } statusOrStart; @@ -120,7 +157,7 @@ class ADS1115_WE #endif void reset(); - bool init(); + bool init(bool ads1015 = false); /* Set number of conversions after which the alert pin will be active * - or you can disable the alert @@ -283,6 +320,7 @@ class ADS1115_WE #ifndef USE_TINY_WIRE_M_ TwoWire *_wire; #endif + bool useADS1015; uint16_t voltageRange; ADS1115_MEASURE_MODE deviceMeasureMode; uint8_t i2cAddress;