Skip to content

Commit 3cd23cb

Browse files
authored
Merge pull request #7 from caternuson/master
added examples
2 parents e593d9e + bba0921 commit 3cd23cb

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

examples/ads1115_differential.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_ads1x15.differential import ADS1115
5+
6+
# Create the I2C bus
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# Create the ADC object using the I2C bus
10+
adc = ADS1115(i2c)
11+
12+
# Print header
13+
print("CHAN 0 - CHAN 1")
14+
print("{:>5}\t{:>5}".format('raw', 'v'))
15+
16+
while True:
17+
# Get raw reading for differential input between channel 0 and 1
18+
raw = adc[(0, 1)].value
19+
20+
# Get voltage reading for differential input between channel 0 and 1
21+
volts = adc[(0, 1)].volts
22+
23+
# Print results
24+
print("{:>5}\t{:>5.3f}".format(raw, volts))
25+
26+
# Sleep for a bit
27+
time.sleep(0.5)

examples/ads1115_single_ended.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_ads1x15.single_ended import ADS1115
5+
6+
# Create the I2C bus
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# Create the ADC object using the I2C bus
10+
adc = ADS1115(i2c)
11+
12+
# Print header
13+
print(" CHAN 0 CHAN 1 CHAN 2 CHAN 3")
14+
print("{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}"
15+
.format('raw', 'v', 'raw', 'v', 'raw', 'v', 'raw', 'v'))
16+
17+
while True:
18+
# Get raw readings for each channel
19+
r0 = adc[0].value
20+
r1 = adc[1].value
21+
r2 = adc[2].value
22+
r3 = adc[3].value
23+
24+
# Get voltage readings for each channel
25+
v0 = adc[0].volts
26+
v1 = adc[1].volts
27+
v2 = adc[2].volts
28+
v3 = adc[3].volts
29+
30+
# Print results
31+
print("{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}"
32+
.format(r0, v0, r1, v1, r2, v2, r3, v3))
33+
34+
# Sleep for a bit
35+
time.sleep(0.5)

0 commit comments

Comments
 (0)