Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions CircuitPy/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +15 to +16
Copy link
Copy Markdown

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, will change.


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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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:
Expand All @@ -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)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)