From 98221f6cac81534b299ffb5db081ee063c430fff Mon Sep 17 00:00:00 2001 From: caternuson Date: Sun, 21 Jan 2018 12:44:07 -0800 Subject: [PATCH 1/3] added examples --- examples/ads1115_differential.py | 27 ++++++++++++++++++++++++ examples/ads1115_single_ended.py | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 examples/ads1115_differential.py create mode 100644 examples/ads1115_single_ended.py diff --git a/examples/ads1115_differential.py b/examples/ads1115_differential.py new file mode 100644 index 0000000..dd4e7aa --- /dev/null +++ b/examples/ads1115_differential.py @@ -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) diff --git a/examples/ads1115_single_ended.py b/examples/ads1115_single_ended.py new file mode 100644 index 0000000..ef5b5ea --- /dev/null +++ b/examples/ads1115_single_ended.py @@ -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) From 5fbbf1062f4356ed9a88daa0a4f404f4a0c355fe Mon Sep 17 00:00:00 2001 From: caternuson Date: Sun, 21 Jan 2018 13:41:24 -0800 Subject: [PATCH 2/3] a little white space for you, linty? --- examples/ads1115_differential.py | 4 ++-- examples/ads1115_single_ended.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/ads1115_differential.py b/examples/ads1115_differential.py index dd4e7aa..e9ff411 100644 --- a/examples/ads1115_differential.py +++ b/examples/ads1115_differential.py @@ -15,10 +15,10 @@ while True: # Get raw reading for differential input between channel 0 and 1 - raw = adc[(0,1)].value + raw = adc[(0, 1)].value # Get voltage reading for differential input between channel 0 and 1 - volts = adc[(0,1)].volts + volts = adc[(0, 1)].volts # Print results print("{:>5}\t{:>5.3f}".format(raw, volts)) diff --git a/examples/ads1115_single_ended.py b/examples/ads1115_single_ended.py index ef5b5ea..a6d6c20 100644 --- a/examples/ads1115_single_ended.py +++ b/examples/ads1115_single_ended.py @@ -12,7 +12,7 @@ # 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')) + .format('raw', 'v', 'raw', 'v', 'raw', 'v', 'raw', 'v')) while True: # Get raw readings for each channel @@ -29,7 +29,7 @@ # 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)) + .format(r0, v0, r1, v1, r2, v2, r3, v3)) # Sleep for a bit time.sleep(0.5) From bba0921a2e020d01d803256a1c5d71b3bd3d7146 Mon Sep 17 00:00:00 2001 From: caternuson Date: Sun, 21 Jan 2018 13:45:09 -0800 Subject: [PATCH 3/3] removed 1 space --- examples/ads1115_single_ended.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ads1115_single_ended.py b/examples/ads1115_single_ended.py index a6d6c20..8d6534a 100644 --- a/examples/ads1115_single_ended.py +++ b/examples/ads1115_single_ended.py @@ -29,7 +29,7 @@ # 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)) + .format(r0, v0, r1, v1, r2, v2, r3, v3)) # Sleep for a bit time.sleep(0.5)