-
Notifications
You must be signed in to change notification settings - Fork 5
Support for gain and range settings #21
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 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84aa87a
add support to modify gain/integration for SI1145
aaronwmorris faf208d
update example with gain settings
aaronwmorris 474cdb4
add properties to enable high range modes
aaronwmorris 05fdade
mask gain bits on read
aaronwmorris c4e301e
read high range setting directly
aaronwmorris b83d030
update example with high signal range
aaronwmorris e9fddfd
script to test various ranges
aaronwmorris 62d7dfb
simplify settings
aaronwmorris 6affa74
typo
aaronwmorris 024cbd3
pylint updates
aaronwmorris dbf0d97
update copyright notices
aaronwmorris 20befa7
remove gain from simpletest. Add comments to gain test
FoamyGuy 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,82 @@ | ||
| # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries | ||
| # SPDX-FileCopyrightText: Copyright (c) 2022 Carter Nelson for Adafruit Industries | ||
| # | ||
| # SPDX-License-Identifier: Unlicense | ||
|
|
||
| import time | ||
| import board | ||
| import adafruit_si1145 | ||
|
|
||
| # setup I2C bus using board default | ||
| # change as needed for specific boards | ||
| i2c = board.I2C() # uses board.SCL and board.SDA | ||
| # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller | ||
|
|
||
| # setup sensor | ||
| si1145 = adafruit_si1145.SI1145(i2c) | ||
|
|
||
|
|
||
| print("Default Vis Gain: {}".format(si1145.vis_gain)) | ||
| print("Default IR Gain: {}".format(si1145.ir_gain)) | ||
| print("Default Vis High range: {}".format(str(si1145.als_vis_range_high))) | ||
| print("Default IR High range: {}".format(str(si1145.als_ir_range_high))) | ||
| print() | ||
|
|
||
|
|
||
| ### Low range | ||
| si1145.als_range_high = False # both settings | ||
| # si1145.als_vis_range_high = False | ||
| # si1145.als_ir_range_high = False | ||
| time.sleep(0.5) | ||
|
|
||
| # test reading attributes | ||
| print("Vis High range: {}".format(str(si1145.als_vis_range_high))) | ||
| print("IR High range: {}".format(str(si1145.als_ir_range_high))) | ||
| print() | ||
|
|
||
|
|
||
| gain_list = ( | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_1, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_2, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_4, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_8, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_16, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_32, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_64, | ||
| adafruit_si1145.GAIN_ADC_CLOCK_DIV_128, | ||
| ) | ||
|
|
||
|
|
||
| for gain in gain_list: | ||
| si1145.gain = gain # both gains | ||
| # si1145.vis_gain = gain | ||
| # si1145.ir_gain = gain | ||
|
|
||
| # test reading attributes | ||
| print("Vis Gain: {}".format(si1145.vis_gain)) | ||
| print("IR Gain: {}".format(si1145.ir_gain)) | ||
|
|
||
| vis, ir = si1145.als | ||
| uv_index = si1145.uv_index | ||
| print("Visible = {}, Infrared = {}, UV Index = {}".format(vis, ir, uv_index)) | ||
| print() | ||
| time.sleep(0.5) | ||
|
|
||
|
|
||
| ### High range | ||
| # In high range mode, sensor gain should be ~14.5 | ||
| si1145.als_range_high = True # both settings | ||
| # si1145.als_vis_range_high = True | ||
| # si1145.als_ir_range_high = True | ||
| time.sleep(0.5) | ||
|
|
||
|
|
||
| # test reading attributes | ||
| print("Vis High range: {}".format(str(si1145.als_vis_range_high))) | ||
| print("IR High range: {}".format(str(si1145.als_ir_range_high))) | ||
| print() | ||
|
|
||
|
|
||
| vis, ir = si1145.als | ||
| uv_index = si1145.uv_index | ||
| print("Visible = {}, Infrared = {}, UV Index = {}".format(vis, ir, uv_index)) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only need 1 copyright notice here instead of two.
Since it's a new file that you created now you can also update the year to 2024 and use your name or username instead of these ones.
You can also omit the "for Adafruit Industries" which is intended to indicate development work that was paid for by Adafruit.