ADS1115 ADC Component

This class allows using ADS1115 Analog to Digital converters (datasheet, adafruit) devices with esphomelib. Doing so requires some steps:

  1. Initialize the i2c bus with the pins you have SDA and SCL connected to:

    // inside setup()
    App.init_i2c(SDA_PIN, SCL_PIN);
  2. Create the “hub” or the ADS1115 device itself. The parameter you pass in here is the i2c

    address of the ADS1115. See set_address() for possible other addresses.

    // after init_i2c
    auto *ads1115 = App.make_ads1115_component(0x48);

    This will create an ADS1115 component which you can now use to create individual sensors.

  3. Create the sensors, you can have multiple of these. Do so by calling get_sensor() with

    the multiplexer channel you want (essentially between which pins you want to measure voltage) and the gain for that sensor and register that sensor.

    auto *sensor = ads1115->get_sensor("ADS1115 Voltage #1", sensor::ADS1115_MULTIPLEXER_P0_N1, sensor::ADS1115_GAIN_6P144);

See Application::make_ads1115_component().

API Reference

enum sensor::ADS1115Multiplexer


ADS1115_MULTIPLEXER_P0_N1 = 0b000
ADS1115_MULTIPLEXER_P0_N3 = 0b001
ADS1115_MULTIPLEXER_P1_N3 = 0b010
ADS1115_MULTIPLEXER_P2_N3 = 0b011
enum sensor::ADS1115Gain


ADS1115_GAIN_6P144 = 0b000
ADS1115_GAIN_4P096 = 0b001
ADS1115_GAIN_2P048 = 0b010
ADS1115_GAIN_1P024 = 0b011
ADS1115_GAIN_0P512 = 0b100
ADS1115_GAIN_0P256 = 0b101
class ADS1115Component : public Component, public I2CDevice

This class allows you to use your ADS1115 devices with esphomelib through i2c.

It is built of like the DallasComponent: A central hub (can be multiple ones) and multiple Sensor instances that all access this central hub.

Note that for this component to work correctly you need to have i2c setup. Do so with

App.init_i2c(SDA_PIN, SCL_PIN);

before the call to App.setup().

Public Functions

ADS1115Component(I2CComponent *parent, uint8_t address)

Construct the component hub for this ADS1115.

  • address: The i2c address for this sensor.

ADS1115Sensor *get_sensor(const std::string &name, ADS1115Multiplexer multiplexer, ADS1115Gain gain, uint32_t update_interval = 15000)

Get a sensor from this ADS1115 from the specified multiplexer and gain.

You can have one ADS1115 create multiple sensors with different multiplexers and/or gains.

An ADS1115Sensor, use this for advanced options.
  • multiplexer: The multiplexer, one of ADS1115_MULTIPLEXER_ then P0_N1, P0_N3, P1_N3, P2_N3, P0_NG, P1_NG, P2_NG, P3_NG.
  • gain: The gain, one of ADS1115_GAIN_then6P144,4P096,2P048,1P024, 0P512,0P256` (B/C).
  • update_interval: The interval in milliseconds the value for this sensor should be checked.

void setup()

Set up the internal sensor array.

void dump_config()
float get_setup_priority() const

HARDWARE_LATE setup priority.

Protected Functions

void request_measurement_(ADS1115Sensor *sensor)

Helper method to request a measurement from a sensor.

Protected Attributes

std::vector<ADS1115Sensor *> sensors_
class ADS1115Sensor : public sensor::EmptySensor<3, ICON_FLASH, UNIT_V>

Internal holder class that is in instance of Sensor so that the hub can create individual sensors.

Public Functions

ADS1115Sensor(const std::string &name, ADS1115Multiplexer multiplexer, ADS1115Gain gain, uint32_t update_interval)
void set_multiplexer(ADS1115Multiplexer multiplexer)
void set_gain(ADS1115Gain gain)
uint32_t update_interval()

Return with which interval the sensor is polled. Return 0 for non-polling mode.

uint8_t get_multiplexer() const
uint8_t get_gain() const

Protected Attributes

ADS1115Multiplexer multiplexer_
ADS1115Gain gain_
uint32_t update_interval_