I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

ADS1115/ADS1115.h
00001 // I2Cdev library collection - ADS1115 I2C device class header file
00002 // Based on Texas Instruments ADS1113/4/5 datasheet, May 2009 (SBAS444B, revised October 2009)
00003 // Note that the ADS1115 uses 16-bit registers, not 8-bit registers.
00004 // 8/2/2011 by Jeff Rowberg <jeff@rowberg.net>
00005 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00006 //
00007 // Changelog:
00008 //     2011-08-02 - initial release
00009 //     2011-10-29 - added getDifferentialx() methods, F. Farzanegan
00010 
00011 /* ============================================
00012 I2Cdev device library code is placed under the MIT license
00013 Copyright (c) 2011 Jeff Rowberg
00014 
00015 Permission is hereby granted, free of charge, to any person obtaining a copy
00016 of this software and associated documentation files (the "Software"), to deal
00017 in the Software without restriction, including without limitation the rights
00018 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00019 copies of the Software, and to permit persons to whom the Software is
00020 furnished to do so, subject to the following conditions:
00021 
00022 The above copyright notice and this permission notice shall be included in
00023 all copies or substantial portions of the Software.
00024 
00025 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00026 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00027 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00028 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00029 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00030 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 THE SOFTWARE.
00032 ===============================================
00033 */
00034 
00035 #ifndef _ADS1115_H_
00036 #define _ADS1115_H_
00037 
00038 #include "I2Cdev.h"
00039 
00040 #define ADS1115_ADDRESS_ADDR_GND    0x48 // address pin low (GND)
00041 #define ADS1115_ADDRESS_ADDR_VDD    0x49 // address pin high (VCC)
00042 #define ADS1115_ADDRESS_ADDR_SDA    0x4A // address pin tied to SDA pin
00043 #define ADS1115_ADDRESS_ADDR_SCL    0x4B // address pin tied to SCL pin
00044 #define ADS1115_DEFAULT_ADDRESS     ADS1115_ADDRESS_ADDR_GND
00045 
00046 #define ADS1115_RA_CONVERSION       0x00
00047 #define ADS1115_RA_CONFIG           0x01
00048 #define ADS1115_RA_LO_THRESH        0x02
00049 #define ADS1115_RA_HI_THRESH        0x03
00050 
00051 #define ADS1115_CFG_OS_BIT          15
00052 #define ADS1115_CFG_MUX_BIT         14
00053 #define ADS1115_CFG_MUX_LENGTH      3
00054 #define ADS1115_CFG_PGA_BIT         11
00055 #define ADS1115_CFG_PGA_LENGTH      3
00056 #define ADS1115_CFG_MODE_BIT        8
00057 #define ADS1115_CFG_DR_BIT          7
00058 #define ADS1115_CFG_DR_LENGTH       3
00059 #define ADS1115_CFG_COMP_MODE_BIT   4
00060 #define ADS1115_CFG_COMP_POL_BIT    3
00061 #define ADS1115_CFG_COMP_LAT_BIT    2
00062 #define ADS1115_CFG_COMP_QUE_BIT    1
00063 #define ADS1115_CFG_COMP_QUE_LENGTH 2
00064 
00065 #define ADS1115_OS_INACTIVE         0x00
00066 #define ADS1115_OS_ACTIVE           0x01
00067 
00068 #define ADS1115_MUX_P0_N1           0x00 // default
00069 #define ADS1115_MUX_P0_N3           0x01
00070 #define ADS1115_MUX_P1_N3           0x02
00071 #define ADS1115_MUX_P2_N3           0x03
00072 #define ADS1115_MUX_P0_NG           0x04
00073 #define ADS1115_MUX_P1_NG           0x05
00074 #define ADS1115_MUX_P2_NG           0x06
00075 #define ADS1115_MUX_P3_NG           0x07
00076 
00077 #define ADS1115_PGA_6P144           0x00
00078 #define ADS1115_PGA_4P096           0x01
00079 #define ADS1115_PGA_2P048           0x02 // default
00080 #define ADS1115_PGA_1P024           0x03
00081 #define ADS1115_PGA_0P512           0x04
00082 #define ADS1115_PGA_0P256           0x05
00083 #define ADS1115_PGA_0P256B          0x06
00084 #define ADS1115_PGA_0P256C          0x07
00085 
00086 #define ADS1115_MV_6P144            0.187500
00087 #define ADS1115_MV_4P096            0.125000
00088 #define ADS1115_MV_2P048            0.062500 // default
00089 #define ADS1115_MV_1P024            0.031250
00090 #define ADS1115_MV_0P512            0.015625
00091 #define ADS1115_MV_0P256            0.007813
00092 #define ADS1115_MV_0P256B           0.007813 
00093 #define ADS1115_MV_0P256C           0.007813
00094 
00095 #define ADS1115_MODE_CONTINUOUS     0x00
00096 #define ADS1115_MODE_SINGLESHOT     0x01 // default
00097 
00098 #define ADS1115_RATE_8              0x00
00099 #define ADS1115_RATE_16             0x01
00100 #define ADS1115_RATE_32             0x02
00101 #define ADS1115_RATE_64             0x03
00102 #define ADS1115_RATE_128            0x04 // default
00103 #define ADS1115_RATE_250            0x05
00104 #define ADS1115_RATE_475            0x06
00105 #define ADS1115_RATE_860            0x07
00106 
00107 #define ADS1115_COMP_MODE_HYSTERESIS    0x00 // default
00108 #define ADS1115_COMP_MODE_WINDOW        0x01
00109 
00110 #define ADS1115_COMP_POL_ACTIVE_LOW     0x00 // default
00111 #define ADS1115_COMP_POL_ACTIVE_HIGH    0x01
00112 
00113 #define ADS1115_COMP_LAT_NON_LATCHING   0x00 // default
00114 #define ADS1115_COMP_LAT_LATCHING       0x01
00115 
00116 #define ADS1115_COMP_QUE_ASSERT1    0x00
00117 #define ADS1115_COMP_QUE_ASSERT2    0x01
00118 #define ADS1115_COMP_QUE_ASSERT4    0x02
00119 #define ADS1115_COMP_QUE_DISABLE    0x03 // default
00120 
00121 
00122 class ADS1115 {
00123     public:
00124         ADS1115();
00125         ADS1115(uint8_t address);
00126         
00127         void initialize();
00128         bool testConnection();
00129 
00130         // CONVERSION register
00131         int16_t getDifferential();
00132         int16_t getDifferential0();
00133         int16_t getDifferential1();
00134         int16_t getDifferential2();
00135         int16_t getDifferential3();
00136         int16_t getDiff0();
00137         int16_t getDiff1();
00138         int16_t getDiff2();
00139         int16_t getDiff3();
00140         float getMilliVolts(); 
00141         float getMvPerCount();
00142 
00143         // CONFIG register
00144         uint8_t getOpStatus();
00145         void setOpStatus(uint8_t mux);
00146         uint8_t getMultiplexer();
00147         void setMultiplexer(uint8_t mux);
00148         uint8_t getGain();
00149         void setGain(uint8_t gain);
00150         uint8_t getMode();
00151         void setMode(uint8_t mode);
00152         uint8_t getRate();
00153         void setRate(uint8_t rate);
00154         uint8_t getComparatorMode();
00155         void setComparatorMode(uint8_t mode);
00156         uint8_t getComparatorPolarity();
00157         void setComparatorPolarity(uint8_t polarity);
00158         bool getComparatorLatchEnabled();
00159         void setComparatorLatchEnabled(bool enabled);
00160         uint8_t getComparatorQueueMode();
00161         void setComparatorQueueMode(uint8_t mode);
00162 
00163         // *_THRESH registers
00164         int16_t getLowThreshold();
00165         void setLowThreshold(int16_t threshold);
00166         int16_t getHighThreshold();
00167         void setHighThreshold(int16_t threshold);
00168 
00169     private:
00170         uint8_t devAddr;
00171         uint16_t buffer[2];
00172         uint8_t devMode;
00173         uint8_t muxMode;
00174         uint8_t pgaMode;
00175 };
00176 
00177 #endif /* _ADS1115_H_ */
 All Data Structures Functions Variables