Skip to content

Commit 10c52e2

Browse files
Made slight tweaks to examples to get them to run on CircuitPython
1 parent 632022c commit 10c52e2

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

examples/Example1_ReadDistance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
readings, be sure the vacuum tape has been removed from the sensor.
5555
"""
5656

57-
import qwiic
57+
import qwiic_vl53l1x
5858
import time
5959

6060
print("VL53L1X Qwiic Test\n")
61-
ToF = qwiic.QwiicVL53L1X()
61+
ToF = qwiic_vl53l1x.QwiicVL53L1X()
6262
if (ToF.sensor_init() == None): # Begin returns 0 on a good init
6363
print("Sensor online!\n")
6464

examples/Example2_SetDistanceMode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
be sure the vacuum tape has been removed from the sensor.
5656
"""
5757

58-
import qwiic
58+
import qwiic_vl53l1x
5959
import time
6060

6161
print("VL53L1X Qwiic Test\n")
62-
ToF = qwiic.QwiicVL53L1X()
62+
ToF = qwiic_vl53l1x.QwiicVL53L1X()
6363

6464
if (ToF.sensor_init() == None): # Begin returns 0 on a good init
6565
print("Sensor online!\n")

examples/Example3_StatusandRate.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@
5959
removed from the sensor.
6060
"""
6161

62-
import qwiic
63-
import time, statistics
62+
import qwiic_vl53l1x
63+
import time
64+
65+
def mean(numbers):
66+
return float(sum(numbers)) / max(len(numbers), 1)
6467

6568
print("VL53L1X Qwiic Test\n")
66-
ToF = qwiic.QwiicVL53L1X()
69+
ToF = qwiic_vl53l1x.QwiicVL53L1X()
6770

68-
if (ToF.sensor_init() == None): # Begin returns 0 on a good init
71+
if (ToF.sensor_init() == None): # Begin returns 0 on a good init
6972
print("Sensor online!\n")
7073

7174
ToF.set_distance_mode(1) # Sets Distance Mode Short (Long- Change value to 2)
@@ -76,7 +79,7 @@
7679
start = time.time()
7780

7881
try:
79-
ToF.start_ranging() # Write configuration bytes to initiate measurement
82+
ToF.start_ranging() # Write configuration bytes to initiate measurement
8083
time.sleep(.005)
8184
distance.append(ToF.get_distance()) # Get the result of the measurement from the sensor
8285
time.sleep(.005)
@@ -91,10 +94,10 @@
9194
distanceFeet = distanceInches / 12.0
9295

9396
if len(distance) < 10:
94-
avgdistance = statistics.mean(distance)
97+
avgdistance = mean(distance)
9598
else:
9699
distance.remove(distance[0])
97-
avgdistance = statistics.mean(distance[len(distance)-10:len(distance)+1]) # Running average of last 10 measurements
100+
avgdistance = mean(distance[len(distance)-10:len(distance)+1]) # Running average of last 10 measurements
98101

99102
signalrate = ToF.get_signal_rate()
100103
rangestatus = ToF.get_range_status()

examples/Example4_SetIntermeasurementPeriod.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@
5555
readings, be sure the vacuum tape has been removed from the sensor.
5656
"""
5757

58-
import qwiic
58+
import qwiic_vl53l1x
5959
import time
6060

6161
print("VL53L1X Qwiic Test\n")
62-
ToF = qwiic.QwiicVL53L1X()
62+
ToF = qwiic_vl53l1x.QwiicVL53L1X()
6363

6464
if (ToF.sensor_init() == None): # Begin returns 0 on a good init
6565
print("Sensor online!\n")
6666

6767
ToF.set_inter_measurement_in_ms(40)
6868

69-
print("Inter Measurement Period (ms): %s \n", ToF.get_inter_measurement_in_ms())
69+
print("Inter Measurement Period (ms):", ToF.get_inter_measurement_in_ms())
7070

7171
while True:
7272
try:

0 commit comments

Comments
 (0)