A library for ADS1015 and ADS1115 from Texas Instruments.
Dependents: IGGE_Power ADS1015-hello_world ADS1115-hello_world frdm_rtos_Eth ... more
Use like this
#include "mbed.h" #include "Adafruit_ADS1015.h" #include "USBSerial.h" #define SERIAL_BAUD_RATE 9600 I2C i2c(p23, p18); Adafruit_ADS1015 ads(&i2c); USBSerial pc; // USB CDC serial port int main() { uint16_t reading; while (1) { reading = ads.readADC_SingleEnded(0); // read channel 0 pc.printf("reading: %d\r\n", reading); // print reading wait(2); // loop 2 sek } }
Library ported from Arduino at github repository.
Breakout boards from Adafruit: http://learn.adafruit.com/adafruit-4-channel-adc-breakouts/overview
GitHub repository: https://github.com/adafruit/Adafruit_ADS1X15
Diff: Adafruit_ADS1015.h
- Revision:
- 2:d864e21d4e58
- Parent:
- 0:8174d9ceeca1
- Child:
- 4:6445a678d458
diff -r 659ccb9047ed -r d864e21d4e58 Adafruit_ADS1015.h --- a/Adafruit_ADS1015.h Sun Nov 10 18:44:47 2013 +0000 +++ b/Adafruit_ADS1015.h Sat Oct 11 08:20:09 2014 +0000 @@ -104,47 +104,46 @@ #define ADS1015_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default) /*=========================================================================*/ -typedef enum -{ - GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V, - GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V, - GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V, - GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V, - GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V, - GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V +typedef enum { + GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V, + GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V, + GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V, + GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V, + GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V, + GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V } adsGain_t; class Adafruit_ADS1015 { protected: - // Instance-specific properties - uint8_t m_i2cAddress; - uint8_t m_conversionDelay; - uint8_t m_bitShift; - adsGain_t m_gain; - I2C* m_i2c; - + // Instance-specific properties + uint8_t m_i2cAddress; + uint8_t m_conversionDelay; + uint8_t m_bitShift; + adsGain_t m_gain; + I2C* m_i2c; + - public: - Adafruit_ADS1015(I2C* i2c = 0, uint8_t i2cAddress = ADS1015_ADDRESS); // set i2c adress = 0 to allow ADS1115 to use this as default constructor - uint16_t readADC_SingleEnded(uint8_t channel); - int16_t readADC_Differential_0_1(void); - int16_t readADC_Differential_2_3(void); - void startComparator_SingleEnded(uint8_t channel, int16_t threshold); - int16_t getLastConversionResults(); - void setGain(adsGain_t gain); - adsGain_t getGain(void); +public: + Adafruit_ADS1015(I2C* i2c = 0, uint8_t i2cAddress = ADS1015_ADDRESS); // set i2c adress = 0 to allow ADS1115 to use this as default constructor + uint16_t readADC_SingleEnded(uint8_t channel); + int16_t readADC_Differential_0_1(void); + int16_t readADC_Differential_2_3(void); + void startComparator_SingleEnded(uint8_t channel, int16_t threshold); + int16_t getLastConversionResults(); + void setGain(adsGain_t gain); + adsGain_t getGain(void); - private: - uint16_t readRegister(uint8_t i2cAddress, uint8_t reg); - void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value); +private: + uint16_t readRegister(uint8_t i2cAddress, uint8_t reg); + void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value); }; // Derive from ADS1105 & override construction to set properties class Adafruit_ADS1115 : public Adafruit_ADS1015 { - public: - Adafruit_ADS1115(I2C* i2c, uint8_t i2cAddress = ADS1015_ADDRESS); +public: + Adafruit_ADS1115(I2C* i2c, uint8_t i2cAddress = ADS1015_ADDRESS); - private: +private: }; \ No newline at end of file