Skip to content

Commit b5b178c

Browse files
authored
Create Single_Ended.ino
1 parent b00bf93 commit b5b178c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************
2+
* @file Single_Ended.ino
3+
*
4+
* @brief Example demonstrating single-ended analog readings
5+
* using the 7Semi ADS7830 8-bit ADC module.
6+
*
7+
* This sketch reads analog voltages from all 8 input channels
8+
* (CH0 to CH7) in single-ended mode over I2C and converts the
9+
* values into voltages using the internal 2.5V reference.
10+
*
11+
* Key features demonstrated:
12+
* - Single-ended channel reads
13+
* - 8-bit ADC resolution (0–2.5V scale)
14+
*
15+
* Connections:
16+
* - VCC -> 3.3V or 5V
17+
* - GND -> GND
18+
* - SDA -> A4 (Uno)
19+
* - SCL -> A5 (Uno)
20+
*
21+
* @section author Author
22+
* Written by 7Semi
23+
*
24+
* @section license License
25+
* @license MIT
26+
* Copyright (c) 2025 7Semi
27+
*******************************************************/
28+
29+
#include <7semi_ADS7830.h>
30+
31+
ADS7830_7semi adc; // Create ADS7830 object
32+
33+
void setup() {
34+
Serial.begin(115200);
35+
Wire.begin();
36+
37+
if (adc.begin()) {
38+
Serial.println("ADS7830 initialized");
39+
} else {
40+
Serial.println("ADS7830 not found!");
41+
while (1);
42+
}
43+
44+
// Enable internal 2.5V reference voltage
45+
// Use DISABLE to use external voltage via VREF pin
46+
adc.intRef(ENABLE);
47+
}
48+
49+
void loop() {
50+
// Array to hold readings from CH0 to CH7
51+
uint8_t values[8];
52+
53+
// Read all 8 channels using loop
54+
for (uint8_t i = 0; i < 8; i++) {
55+
values[i] = adc.readSingleCh(i);
56+
}
57+
58+
// Convert ADC reading (0–255) to voltage using scale factor
59+
float scale = 2.5 / 255.0;
60+
61+
Serial.println("=== Single-Ended Readings (in Volts) ===");
62+
for (uint8_t i = 0; i < 8; i++) {
63+
Serial.print("CH");
64+
Serial.print(i);
65+
Serial.print(": ");
66+
Serial.println(values[i] * scale, 3); // Print 3 decimal places
67+
}
68+
Serial.println("========================================");
69+
Serial.println();
70+
71+
delay(1000);
72+
}

0 commit comments

Comments
 (0)