From f7ab3dda9405010a6bf275f7c5516e29f4f3799a Mon Sep 17 00:00:00 2001 From: johnnohj <166672127+johnnohj@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:37:42 -0400 Subject: [PATCH 1/3] initial commit --- .pre-commit-config.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..4fdf32f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,24 @@ repos: - repo: https://github.com/python/black - rev: 23.3.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 + rev: v4.0.3 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace + - id: mixed-line-ending + args: + - --fix=lf - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + rev: v3.3.1 hooks: - id: pylint name: pylint (library code) From 24aa202def834e3cf72c6c5a53798f18a673223a Mon Sep 17 00:00:00 2001 From: johnnohj <166672127+johnnohj@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:38:11 -0400 Subject: [PATCH 2/3] initial commit --- .../adafruit_vl53l1x_displayio_simpletest.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/adafruit_vl53l1x_displayio_simpletest.py diff --git a/examples/adafruit_vl53l1x_displayio_simpletest.py b/examples/adafruit_vl53l1x_displayio_simpletest.py new file mode 100644 index 0000000..b72ba9c --- /dev/null +++ b/examples/adafruit_vl53l1x_displayio_simpletest.py @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# contributions by J Fletcher, adapting code by Prof Gallaugher: +# https://www.youtube.com/watch?v=cdx1A1xoEWc&t=5s +# tested on ESP32-S3 Reverse TFT Feather: +# https://www.adafruit.com/product/5691 +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_display_text.bitmap_label import Label +from terminalio import FONT +from displayio import Group +import adafruit_vl53l1x + +# create a main_group to hold anything we want to show on the display. +main_group = Group() + +# Create sensor object, communicating over the board's default I2C bus +# i2c = board.I2C() # uses board.SCL and board.SDA +i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +vl53 = adafruit_vl53l1x.VL53L1X(i2c) + +# Create a Label to show the readings. If you have a very small +# display you may need to change to scale=1. +display_output_label = Label(FONT, text="", scale=1) + +# place the label near the top left corner with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = (4, 4) + +# add the label to the main_group +main_group.append(display_output_label) + +# set the main_group as the root_group of the built-in DISPLAY +board.DISPLAY.root_group = main_group +# create a display object placeholder to be updated by the loop +screen = (f"Distance: {''}cm, {''}in, {''}ft") +# initiate repeated sensor readings +vl53.start_ranging() + + +# begin main loop +while True: + # There will be no values to populate at first, just the bare 'Distance: cm, in, ft' text + # Assuming the first 'try' succeeds, this will be updated once the loop starts over + display_output_label.text = screen + + # This 'try' sequence will either update the displayed items with fresh data or repeat the + # last available data. VL53L1X sensors output `None` when no object reflects the laser, + # e.g., there is nothing within 4 meters, or when objects pass too quickly in and out of + # view (usually perpendicular to the field of vision). + try: + if vl53.distance: # simple test to see there is a value to read; no value = exception + distance = vl53.distance # sets the variable (used by the display) to the sensor data + inches = distance*0.394 # VL53L1X outputs distance in metric, so we convert to imperial + screen = (f"Distance: {distance: .1f}cm, {inches: .1f}in, {inches/12: .1f}ft") + # if we made it this far, we have new data to display! + except TypeError: + repeat_screen = screen + screen = repeat_screen + # if things went sideways, we repeat the previous loop's data so we can try again + + time.sleep(0.25) From 9224eebe88dfdc2994f72a5e32840c514e03e4c6 Mon Sep 17 00:00:00 2001 From: johnnohj <166672127+johnnohj@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:51:34 -0400 Subject: [PATCH 3/3] format update, appease black --- .../adafruit_vl53l1x_displayio_simpletest.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/adafruit_vl53l1x_displayio_simpletest.py b/examples/adafruit_vl53l1x_displayio_simpletest.py index b72ba9c..a00640f 100644 --- a/examples/adafruit_vl53l1x_displayio_simpletest.py +++ b/examples/adafruit_vl53l1x_displayio_simpletest.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries # contributions by J Fletcher, adapting code by Prof Gallaugher: # https://www.youtube.com/watch?v=cdx1A1xoEWc&t=5s # tested on ESP32-S3 Reverse TFT Feather: @@ -17,7 +17,8 @@ # Create sensor object, communicating over the board's default I2C bus # i2c = board.I2C() # uses board.SCL and board.SDA -i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +i2c = board.STEMMA_I2C() +# For using the built-in STEMMA QT connector on a microcontroller vl53 = adafruit_vl53l1x.VL53L1X(i2c) # Create a Label to show the readings. If you have a very small @@ -34,7 +35,7 @@ # set the main_group as the root_group of the built-in DISPLAY board.DISPLAY.root_group = main_group # create a display object placeholder to be updated by the loop -screen = (f"Distance: {''}cm, {''}in, {''}ft") +screen = f"Distance: {''}cm, {''}in, {''}ft" # initiate repeated sensor readings vl53.start_ranging() @@ -45,19 +46,22 @@ # Assuming the first 'try' succeeds, this will be updated once the loop starts over display_output_label.text = screen - # This 'try' sequence will either update the displayed items with fresh data or repeat the - # last available data. VL53L1X sensors output `None` when no object reflects the laser, + # This 'try' sequence will either update the displayed items with fresh data or repeat the + # last available data. VL53L1X sensors output `None` when no object reflects the laser, # e.g., there is nothing within 4 meters, or when objects pass too quickly in and out of # view (usually perpendicular to the field of vision). try: - if vl53.distance: # simple test to see there is a value to read; no value = exception - distance = vl53.distance # sets the variable (used by the display) to the sensor data - inches = distance*0.394 # VL53L1X outputs distance in metric, so we convert to imperial - screen = (f"Distance: {distance: .1f}cm, {inches: .1f}in, {inches/12: .1f}ft") + if vl53.distance: + # simple test to see there is a value to read; no value = exception + distance = vl53.distance + # sets the variable (used by the display) to the sensor data + inches = distance * 0.394 + # VL53L1X outputs distance in metric, so we convert to imperial + screen = f"Distance: {distance: .1f}cm, {inches: .1f}in, {inches/12: .1f}ft" # if we made it this far, we have new data to display! - except TypeError: + except TypeError: repeat_screen = screen screen = repeat_screen # if things went sideways, we repeat the previous loop's data so we can try again - + time.sleep(0.25)