ESP32 + ADS1015: Data rate configuration not matching expected SPS

radbrvip
Posts: 2
Joined: Mon Sep 08, 2025 7:29 pm

ESP32 + ADS1015: Data rate configuration not matching expected SPS

Postby radbrvip » Mon Sep 08, 2025 7:33 pm

Hi, how are you doing? My name is Emerson, I'm from Brazil and I'm trying to use the ADS1015 conversor circuit using an ESP32 and I²C protocol, my code has a setup as the code below, the trouble I'm having right now is to set the frequency rate, I'm trying to set it to 2400 SPS or 3300 SPS, any of the values as the table indicates on github, but the response time of the circuit is not following the rate configured.

Code: Select all

/*  
    Projeto: Conjunto de sensores ZMPT101B - SCT013 e conversor ADC ADS1115 com ESP32
    Autor: Emerson Nunes dos Santos
    Orientador: Idalmir de Souza Queiroz Júnior
    -- Versão 33 -- em teste...
*/

//DECLARAÇÃO DE BIBLIOTECAS
#include <Adafruit_ADS1X15.h>
#include <Arduino.h>
//DEFINES GERAIS
#define PIN_S_TENS 0 //PORTA LEITURA TENSÃO
#define PIN_S_CORR 1 //PORTA LEITURA CORRENTE




//DECLARAÇÃO DE OBJETOS
Adafruit_ADS1015 ads; //OBJETO REFERENTE A LEITURA DAS PORTAS DO SENSOR ADS1115

//FUNÇÃO DE CONFIGURAÇÃO DE CONEXÕES E VARIÁVEIS INICIAIS
void setup(void){
  //TEMPO PARA INICIALIZAÇÃO
  delay(5000);
  //INICIALIZAÇÃO DA TAXA DE TRANSMISSÃO DA COMUNICAÇÃO SERIAL
  Serial.begin(RATE_SERIAL);
  Serial.println("Serial initiated successfully!");
  Serial.println("Using rate = 115200 bits/s for Serial Transmission");
  Serial.println("Projeto: Conjunto de sensores ZMPT101B - SCT013 e conversor ADC ADS1015 com ESP32");
  Serial.println("Autor: Emerson Nunes dos Santos");
  Serial.println("Orientador: Idalmir de Souza Queiroz Júnior");
  Serial.println("-- Versão 33 -- em teste...");
  Serial.println("Horário sincronizado!");
  //INICIALIZAÇÃO DA COMUNICAÇÃO I2C
  Serial.println("Initializing I2C Wire configuration");
  Wire.begin(21, 22, 400000);
  Serial.println("I2C Wire initialized successfully!");
  //PRIMEIRO PRINT PARA MOSTRAR A FORM
  Serial.println("Initializing ADS1015 ADC Converter");
  Serial.println("Getting single-ended readings from AIN0 and AIN1");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  //DEFININDO O GANHO DE CONVERSÃO DO ADS1115
  ads.setGain(GAIN_ONE);// 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  //DEFININDO A FREQUÊNCIA DE AQUISIÇÃO DE DADOS DO ADS1115
  ads.setDataRate(RATE_ADS1015_3300SPS);
  //VERIFICAÇÃO SE INICIALIZAÇÃO FOI UM SUCESSO
  if (!ads.begin())
  {
    Serial.println("Failed to initialize ADS.");
    // while (1);
    // ESP.restart();
  }
  // Configura para modo contínuo no canal 0
  // ads.startADCReading(ADS1X15_REG_CONFIG_MUX_SINGLE_0, /*continuous=*/true);
  Serial.println("ADS1015 initialized successfully!");
  delay(2000);
  Serial.println("Iniciando medições: ");
  Serial.println("-------------------------------------------------");
}
and then in the void loop I'm trying to use this code, to verify the response time for 512 samples, and it's using more time than for the rate configured, it's like 84 SPS for a 3300 SPS configured rate, when using the continuous mode it's like 3400 SPS, but for singled ended mode it's not even close to the frequency rate of setup

Code: Select all

void LEITURA_ADS (){
  i = 0;
  int64_t t1 = esp_timer_get_time();
  // LEITURA DA TENSÃO COM FREQUÊNCIA DE AMOSTRAGEM DE 384 Hz (f_sinal*2 + acréscimo = 60*2 + 264)
  while(i < N_AMOSTRAS){
    leitura_corr_bin[i] = ads.readADC_SingleEnded(PIN_S_CORR);
    i ++;
  }
  int64_t dt1 = esp_timer_get_time() - t1;
  Serial.print("tempo leitura corr: ");
  Serial.println(dt1);
  delay(2000);
  i = 0;

}
Could you help me to solve it? I'm using the ADS1015 to acquire some current and voltage values to provide an harmonic analysis for my graduate research.


Best regards,

Emerson Santos

Sprite
Espressif staff
Espressif staff
Posts: 10599
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 + ADS1015: Data rate configuration not matching expected SPS

Postby Sprite » Tue Sep 09, 2025 10:07 am

FYI I renamed your post. We're humans here, we expect a human-readable topic title.

MicroController
Posts: 2663
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 + ADS1015: Data rate configuration not matching expected SPS

Postby MicroController » Tue Sep 09, 2025 1:53 pm

In single-conversion mode, I would expect more than 84 SPS, but definitely significantly less than the configured rate.
The reason is that I2C communication isn't really high-speed. In single-conversion mode, the MCU first sends a "start" command to the ADC, then keeps sending "reads" until the conversion is complete, then sends a "read" to read the data, and only then sends the next "start" command. This means that during the time it takes to do the data read and send the new start command the ADC is always idle, i.e. not doing a conversion.

I suggest to use continuous mode and the ADC's ALRT/RDY pin to reduce the communication overhead. (1. Start continuous conversion, 2. wait for RDY to be set, 3. read data, 4. goto 2.) This may not be (easily) possible with the library you're currently using.

radbrvip
Posts: 2
Joined: Mon Sep 08, 2025 7:29 pm

Re: ESP32 + ADS1015: Data rate configuration not matching expected SPS

Postby radbrvip » Tue Sep 09, 2025 3:08 pm

In single-conversion mode, I would expect more than 84 SPS, but definitely significantly less than the configured rate.
The reason is that I2C communication isn't really high-speed. In single-conversion mode, the MCU first sends a "start" command to the ADC, then keeps sending "reads" until the conversion is complete, then sends a "read" to read the data, and only then sends the next "start" command. This means that during the time it takes to do the data read and send the new start command the ADC is always idle, i.e. not doing a conversion.

I suggest to use continuous mode and the ADC's ALRT/RDY pin to reduce the communication overhead. (1. Start continuous conversion, 2. wait for RDY to be set, 3. read data, 4. goto 2.) This may not be (easily) possible with the library you're currently using.
Thank you for the help, I got the idea, so I will try to take the values using diretcly the wire configuration and the alrt and rdy pins, thank you very much!

Who is online

Users browsing this forum: Amazon [Bot], meta-externalagent, PerplexityBot, Semrush [Bot] and 6 guests