Skip to content

Commit caba0ea

Browse files
authored
Merge pull request #24 from caternuson/iss23_gain
Add gain example.
2 parents 0109b1f + 1b9a1af commit caba0ea

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/ads1x15_gain_example.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import time
2+
import board
3+
import busio
4+
#import adafruit_ads1x15.ads1015 as ADS
5+
import adafruit_ads1x15.ads1115 as ADS
6+
from adafruit_ads1x15.analog_in import AnalogIn
7+
8+
# Create the I2C bus
9+
i2c = busio.I2C(board.SCL, board.SDA)
10+
11+
# Create the ADS object
12+
#ads = ADS.ADS1015(i2c)
13+
ads = ADS.ADS1115(i2c)
14+
15+
# Create a sinlge ended channel on Pin 0
16+
# Max counts for ADS1015 = 2047
17+
# ADS1115 = 32767
18+
chan = AnalogIn(ads, ADS.P0)
19+
20+
# The ADS1015 and ADS1115 both have the same gain options.
21+
#
22+
# GAIN RANGE (V)
23+
# ---- ---------
24+
# 2/3 +/- 6.144
25+
# 1 +/- 4.096
26+
# 2 +/- 2.048
27+
# 4 +/- 1.024
28+
# 8 +/- 0.512
29+
# 16 +/- 0.256
30+
#
31+
gains = (2/3, 1, 2, 4, 8, 16)
32+
33+
while True:
34+
ads.gain = gains[0]
35+
print('{:5} {:5.3f}'.format(chan.value, chan.voltage), end='')
36+
for gain in gains[1:]:
37+
ads.gain = gain
38+
print(' | {:5} {:5.3f}'.format(chan.value, chan.voltage), end='')
39+
print()
40+
time.sleep(0.5)

0 commit comments

Comments
 (0)