-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from caternuson/fast_read2
Fast channel reads via caching last channel
- Loading branch information
Showing
2 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |