-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
ADS_differential.ino
70 lines (54 loc) · 1.67 KB
/
ADS_differential.ino
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// FILE: ADS_differential.ino
// AUTHOR: Rob.Tillaart
// PURPOSE: read differential
// URL: https://github.com/RobTillaart/ADS1X15
// test 1
// connect 2 potmeters in series
//
// GND ---[ x ]------[ y ]---- 5V
// | |
//
// measure at x and y (connect to AIN0 and AIN1).
// x should be lower or equal to y
// test 2
// connect 2 potmeters parallel
//
// GND ---[ x ]------ 5V
// |
//
// GND ---[ y ]------ 5V
// |
//
// measure at x and y (connect to AIN0 and AIN1).
// range from -VDD .. +VDD are possible
#include <ADS1X15.h>
ADS1115 ADS(0x48);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0);
}
void loop()
{
int16_t val_01 = ADS.readADC_Differential_0_1();
int16_t val_03 = ADS.readADC_Differential_0_3();
int16_t val_13 = ADS.readADC_Differential_1_3();
int16_t val_23 = ADS.readADC_Differential_2_3();
float volts_01 = ADS.toVoltage(val_01);
float volts_03 = ADS.toVoltage(val_03);
float volts_13 = ADS.toVoltage(val_13);
float volts_23 = ADS.toVoltage(val_23);
Serial.print("\tval_01: "); Serial.print(val_01); Serial.print("\t"); Serial.println(volts_01, 3);
Serial.print("\tval_03: "); Serial.print(val_03); Serial.print("\t"); Serial.println(volts_03, 3);
Serial.print("\tval_13: "); Serial.print(val_13); Serial.print("\t"); Serial.println(volts_13, 3);
Serial.print("\tval_23: "); Serial.print(val_23); Serial.print("\t"); Serial.println(volts_23, 3);
Serial.println();
delay(1000);
}
// -- END OF FILE --