Skip to content

Commit 1fe6fce

Browse files
authored
Create Basic.ino
1 parent c750ec2 commit 1fe6fce

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

examples/Basic/Basic.ino

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
*******************************************************
2+
* @file Basic.ino
3+
*
4+
* @brief Basic example demonstrating usage of the 7Semi ADS1xx5 library.
5+
*
6+
* This example initializes an ADS1015 (12-bit) or ADS1115 (16-bit) ADC over I2C
7+
* and reads voltages from all 4 channels in both single-ended and differential modes.
8+
*
9+
* Key features demonstrated:
10+
* - Reading single-ended input voltages from AIN0–AIN3
11+
* - Reading differential voltages (AIN0–AIN1 and AIN2–AIN3)
12+
* - Configuring programmable gain amplifier (PGA)
13+
*
14+
* @note This example requires the 7Semi ADS1xx5 library to be installed.
15+
* It supports both 7Semi ADS1015 and ADS1115 modules.
16+
*
17+
* @section author Author
18+
* Written by 7Semi
19+
*
20+
* @section license License
21+
* @license MIT
22+
* Copyright (c) 2025 7Semi
23+
*******************************************************/
24+
25+
#include <7semi_ADS1xx5.h>
26+
27+
// Create ADS1xx5_7semi object
28+
// default address 0x48
29+
ADS1xx5_7semi adc;
30+
31+
void setup() {
32+
Serial.begin(115200);
33+
delay(500);
34+
Serial.println("ADS1xx5 Test Begin");
35+
36+
if (!adc.begin()) {
37+
Serial.println("Failed to connect to ADS1xx5!");
38+
while (1)
39+
;
40+
}
41+
Serial.println("ADS1xx5 Connected");
42+
43+
// Optional: Set PGA (reference voltage)
44+
// Default: ±2.048V
45+
// To change: use
46+
// PGA_6_144V 6.144V
47+
// PGA_4_096V 4.096V
48+
// PGA_1_024V 1.024V
49+
// PGA_0_512V 0.512V
50+
// PGA_0_256V 0.256V
51+
adc.setRefV(PGA_2_048V); // ±2.048V full scale
52+
}
53+
54+
void loop() {
55+
Serial.println("Reading Single-Ended Channels:");
56+
for (int ch = 0; ch < 4; ch++) {
57+
float voltage = adc.readCH(ch);
58+
Serial.print("AIN");
59+
Serial.print(ch);
60+
Serial.print(": ");
61+
Serial.print(voltage, 6);
62+
Serial.println(" V");
63+
delay(50);
64+
}
65+
// MUX_AIN0_AIN1 AIN0 - AIN1
66+
// MUX_AIN0_AIN3 AIN0 - AIN3
67+
// MUX_AIN1_AIN3 AIN1 - AIN3
68+
// MUX_AIN2_AIN3 AIN2 - AIN3
69+
Serial.println("\n Reading Differential Voltages:");
70+
float diff0_1 = adc.readDiff(0); // AIN0 - AIN1
71+
float diff2_3 = adc.readDiff(3); // AIN2 - AIN3
72+
73+
Serial.print("AIN0 - AIN1: ");
74+
Serial.print(diff0_1, 6);
75+
Serial.println(" V");
76+
77+
Serial.print("AIN2 - AIN3: ");
78+
Serial.print(diff2_3, 6);
79+
Serial.println(" V");
80+
81+
Serial.println("------------------------------------------------");
82+
delay(2000);
83+
}

0 commit comments

Comments
 (0)