Let me share one more thing.
When I used this library to modify SPS, a strange thing happened.
If you refer to the designer's website or the sample code, you will see that you can set the SPS by changing the following function,
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
//adc.setConvRate(ADS1115_128_SPS); //uncomment if you want to change the default
I followed this and ran the test with the SPS settings changed to 860, 128, and 8.
The raw data of time and voltage up to 5000msec recorded by mills() is attached.
Looking at this, it seems that the lower the SPS, the less noise there is.
By the way, the same thing does not happen when I reduce the number of trials by interposing delay() in the code and library I used before.
It may depend on the developer's settings or the source code, but I thought that the SPS may be related to the accuracy of the ADC. Does this give us a clue?
For reference, here is the datasheet for ADS1115. In addition, the code used in this project is attached.
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_0256); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channel
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
adc.setConvRate(ADS1115_8_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
}
void loop() {
float voltage = 0.0;
Serial.print(";");
Serial.print(millis());
Serial.print(";");
voltage = readChannel(ADS1115_COMP_0_GND);
Serial.println(voltage*1000,5);
}
float readChannel(ADS1115_MUX channel) {
float voltage = 0.0;
adc.setCompareChannels(channel);
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
return voltage;
}