This repository was archived by the owner on May 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
add uart #1
Open
caseyjbrotherton
wants to merge
2
commits into
main
Choose a base branch
from
features/uart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add uart #1
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,28 @@ | |
| import busio | ||
| import board | ||
|
|
||
|
|
||
| import adafruit_vl53l0x | ||
|
|
||
| # Initialize I2C bus and sensor. | ||
| i2c1 = busio.I2C(board.GP5, board.GP4) | ||
| vl53_1 = adafruit_vl53l0x.VL53L0X(i2c1) | ||
| sensor1Range = -2.0 | ||
| sensor2Range = -2.0 | ||
|
|
||
| uart = busio.UART(board.GP0, board.GP1, baudrate=115200, bits=8, parity=None ) | ||
|
|
||
| print("new version - uart") | ||
| try: | ||
| i2c1 = busio.I2C(board.GP5, board.GP4) | ||
| vl53_1 = adafruit_vl53l0x.VL53L0X(i2c1) | ||
| except: | ||
| print("No 1st sensor connected") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these prints get saved anywhere where we could access them later? After a match for instance |
||
|
|
||
| i2c2 = busio.I2C(board.GP7, board.GP6) | ||
| vl53_2 = adafruit_vl53l0x.VL53L0X(i2c2) | ||
| try: | ||
| i2c2 = busio.I2C(board.GP7, board.GP6) | ||
| vl53_2 = adafruit_vl53l0x.VL53L0X(i2c2) | ||
| except: | ||
| print("No 2nd sensor connected") | ||
|
|
||
|
|
||
| # Optionally adjust the measurement timing budget to change speed and accuracy. | ||
| # See the example here for more details: | ||
|
|
@@ -28,5 +42,18 @@ | |
|
|
||
| # Main loop will read the range and print it every second. | ||
| while True: | ||
| print("{0}, {0}".format(vl53_1.range, vl53_2.range)) | ||
| time.sleep(1.0) | ||
| try: | ||
| sensor1Range = vl53_1.range | ||
| except: | ||
| sensor1Range = -1 | ||
|
|
||
|
|
||
| try: | ||
| sensor2Range = vl53_2.range | ||
|
|
||
| except: | ||
| sensor2Range = -1 | ||
| print("{0}, {1},".format(sensor1Range, sensor2Range)) | ||
| uart.write(bytearray("{0}, {1},\r\n".format(sensor1Range, sensor2Range))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why include the carriage return (\r)? Doesn't seem like the roboRIO code expects it |
||
|
|
||
| time.sleep(0.005) | ||
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.
Should these just be -2 so they don't get initialized as floating point values? If something weird happens and they fall through to the UART, it'll write a long floating point to string conversion (e.g. "-2.0000000"), won't it?
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.
good call, will change.