From a3d1c3ffafb8e6890582e75f20e90a26e13fdcee Mon Sep 17 00:00:00 2001 From: caternuson Date: Sat, 1 Jun 2019 08:03:28 -0700 Subject: [PATCH] add example --- examples/ads1x15_fast_read.py | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/ads1x15_fast_read.py diff --git a/examples/ads1x15_fast_read.py b/examples/ads1x15_fast_read.py new file mode 100644 index 0000000..8f0332d --- /dev/null +++ b/examples/ads1x15_fast_read.py @@ -0,0 +1,37 @@ +import time +import board +import busio +import adafruit_ads1x15.ads1015 as ADS +from adafruit_ads1x15.ads1x15 import Mode +from adafruit_ads1x15.analog_in import AnalogIn + +# Data collection setup +RATE = 3300 +SAMPLES = 1000 + +# Create the I2C bus with a fast frequency +i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000) + +# Create the ADC object using the I2C bus +ads = ADS.ADS1015(i2c) + +# Create single-ended input on channel 0 +chan0 = AnalogIn(ads, ADS.P0) + +# ADC Configuration +ads.mode = Mode.CONTINUOUS +ads.data_rate = RATE + +data = [None]*SAMPLES + +start = time.monotonic() + +# Read the same channel over and over +for i in range(SAMPLES): + data[i] = chan0.value + +end = time.monotonic() +total_time = end - start + +print("Time of capture: {}s".format(total_time)) +print("Sample rate requested={} actual={}".format(RATE, SAMPLES / total_time))