add example
This commit is contained in:
parent
96e97cfe1e
commit
a3d1c3ffaf
1 changed files with 37 additions and 0 deletions
37
examples/ads1x15_fast_read.py
Normal file
37
examples/ads1x15_fast_read.py
Normal file
|
|
@ -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))
|
||||
Loading…
Reference in a new issue