Skip to content

Commit

Permalink
Merge pull request #4759 from tonhuisman/bugfix/P113-apply-fix-for-sh…
Browse files Browse the repository at this point in the history
…ifted-i2c-address

[P113] Fix for shifted I2C address in library, code improvements
  • Loading branch information
TD-er authored Aug 13, 2023
2 parents 9297ac9 + 398e412 commit c25341d
Show file tree
Hide file tree
Showing 21 changed files with 579 additions and 132 deletions.
2 changes: 1 addition & 1 deletion docs/source/Plugin/P113.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ I2C Options

The available settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`

**I2C Address**: The address the device is using. The chip allows to select the secondary address and keep that active until the next power-cycle of the sensor.
**I2C Address**: The address the device is using. Because of an issue with changing the I2C address of the sensor, this list is limited to 1 item, and the address isn't changed/set.

Device Settings
^^^^^^^^^^^^^^^^
Expand Down
96 changes: 96 additions & 0 deletions lib/SparkFun_VL53L1X/.github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# LibraryBuild.yml
# Github workflow script to test compile all examples of an Arduino library repository.
#
# Copyright (C) 2020 Armin Joachimsmeyer
# https://github.com/ArminJo/Github-Actions
# License: MIT
#
# Before being able to push to my .github\workflows directories,
# I had to create a new personal token with workflow enabled at https://github.com/settings/tokens

# This is the name of the workflow, visible on GitHub UI.
name: LibraryBuild
on:
push: # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request
paths:
- '**.ino'
- '**.cpp'
- '**.h'
- '**LibraryBuild.yml'
pull_request:

jobs:
build:
name: ${{ matrix.arduino-boards-fqbn }} - test compiling examples

runs-on: ubuntu-18.04 # I picked Ubuntu to use shell scripts.

env:
# Comma separated list without double quotes around the list.
PLATFORM_DEFAULT_URL: https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json
REQUIRED_LIBRARIES: EspSoftwareSerial

strategy:
matrix:
# The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn`
# In the Arduino IDE, the fqbn is printed in the first line of the verbose output for compilation as parameter -fqbn=... for the "arduino-builder -dump-prefs" command
#
# Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega
# arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native"
# ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro
# STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
# esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80
# You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
#############################################################################################################
arduino-boards-fqbn:
- arduino:avr:uno
- arduino:avr:leonardo
- arduino:avr:mega
- arduino:sam:arduino_due_x
- SparkFun:apollo3:artemis
- SparkFun:apollo3:amap3redboard
- SparkFun:apollo3:amap3nano
- SparkFun:apollo3:amap3atp
- SparkFun:apollo3:amap3thing
- SparkFun:apollo3:edge
- SparkFun:apollo3:edge2
- esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
- esp32:esp32:featheresp32:FlashFreq=80
- STM32:stm32:GenF1:pnum=BLUEPILL_F103C8

# Choose the right platform for the boards we want to test. (maybe in the future Arduino will automatically do this for you).
# This works like this: when the fqbn is "arduino:avr:uno" the variable `platform` is set to "arduino:avr".
# Just take the first 2 token of the fqbn - this cannot be automatically done by GitHub workflow :-(
# You may exclude specific examples for a board with examples-exclude: Use a space separated list.
#############################################################################################################
include:
- arduino-boards-fqbn: arduino:sam:arduino_due_x
examples-exclude: Example5_LCDDemo # No SoftwareSerial available. Space separated list of (unique substrings of) example names to exclude in build

- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json

- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
platform-url: https://dl.espressif.com/dl/package_esp32_index.json

- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/dev/STM32/package_stm_index.json

# Do not cancel all jobs / architectures if one job fails
fail-fast: false

# This is the list of steps this job will run.
steps:

# First of all, we clone the repo using the `checkout` action.
- name: Checkout
uses: actions/checkout@v2

- name: Compile all examples
uses: ArminJo/arduino-test-compile@v2
with:
required-libraries: ${{ env.REQUIRED_LIBRARIES }}
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
platform-default-url: ${{ env.PLATFORM_DEFAULT_URL }}
platform-url: ${{ matrix.platform-url }}
examples-exclude: ${{ matrix.examples-exclude }}
31 changes: 10 additions & 21 deletions lib/SparkFun_VL53L1X/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
COPYRIGHT(c) 2018 STMicroelectronics
Copyright © 2022 SparkFun Electronics

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of STMicroelectronics nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
36 changes: 25 additions & 11 deletions lib/SparkFun_VL53L1X/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ SparkFun Qwiic 4m Distance Sensor with VL53L1X
[![Build Status](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/workflows/LibraryBuild/badge.svg)](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/actions)


![SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)](https://cdn.sparkfun.com//assets/parts/1/2/9/4/8/14722-SparkFun_Distance_Sensor_Breakout-_4_Meter__VL53L1X__Qwiic_-01.jpg)
<table class="table table-hover table-striped table-bordered">
<tr align="center">
<td><a href="https://www.sparkfun.com/products/14722"><img src="https://cdn.sparkfun.com//assets/parts/1/2/9/4/8/14722-SparkFun_Distance_Sensor_Breakout-_4_Meter__VL53L1X__Qwiic_-01.jpg" alt="SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)"></a></td>
<td><a href="https://www.sparkfun.com/products/18993"><img src="https://cdn.sparkfun.com//assets/parts/1/8/5/7/2/18993-SparkFun_Distance_Sensor_-_1.3_Meter__VL53L4CD__Qwiic_-01.jpg" alt="SparkFun Distance Sensor - 1.3 Meter, VL53L4CD (Qwiic)"></a></td>
</tr>
<tr align="center">
<td>SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic) <i>[<a href="https://www.sparkfun.com/products/14722">SEN-14722</a>]</i></td>
<td>SparkFun Distance Sensor - 1.3 Meter, VL53L4CD (Qwiic)<i>[<a href="https://www.sparkfun.com/products/18993">SEN-18993</a>]</i></td>
</tr>
</table>

[*SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)(SEN-14722)*](https://www.sparkfun.com/products/14722)
The VL53L1X is a Time Of Flight (ToF) sensor that use a VCSEL (vertical cavity surface emitting laser) to emit a class 1 IR laser and time the reflection to the target. What does all this mean? Using the VL53L1X, you can measure the distance to an object up to 4 meters away with millimeter resolution! That’s pretty incredible.

The VL53L1X is the latest Time Of Flight (ToF) sensor to be released. It uses a VCSEL (vertical cavity surface emitting laser) to emit a class 1 IR laser and time the reflection to the target. What does all this mean? You can measure the distance to an object up to 4 meters away with millimeter resolution! That’s pretty incredible.
We’re far from done: The VL53L1X is a highly complex sensor with a multitude of options and configurations. We’ve written example sketches that allow you to read the distance, signal rate, and range status. Because STMicroelectronics has chosen not to release a complete datasheet we are forced to reverse engineer the interface from their example code and I2C data stream captures. If you’re into puzzles we could use your help to make the library better!

We’re far from done: The VL53L1X is a highly complex sensor with a multitude of options and configurations. We’ve written example sketches that allow you to read the distance, signal rate, and range status. Because ST has chosen not to release a complete datasheet we are forced to reverse engineer the interface from their example code and I2C data stream captures. If you’re into puzzles we could use your help to make the library better!

We’ve found the precision of the sensor to be 1mm but the accuracy is around +/-5mm.
We’ve found the precision of VL53L1X sensor to be 1mm but the accuracy is around +/-5mm.

SparkFun labored with love to create this code. Feel like supporting open source hardware?
Buy a [breakout board](https://www.sparkfun.com/products/14722) from SparkFun!

*Note: The VL53L4CD is the cousin of VL53L1X. Overall, the sensor functions the same except for a few differences in the specifications. We've also found the precision of VL53L4CD sensor to be 1mm but the accuracy is around +/-7mm (white target: 88%, indoor, no infrared).*

Repository Contents
-------------------

Expand All @@ -25,17 +34,20 @@ Repository Contents

Documentation
--------------
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide)**
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-vl53l4cd-hookup-guide)**- Basic tutorial for the VL53L1X and VL53L4CD

