-
Notifications
You must be signed in to change notification settings - Fork 58
Added Comparator functionality #98
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
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
017fb9f
Added Comparator functionality
RoaCode c84a39d
Improved Comments
RoaCode 7d98fde
Addressed PR comments
RoaCode 0aa1cd7
Moved threshold writes to setters
RoaCode 29ee801
Fixed ads1x15 init comment
RoaCode a730639
Corrected Pylint issues
RoaCode f74e4f9
Correcting pylint issues
RoaCode 4ba6144
Moved 2's complement calculation to threshold setters
RoaCode 8ddd81c
Moved threshold defaults to subclass
RoaCode 657b768
Updated comments with threshold register info
RoaCode f7fd261
Removed 2s Complement calculations
RoaCode 3e31097
Removed bit truncation warning
RoaCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
import board | ||
import busio | ||
import countio | ||
|
||
import adafruit_ads1x15.ads1015 as ADS | ||
# import adafruit_ads1x15.ads1115 as ADS | ||
from adafruit_ads1x15.analog_in import AnalogIn | ||
|
||
# Create the I2C bus | ||
i2c = busio.I2C(board.SCL, board.SDA) | ||
|
||
# Create the ADS object | ||
ads = ADS.ADS1015(i2c) | ||
# ads = ADS.ADS1115(i2c) | ||
|
||
# Create a single-ended channel on Pin 0 | ||
# Max counts for ADS1015 = 2047 | ||
# ADS1115 = 32767 | ||
chan = AnalogIn(ads, ADS.P0) | ||
|
||
# Create Interrupt-driven input to track comparator changes | ||
int_pin = countio.Counter(board.GP9, edge=countio.Edge.RISE) | ||
|
||
# Set comparator to assert after 1 ADC conversion | ||
ads.compqueue = 1 | ||
# Set comparator low threshold to 2V | ||
ads.write_comparator_low_threshold(chan.ADC_value(2)) | ||
# Set comparator high threshold to 2.002V. High threshold must be above low threshold | ||
ads.write_comparator_high_threshold(chan.ADC_value(2.002)) | ||
|
||
count = 0 | ||
while True: | ||
print(chan.value, chan.voltage) #This initiates new ADC reading | ||
if int_pin.count > count: | ||
print("Comparator Triggered") | ||
count = int_pin.count | ||
time.sleep(2) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.