Im trying to make the ADS1115 work with an ES32 board using the wire librarie and the adafruit one made for this device but i only get slow sampling.
Its the first time i use the ESP32 and i had some experience with the Arduino MEGA.
I've tried some examples that i found around but it only takes about 11-12 miliseconds per sample.
(to see that i probed the SCL pin in the scope when reading each 500 miliseconds.)
How fast sampling do you need? ADS1115 is not very fast - from the datasheet 'The ADS111x perform conversions at data rates up to 860 samples per second (SPS).' i.e. 1.16 ms. Why you not use the integrated ADC in ESP32? I'm think it's faster.
I need to get 250 samples per second, i was trying the following code and schematic.
#include <Arduino.h>
#include <Adafruit_ADS1X15.h>
#include <Wire.h>
#include <SPI.h>
Adafruit_ADS1115 anaDigConverter; // Se crea un objeto de la librería, llamado anaDigConverter
const float multiplier = 0.1875F; //
void setup(void)
{
Serial.begin(38400); // Se inicia el monitor serial
anaDigConverter.begin(); // Se inicia el AD1115
Wire.setClock(1000000);
Wire.begin();
}
void loop(void)
{
int16_t results = anaDigConverter.readADC_Differential_0_1(); // Creamos una variable donde se almacena la lectura diferencial.
Serial.print("Diferencial: ");
Serial.print(results);
Serial.print(" ");
Serial.print(results*multiplier);
Serial.println("mV");
delay(500);
}
I've been trying to get higher speed, but as i mention, only a single reading takes about 12 miliseconds and i need less than 4 miliseconds per single sampling reading.
I really would apreciate your help or aproach on the goal.
I don't have a solution but I think I know your limitation using the Adafruit library.
It appears the Adafruit library is setup to make a measurement each time
results = ads.readADC_Differential_0_1();
is called. The library has a 1 second delay so you will not be able to sample faster than that.
What you need to do (and I don't know how to do this) is to set the sample rate for 250 samples per second then set the converter to the continuous conversion mode.
The library has 'getDataRate' and 'setDataRate' commands. Use them to check the sampling rate and set another.
#define RATE_ADS1115_8SPS (0x0000) ///< 8 samples per second
#define RATE_ADS1115_16SPS (0x0020) ///< 16 samples per second
#define RATE_ADS1115_32SPS (0x0040) ///< 32 samples per second
#define RATE_ADS1115_64SPS (0x0060) ///< 64 samples per second
#define RATE_ADS1115_128SPS (0x0080) ///< 128 samples per second (default)
#define RATE_ADS1115_250SPS (0x00A0) ///< 250 samples per second
#define RATE_ADS1115_475SPS (0x00C0) ///< 475 samples per second
#define RATE_ADS1115_860SPS (0x00E0) ///< 860 samples per second
I still don't understand why you don't use the ESP32 its own ADC.
I don't know the OP's goal in choosing this converter but I know it is much better than the ESP32 internal A/D. The ADS1115 is a ΔΣ converter, slower than the ESP32 but much more noise resistant.
Hello JohnRob and thank you for giving me the welcome and answer the thread.
I want to answer flashko's question: I am using ADS1115 instead because i need to make an EEG, so the team ask me to design a device with a minimum resolution of 16 bit (they are making some EEG studies with another device with 24 bit resolution and it has like 16 channels but in this case we will be using only 2 differential channels)
So i've been looking for a cheap and easy to use ADC to make the measurements. Anyways i'll try the ESP32 ones, maybe we can find annother way to do that.
You might find it interesting / useful that a ΔΣ converter reacts to the input signal for the full time of the conversion.
A typical converter samples the voltage for an instant then converts that sample. If this sample was at a noise spike that spike will effect your reading.
With a ΔΣ converter a noise spike during the conversion will be integrated out (maybe the wrong term but it best describes the inner working of the converter).
Yes!... in fact i am not going to connect the electrodes directly to the ADC because i will get a noisy signal so in that case i have to use a differential amplifier and then get the signals from the electrodes and those devices will perform very well for the low frecuencies that i am working on.
Anyways the thing is that i need to understand how to configure the ADS1115 "manually" with the Wire.h library that is included in arduino IDE because i can't understand the specific libraries made specificly for the device.
Examples detailed deeply would be appreciated.
I'm reading the datasheet of the ADC to know how it works in detail.
Yes, thak you!... but anyways if i can't get the 250 SPS or master the device, i will not be able to do the tests and make a choice of how to connect, arrange or whatever this thing. I apreciate a lot your answer.
I'm sure you are aware of the safety precautions in recording EEG (specifically not electrocuting the patient) so will your device be powered from batteries? Will you be using scalp electrodes?
You will need a LOT of gain before you can measure usefully with the ADC.
I'm not sure I see why such high resolution is useful whan the signal is invariably accompanied by noise.
Hello guys, sorry for my delay, i was doing some familiar stuff.
No, i have not tried at all, but i will do it soon, this is the first time i have to use the I2C protocol so i am learning from it. I realized that i should configure the device to make it work as i want it to.
I'm aware of the safety and we are making the electrodes in a custom way. We are aproaching a gain of about 50.000 so there will be a good signal. We are using digital customized filters that are working fine for our purposes, so i don't have to be worried about it.
In this case, we get about 20 microVolts, but it depends on the signal you want to get. Our goal is to get the bigger and low frequency waves that ussualy are produced in a specific sleep stage and we are making studies only to learn how the sleep stages behaves.
About the reference electrode, we place it behind the ear, but there are also some other points depending of what electrodes you are using. I'm not an expert so there's not much to tell you certainly.
It has been my experience with ΔΣ converters that they are excellent for low frequency signals containing an appreciable amount of high frequency "noise". Whether you need the high resolution on not. The longer integration time "integrates out" the noise resulting in a usable signal. I have tried to "digitally" average the output of a sample and hold input ADC with no success.
One situation that drove this concept home was measuring thermocouple signals in an Automotive environment. We started with Successive Approximation conversion and found the noise made the data unusable. No amount of digital post filtering could provide acceptable data. We then switched to ΔΣ conversion which provided a usable signal.
@johnerrington would be interested in hearing your recommendation given the signal is below 50 Hz. And what IC do you recommend.