Product Versions
Products that use this Library
--------------
* **[SEN-14722](https://www.sparkfun.com/products/14722)** - SparkFun red version
* **[SPX-14667](https://www.sparkfun.com/products/14667)** - SparkX Version

* **[SEN-18993](https://www.sparkfun.com/products/18993)** - SparkFun red version for VL53L4CD
* **[SEN-14722](https://www.sparkfun.com/products/14722)** - SparkFun red version for VL53L1X
* **[SPX-14667](https://www.sparkfun.com/products/14667)** - SparkX Version for VL53L1X

License Information
-------------------

This product is _**open source**_!
SparkFun's source files are _**open source**_!

Please review the LICENSE.md file for license information.

Expand All @@ -45,4 +57,6 @@ Please use, reuse, and modify these files as you see fit. Please maintain attrib

Distributed as-is; no warranty is given.

The source files included in the subfolder **st_src** are licensed differently. They are licensed under the BSD-3 license, check the License.md in
that subfolder for specifics.
- Your friends at SparkFun.
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#include <ComponentObject.h>
#include <RangeSensor.h>
#include <SparkFun_VL53L1X.h>
#include <vl53l1x_class.h>
#include <vl53l1_error_codes.h>

/*
Reading distance from the laser based VL53L1X
By: Nathan Seidle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#include <Arduino.h>

#include <ComponentObject.h>
#include <RangeSensor.h>
#include <SparkFun_VL53L1X.h>
#include <vl53l1x_class.h>
#include <vl53l1_error_codes.h>

/*
Calling distance offset calibration for the laser based VL53L1X
By: Armin Joachimsmeyer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Reading distance from the laser based VL53L1X
By: Nathan Seidle
Revised by: Andy England and Ricardo Ramos
SparkFun Electronics
Date: January 21st, 2022
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
SparkFun labored with love to create this code. Feel like supporting open source hardware?
Buy a board from SparkFun! https://www.sparkfun.com/products/14667
This example sets high and low thresholds for detection.
Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h" //Click here to get the library: http://librarymanager/All#SparkFun_VL53L1X

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Wire.begin();

Serial.begin(115200);
Serial.println("VL53L1X Qwiic Test");

if (distanceSensor.begin() != 0) //Begin returns 0 on a good init
{
Serial.println("Sensor failed to begin. Please check wiring. Freezing...");
while (1)
;
}
Serial.println("Sensor online!");

DetectionConfig dc; // struct instance which holds the detection configuration
dc.IntOnNoTarget = 1; // No longer used - just use 1 per ST
dc.distanceMode = DISTANCE_SHORT; // short distance mode
dc.thresholdHigh = 300; // high threshold of 300 mm
dc.thresholdLow = 70; // low threshold of 70 mm
dc.windowMode = WINDOW_IN; // will measure and trigger interrrupt when measurement fall between 70 and 300 mm

if(distanceSensor.setThresholdConfig(&dc) == true)
{
Serial.println("Thresholds programmed. Reading configuration back...");
dc = {};
if(distanceSensor.getThresholdConfig(&dc) == true)
{
Serial.print("IntOnNoTarget: ");
Serial.println(dc.IntOnNoTarget);
Serial.print("Distance Mode: ");

if(dc.distanceMode == DISTANCE_SHORT)
Serial.println("DISTANCE_SHORT (0)");
else
Serial.println("DISTANCE_LONG (1)");

Serial.print("Threshold High: ");
Serial.println(dc.thresholdHigh);
Serial.print("Threshold Low: ");
Serial.println(dc.thresholdLow);
Serial.print("Window mode: ");
switch (dc.windowMode)
{
case WINDOW_BELOW:
Serial.println("WINDOW_BELOW (0)");
break;

case WINDOW_ABOVE:
Serial.println("WINDOW_ABOVE (1)");
break;

case WINDOW_OUT:
Serial.println("WINDOW_OUT (2)");
break;

case WINDOW_IN:
Serial.println("WINDOW_IN (3)");
break;

default:
break;
}
}
}
else
{
Serial.println("Could not set threshold configuration.");
}
Serial.println("Starting measurements in 2 seconds.");
delay(2000);
Serial.println("Measurements started!");

}

void loop(void)
{
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement

while (!distanceSensor.checkForDataReady())
{
delay(1);
}
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
distanceSensor.clearInterrupt();

distanceSensor.stopRanging();

Serial.print("Distance(mm): ");
Serial.print(distance);

float distanceInches = distance * 0.0393701;
float distanceFeet = distanceInches / 12.0;

Serial.print("\tDistance(ft): ");
Serial.print(distanceFeet, 2);

Serial.println();
}
Loading

0 comments on commit c25341d

Please sign in to comment.