Skip to content

added examples #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/ads1115_differential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time
import board
import busio
from adafruit_ads1x15.differential import ADS1115

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
adc = ADS1115(i2c)

# Print header
print("CHAN 0 - CHAN 1")
print("{:>5}\t{:>5}".format('raw', 'v'))

while True:
# Get raw reading for differential input between channel 0 and 1
raw = adc[(0, 1)].value

# Get voltage reading for differential input between channel 0 and 1
volts = adc[(0, 1)].volts

# Print results
print("{:>5}\t{:>5.3f}".format(raw, volts))

# Sleep for a bit
time.sleep(0.5)
35 changes: 35 additions & 0 deletions examples/ads1115_single_ended.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
import board
import busio
from adafruit_ads1x15.single_ended import ADS1115

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
adc = ADS1115(i2c)

# Print header
print(" CHAN 0 CHAN 1 CHAN 2 CHAN 3")
print("{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}"
.format('raw', 'v', 'raw', 'v', 'raw', 'v', 'raw', 'v'))

while True:
# Get raw readings for each channel
r0 = adc[0].value
r1 = adc[1].value
r2 = adc[2].value
r3 = adc[3].value

# Get voltage readings for each channel
v0 = adc[0].volts
v1 = adc[1].volts
v2 = adc[2].volts
v3 = adc[3].volts

# Print results
print("{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}"
.format(r0, v0, r1, v1, r2, v2, r3, v3))

# Sleep for a bit
time.sleep(0.5)