-
Notifications
You must be signed in to change notification settings - Fork 20
/
ADS1115.ino
executable file
·65 lines (55 loc) · 1.54 KB
/
ADS1115.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
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// ADS1115
// This code is designed to work with the ADS1115_I2CADC I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Analog-Digital-Converters?sku=ADS1115_I2CADC#tabs-0-product_tabset-2
#include <Wire.h>
// ADS1115 I2C address is 0x48(72)
#define Addr 0x48
void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise Serial Communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x01);
// AINP = AIN0 and AINN = AIN1, +/- 2.048V
Wire.write(0x84);
// Continuous conversion mode, 128 SPS
Wire.write(0x83);
// Stop I2C Transmission
Wire.endTransmission();
delay(300);
}
void loop()
{
unsigned int data[2];
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// raw_adc msb, raw_adc lsb
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data
int raw_adc = (data[0] * 256) + data[1];
if (raw_adc > 32767)
{
raw_adc -= 65535;
}
// Output data to serial monitor
Serial.print("Digital Value of Analog Input : ");
Serial.println(raw_adc);
delay(500);
}