12#if DETWS_ENABLE_ADS1115
17const uint16_t OS_SINGLE = 0x8000;
18const uint16_t MUX_SINGLE0 = 0x4000;
19const uint16_t MODE_SINGLE = 0x0100;
20const uint16_t COMP_DISABLE = 0x0003;
23const uint16_t PGA_BITS[6] = {0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0A00};
24const int32_t FSR_UV[6] = {6144000, 4096000, 2048000, 1024000, 512000, 256000};
35 uint16_t cfg = OS_SINGLE;
36#if DETWS_ADS1115_DIFFERENTIAL
37 cfg |= (uint16_t)((uint16_t)channel << 12);
39 cfg |= (uint16_t)(MUX_SINGLE0 | ((uint16_t)channel << 12));
41 cfg |= PGA_BITS[gain];
43 cfg |= (uint16_t)((uint16_t)dr << 5);
52 return (int32_t)((int64_t)raw * FSR_UV[gain] / 32768);
75bool wr16(uint8_t reg, uint16_t v)
77 Wire.beginTransmission(s_ads.addr);
79 Wire.write((uint8_t)(v >> 8));
80 Wire.write((uint8_t)(v & 0xFF));
81 return Wire.endTransmission() == 0;
84bool rd16(uint8_t reg, uint16_t *v)
86 Wire.beginTransmission(s_ads.addr);
88 if (Wire.endTransmission(
false) != 0)
90 if (Wire.requestFrom((
int)s_ads.addr, 2) != 2)
92 uint8_t hi = (uint8_t)Wire.read();
93 uint8_t lo = (uint8_t)Wire.read();
94 *v = (uint16_t)(((uint16_t)hi << 8) | lo);
116 static const uint16_t ads1115_sps[8] = {8, 16, 32, 64, 128, 250, 475, 860};
117 delay(1000u / ads1115_sps[dr] + 1);
125bool ads1115_read_uv(uint8_t channel, uint8_t gain, int32_t *microvolts)
User-facing configuration for DeterministicESPAsyncWebServer.
#define DETWS_ADS1115_I2C_ADDR
I2C address of the ADS1115 (0x48 with ADDR to GND; 0x49/0x4A/0x4B for VDD/SDA/SCL).
#define DETWS_ADS1115_DR
Default ADS1115 data-rate code (ADS1115_DR_*): 0=8, 1=16, 2=32, 3=64, 4=128 (default),...
#define DETWS_ADS1115_GAIN
Default ADS1115 PGA gain code (ADS1115_GAIN_*): 0=+/-6.144V, 1=+/-4.096V, 2=+/-2.048V (default),...
TI ADS1115 16-bit ADC codec (DETWS_ENABLE_ADS1115).
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....
bool ads1115_begin(uint8_t addr)
Initialize the I2C bus for the ADS1115 at addr.
#define ADS1115_REG_CONVERSION
conversion result register
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.
#define ADS1115_REG_CONFIG
configuration register
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.
The one owner of the shared I2C bus bring-up for the peripheral drivers.
void detws_i2c_begin()
Bring up the shared I2C bus on DETWS_I2C_SDA_PIN / DETWS_I2C_SCL_PIN (-1 = default).
static constexpr uint8_t ADS1115_DR_128
128 SPS (default)
static constexpr uint8_t ADS1115_DR_860
860 SPS
static constexpr uint8_t ADS1115_GAIN_16
+/- 0.256 V