From 173381644fa5e246e1e95c1f2ab403c35be5852c Mon Sep 17 00:00:00 2001 From: caseyjbrotherton Date: Sat, 11 Mar 2023 17:23:13 -0600 Subject: [PATCH 1/2] add uart Add write to uart and usb. Committing changes by @Asher123456789 that did try catch, and other modifications --- CircuitPy/code.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/CircuitPy/code.py b/CircuitPy/code.py index 5e0ba25..2e28ec0 100644 --- a/CircuitPy/code.py +++ b/CircuitPy/code.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries + SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # Simple demo of the VL53L0X distance sensor. @@ -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") -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) \ No newline at end of file + 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))) + + time.sleep(0.005) From 0ec24cac749d489397d5d722bf3e4d7b6f932dd6 Mon Sep 17 00:00:00 2001 From: caseyjbrotherton Date: Sun, 12 Mar 2023 11:22:49 -0500 Subject: [PATCH 2/2] Fix comment line --- CircuitPy/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CircuitPy/code.py b/CircuitPy/code.py index 2e28ec0..29a517f 100644 --- a/CircuitPy/code.py +++ b/CircuitPy/code.py @@ -1,4 +1,4 @@ - SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # Simple demo of the VL53L0X distance sensor.