DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ads1115.h File Reference

TI ADS1115 16-bit ADC codec (DETWS_ENABLE_ADS1115). More...

#include <stdint.h>

Go to the source code of this file.

Classes

struct  Ads1115Gain
 Programmable-gain settings (PGA register codes; full-scale +/- range). Config field values shifted into the config word, so integer constants in a namespacing struct - cast-free. More...
 
struct  Ads1115DataRate
 Data-rate settings (DR register codes; samples per second). More...
 

Macros

#define ADS1115_REG_CONVERSION   0x00
 conversion result register
 
#define ADS1115_REG_CONFIG   0x01
 configuration register
 

Functions

uint16_t ads1115_config_single (uint8_t channel, uint8_t gain, uint8_t dr)
 Build the 16-bit config word for a single-shot, single-ended reading of channel (0..3) at gain gain and data rate dr (comparator disabled). Out-of-range fields fall back to channel 0 / gain +/-2.048 V / 128 SPS.
 
int32_t ads1115_raw_to_uv (int16_t raw, uint8_t gain)
 Convert a signed 16-bit sample to microvolts for gain's full-scale range.
 
bool ads1115_begin (uint8_t addr)
 Initialize the I2C bus for the ADS1115 at addr.
 
bool ads1115_read_raw (uint8_t channel, uint8_t gain, int16_t *raw)
 Single-shot read of channel (0..3) at gain into raw.
 
bool ads1115_read_uv (uint8_t channel, uint8_t gain, int32_t *microvolts)
 Single-shot read of channel at gain, converted to microvolts in microvolts.
 

Detailed Description

TI ADS1115 16-bit ADC codec (DETWS_ENABLE_ADS1115).

The ADS1115 is a 4-channel 16-bit analog-to-digital converter on the I2C bus with a programmable-gain amplifier - far more resolution and range control than the ESP32's own ADC. A reading is a 16-bit config-register write (start, channel, gain, mode, data rate) followed by a 16-bit read of the conversion register; the signed result scales to a voltage by the selected gain's full-scale range.

This codec is pure and host-tested: ads1115_config_single builds the config word for a single-shot single-ended reading, and ads1115_raw_to_uv converts the signed sample to microvolts. On an ESP32 the binding writes the config, waits for the conversion, and reads it back over I2C (Wire); only that touches hardware.

A cheap solder-and-bench-test breakout: measure a battery, a potentiometer, or an analog sensor and bridge the reading onto the network.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file ads1115.h.

Macro Definition Documentation

◆ ADS1115_REG_CONVERSION

#define ADS1115_REG_CONVERSION   0x00

conversion result register

Definition at line 31 of file ads1115.h.

◆ ADS1115_REG_CONFIG

#define ADS1115_REG_CONFIG   0x01

configuration register

Definition at line 32 of file ads1115.h.

Function Documentation

◆ ads1115_config_single()

uint16_t ads1115_config_single ( uint8_t  channel,
uint8_t  gain,
uint8_t  dr 
)

Build the 16-bit config word for a single-shot, single-ended reading of channel (0..3) at gain gain and data rate dr (comparator disabled). Out-of-range fields fall back to channel 0 / gain +/-2.048 V / 128 SPS.

◆ ads1115_raw_to_uv()

int32_t ads1115_raw_to_uv ( int16_t  raw,
uint8_t  gain 
)

Convert a signed 16-bit sample to microvolts for gain's full-scale range.

◆ ads1115_begin()

bool ads1115_begin ( uint8_t  addr)

Initialize the I2C bus for the ADS1115 at addr.

Returns
true on ESP32.

◆ ads1115_read_raw()

bool ads1115_read_raw ( uint8_t  channel,
uint8_t  gain,
int16_t *  raw 
)

Single-shot read of channel (0..3) at gain into raw.

Returns
false on error.

◆ ads1115_read_uv()

bool ads1115_read_uv ( uint8_t  channel,
uint8_t  gain,
int32_t *  microvolts 
)

Single-shot read of channel at gain, converted to microvolts in microvolts.