Arduino library 路 Sensors

ADS1X15 (Rob Tillaart): ADS1115 reads without blocking

Rob Tillaart鈥檚 ADS1X15 is the other popular driver for the ADS1115 and its family, with one class per chip: ADS1013, ADS1014, ADS1015, ADS1113, ADS1114 and ADS1115. You give the I2C address in the constructor, start Wire yourself, and read an input with readADC(channel).

Built in on Mokxi: #include <ADS1X15.h> and it builds, with nothing to install. Free, and no account needed.

What ADS1X15 does

Its gain numbers are the amplifier鈥檚 own settings rather than names: 0 for plus or minus 6.144 V, 1 for 4.096 V, 2 for 2.048 V, 4, 8 and 16 for the smaller ranges. toVoltage(1) tells you how many volts one count is at the current gain, so a reading times that factor is the input voltage.

Where the library shines is non-blocking reads. requestADC() starts a conversion and returns at once; isReady() says when it is done; getValue() collects it. A sketch can keep a display or a motor going while the converter works. In Mokxi the ADS1013, ADS1014 and ADS1015 classes read the ADS1115 part as 12 bits.

Library Manager nameADS1X15
AuthorRob Tillaart
Include#include <ADS1X15.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesSixteen-bit ADC, ADS1115

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <ADS1X15.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ADS1X15" by Rob Tillaart from the Arduino IDE鈥檚 Library Manager (Sketch, Include Library, Manage Libraries), or add ADS1X15 to lib_deps in PlatformIO. Mokxi follows the calls of release 0.6.2, so a sketch written here builds there too.

What to know in the simulator: The ADS1013, ADS1014 and ADS1015 classes read the ADS1115 part as twelve bits.

ESP32-C3 路 Arduino Uno 路 Arduino Nano 路 Arduino Mega 2560 路 Arduino Leonardo 路 SparkFun Pro Micro 路 Arduino Micro 路 ESP32-C6 路 Raspberry Pi Pico 路 Raspberry Pi Pico W 路 Seeed XIAO SAMD21 路 STM32 路 STM32 Nucleo-F411RE 路 STM32 Blue Pill 路 micro:bit V2 路 Arduino Uno R4 路 ESP32 DevKit 路 ESP32-S3-DevKitC-1 路 ESP8266 NodeMCU 路 Arduino Pro Mini 3.3 V 路 Seeed XIAO ESP32-C3 路 ESP32-C3 SuperMini 路 Seeed XIAO ESP32-C6 路 ESP32-DevKitC V4 路 LOLIN32 Lite 路 Wemos D1 R32 路 Cheap Yellow Display 路 TTGO T-Display 路 Seeed XIAO ESP32-S3 路 Arduino Nano ESP32 路 Arduino Nano RP2040 Connect 路 Seeed XIAO RP2040 路 Waveshare RP2040-Zero 路 Arduino Uno R4 WiFi

The calls you will use

In the order a sketch meets them.

ADS1115 ADS(0x48)

Creates the converter at address 0x48.

ADS.begin()

Checks the chip answers. Call Wire.begin() before it.

ADS.isConnected()

True when the address answers, for a clear message in setup().

ADS.setGain(0)

Sets the range: 0 is plus or minus 6.144 V, 1 is 4.096 V, 2 is 2.048 V, and 4, 8 and 16 are smaller.

int16_t raw = ADS.readADC(0)

Converts input 0 and waits for the result.

int16_t raw = ADS.readADC(0);
float f = ADS.toVoltage(1);
Serial.println(raw * f, 3);

ADS.toVoltage(1)

The voltage of one count at the current gain.

ADS.requestADC(0)

Starts a conversion on input 0 and returns at once. Poll isReady(), then read the result with getValue().

ADS.readADC_Differential_0_1()

The difference between inputs 0 and 1, with the other pairs beside it.

ADS.setDataRate(7)

Samples per second from 0 (8 a second) to 7 (860 a second). 4 is the default of 128.

Example: Read 3.3 V on an ADS1115 the Rob Tillaart way

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino 路 Arduino Uno R3
#include <ADS1X15.h>

ADS1115 ADS(0x48);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Serial.print("connected ");
  Serial.println(ADS.begin());
  ADS.setGain(1);  // +/-4.096 V
}

void loop() {
  int16_t a0 = ADS.readADC(0);
  int16_t a1 = ADS.readADC(1);
  float f = ADS.toVoltage(1);
  Serial.print("A0 ");
  Serial.print(a0);
  Serial.print(" = ");
  Serial.print(a0 * f, 3);
  Serial.print(" V, A1 ");
  Serial.println(a1);
  Serial.print("diff ");
  Serial.println(ADS.readADC_Differential_0_1());
  delay(1000);
}

Wiring

  • Arduino Uno R3 A4 to Sixteen-bit ADC, ADS1115 SDA
  • Arduino Uno R3 A5 to Sixteen-bit ADC, ADS1115 SCL
  • Arduino Uno R3 5V to Sixteen-bit ADC, ADS1115 VDD
  • Arduino Uno R3 GND to Sixteen-bit ADC, ADS1115 GND
  • Arduino Uno R3 3V3 to Sixteen-bit ADC, ADS1115 A0
  • Arduino Uno R3 GND to Sixteen-bit ADC, ADS1115 A1

Open it in the editor, wired and ready to run

Common errors and how to fix them

readADC() returns 0 or -1 on every channel

Check isConnected() first. If it is false, the address or wiring is wrong; if true, make sure Wire.begin() came before ADS.begin().

getValue() returns the same number twice

It was called before the conversion finished. After requestADC(), wait until isReady() is true before calling getValue().

A sketch from the Adafruit library will not compile

The two libraries have different class names and calls. Replace Adafruit_ADS1115 with ADS1115 ADS(0x48), readADC_SingleEnded() with readADC(), and computeVolts() with a reading times toVoltage(1).

Try ADS1X15 without installing anything

Open the example, change the sketch, and keep your version in a free account.