-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathADS1115_new accuracy
30 lines (25 loc) · 1.69 KB
/
ADS1115_new accuracy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// https://passionelectronique.fr/tutorial-ads1115/
#include "ADS1X15.h" //https://github.com/RobTillaart/ADS1X15
ADS1115 ADS(0x48); // ADS1115 physically defined at address 0x48
void setup() {
Serial.begin(9600);
ADS.begin();
ADS.setGain(1); // We take the lowest gain (index 1), to have the measurement range 4.096 volt
ADS.setMode(1); // The ADC is told that measurements will be taken on demand, not continuously (0 = CONTINUOUS, 1 = SINGLE)
ADS.setDataRate(7); // We specify the speed of voltage measurement we want, from 0 to 7 (7 being the fastest, that is 860 samples per second)
ADS.readADC(0); // And we do an empty reading, to send all these parameters
}
void loop() {
// Request for voltage measurement at the ADC (results between -32768 and +32767)
int16_t count_A0 = ADS.readADC(0); // Voltage measurement of pin A0, relative to ground
int16_t count_A1 = ADS.readADC(1); // Voltage measurement of pin A1, relative to ground
int16_t count_A2 = ADS.readADC(2); // Voltage measurement of pin A2, relative to ground
int16_t count_A3 = ADS.readADC(3); // Voltage measurement of pin A3, relative to ground
float f = ADS.toVoltage(1); // voltage factor
Serial.print("\tAnalog0: "); Serial.print(count_A0); Serial.print('\t'); Serial.println(count_A0 * f, 30);
Serial.print("\tAnalog1: "); Serial.print(count_A1); Serial.print('\t'); Serial.println(count_A1 * f, 30);
Serial.print("\tAnalog2: "); Serial.print(count_A2); Serial.print('\t'); Serial.println(count_A2 * f, 30);
Serial.print("\tAnalog3: "); Serial.print(count_A3); Serial.print('\t'); Serial.println(count_A3 * f, 30);
Serial.println();
delay(1000);
}