Skip to content

Commit 1773c55

Browse files
Merge pull request #18 from sparkfun/Intermeasurement-period
updating to lite, wrapped version of ST library
2 parents 0ad29f9 + 7a4755f commit 1773c55

21 files changed

+2695
-12879
lines changed

LICENSE.md

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,23 @@
1-
SparkFun License Information
2-
============================
3-
4-
SparkFun uses two different licenses for our files — one for hardware and one for code.
5-
6-
Hardware
7-
---------
8-
9-
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**
10-
11-
Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).
12-
13-
You are free to:
14-
15-
Share — copy and redistribute the material in any medium or format
16-
Adapt — remix, transform, and build upon the material
17-
for any purpose, even commercially.
18-
The licensor cannot revoke these freedoms as long as you follow the license terms.
19-
Under the following terms:
20-
21-
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
22-
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
23-
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
24-
Notices:
25-
26-
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
27-
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
28-
29-
30-
Code
31-
--------
32-
33-
**SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**
34-
35-
The MIT License (MIT)
36-
37-
Copyright (c) 2016 SparkFun Electronics
38-
39-
Permission is hereby granted, free of charge, to any person obtaining a copy
40-
of this software and associated documentation files (the "Software"), to deal
41-
in the Software without restriction, including without limitation the rights
42-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43-
copies of the Software, and to permit persons to whom the Software is
44-
furnished to do so, subject to the following conditions:
45-
46-
The above copyright notice and this permission notice shall be included in all
47-
copies or substantial portions of the Software.
48-
49-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55-
SOFTWARE.
1+
COPYRIGHT(c) 2018 STMicroelectronics
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
1. Redistributions of source code must retain the above copyright notice,
6+
this list of conditions and the following disclaimer.
7+
2. Redistributions in binary form must reproduce the above copyright notice,
8+
this list of conditions and the following disclaimer in the documentation
9+
and/or other materials provided with the distribution.
10+
3. Neither the name of STMicroelectronics nor the names of its contributors
11+
may be used to endorse or promote products derived from this software
12+
without specific prior written permission.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Reading distance from the laser based VL53L1X
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: April 4th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SparkFun labored with love to create this code. Feel like supporting open source hardware?
9+
Buy a board from SparkFun! https://www.sparkfun.com/products/14667
10+
11+
This example prints the distance to an object.
12+
13+
Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
14+
*/
15+
16+
#include <Wire.h>
17+
//#include "vl53l1x_class.h"
18+
#include "SparkFun_VL53L1X.h"
19+
20+
SFEVL53L1X distanceSensor(Wire, 2, 3);
21+
int distance;
22+
23+
void setup(void)
24+
{
25+
Wire.begin();
26+
27+
Serial.begin(9600);
28+
Serial.println("VL53L1X Qwiic Test");
29+
30+
if (distanceSensor.init() == 0)
31+
{
32+
Serial.println("Sensor online!");
33+
}
34+
}
35+
36+
void loop(void)
37+
{
38+
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
39+
distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
40+
distanceSensor.stopRanging(); //Write configuration bytes to initiate measurement
41+
42+
float distanceInches = distance * 0.0393701; //calculate Feet
43+
float distanceFeet = distanceInches / 12.0;
44+
45+
Serial.print("Distance(mm): ");
46+
Serial.print(distance);
47+
Serial.print("\tDistance(ft): ");
48+
Serial.print(distanceFeet, 2);
49+
50+
Serial.println();
51+
52+
}
53+

examples/Example1_ReadDistance/Example1_ReadDistance.ino renamed to examples/Example1_ReadDistance/Example1_ReadDistance/Example1_ReadDistance/Example1_ReadDistance.ino

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Date: April 4th, 2018
66
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
77
8-
SparkFun labored with love to create this code. Feel like supporting open source hardware?
8+
SparkFun labored with love to create this code. Feel like supporting open source hardware?
99
Buy a board from SparkFun! https://www.sparkfun.com/products/14667
1010
1111
This example prints the distance to an object.
@@ -14,9 +14,13 @@
1414
*/
1515

1616
#include <Wire.h>
17+
#include "SparkFun_VL53L1X.h"
1718

18-
#include "SparkFun_VL53L1X_Arduino_Library.h"
19-
VL53L1X distanceSensor;
19+
//Optional interrupt and shutdown pins.
20+
#define SHUTDOWN_PIN 2
21+
#define INTERRUPT_PIN 3
22+
23+
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2024

2125
void setup(void)
2226
{
@@ -25,20 +29,16 @@ void setup(void)
2529
Serial.begin(9600);
2630
Serial.println("VL53L1X Qwiic Test");
2731

28-
if (distanceSensor.begin() == false)
29-
Serial.println("Sensor offline!");
32+
if (distanceSensor.init() == false)
33+
Serial.println("Sensor online!");
3034

3135
}
3236

3337
void loop(void)
3438
{
35-
distanceSensor.startMeasurement(); //Write configuration bytes to initiate measurement
36-
37-
//Poll for completion of measurement. Takes 40-50ms.
38-
while (distanceSensor.newDataReady() == false)
39-
delay(5);
40-
39+
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
4140
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
41+
distanceSensor.stopRanging();
4242

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

examples/Example2_SetDistanceMode/Example2_SetDistanceMode.ino

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
*/
1515

1616
#include <Wire.h>
17+
#include "SparkFun_VL53L1X.h"
1718

18-
#include "SparkFun_VL53L1X_Arduino_Library.h"
19-
VL53L1X distanceSensor;
19+
//Optional interrupt and shutdown pins.
20+
#define SHUTDOWN_PIN 2
21+
#define INTERRUPT_PIN 3
2022

21-
uint8_t shortRange = 0;
22-
uint8_t midRange = 1;
23-
uint8_t longRange = 2;
23+
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2424

2525
void setup(void)
2626
{
@@ -29,21 +29,18 @@ void setup(void)
2929
Serial.begin(9600);
3030
Serial.println("VL53L1X Qwiic Test");
3131

32-
if (distanceSensor.begin() == false)
32+
if (distanceSensor.init() == false)
3333
{
34-
Serial.println("Sensor offline!");
34+
Serial.println("Sensor online!");
3535
}
36-
//Call setDistanceMode with 0, 1, or 2 to change the sensing range.
37-
distanceSensor.setDistanceMode(shortRange);
36+
37+
distanceSensor.setDistanceModeShort();
38+
//distanceSensor.setDistanceModeLong();
3839
}
3940

4041
void loop(void)
4142
{
42-
distanceSensor.startMeasurement(); //Write configuration bytes to initiate measurement
43-
44-
//Poll for completion of measurement. Takes 40-50ms.
45-
while (distanceSensor.newDataReady() == false)
46-
delay(5);
43+
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
4744

4845
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
4946

examples/Example3_StatusAndRate/Example3_StatusAndRate.ino

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
*/
1515

1616
#include <Wire.h>
17+
#include "SparkFun_VL53L1X.h"
1718

18-
#include "SparkFun_VL53L1X_Arduino_Library.h"
19-
VL53L1X distanceSensor;
19+
//Optional interrupt and shutdown pins.
20+
#define SHUTDOWN_PIN 2
21+
#define INTERRUPT_PIN 3
22+
23+
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2024

2125
//Store distance readings to get rolling average
2226
#define HISTORY_SIZE 10
@@ -26,13 +30,12 @@ byte historySpot;
2630
void setup(void)
2731
{
2832
Wire.begin();
29-
Wire.setClock(400000); //Increase I2C bus speed to 400kHz
3033

3134
Serial.begin(9600);
3235
Serial.println("VL53L1X Qwiic Test");
3336

34-
if (distanceSensor.begin() == false)
35-
Serial.println("Sensor offline!");
37+
if (distanceSensor.init() == false)
38+
Serial.println("Sensor online!");
3639

3740
for (int x = 0 ; x < HISTORY_SIZE ; x++)
3841
history[x] = 0;
@@ -41,21 +44,15 @@ void setup(void)
4144
void loop(void)
4245
{
4346
long startTime = millis();
44-
distanceSensor.startMeasurement(); //Write configuration block of 135 bytes to setup a measurement
45-
46-
//Poll for completion of measurement. Takes 40-50ms.
47-
while (distanceSensor.newDataReady() == false)
48-
delay(5);
49-
50-
long endTime = millis();
51-
47+
distanceSensor.startRanging(); //Write configuration block of 135 bytes to setup a measurement
5248
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
53-
49+
long endTime = millis();
50+
5451
Serial.print("Distance(mm): ");
5552
Serial.print(distance);
5653

5754
history[historySpot] = distance;
58-
if (historySpot++ == HISTORY_SIZE) historySpot = 0;
55+
if (++historySpot == HISTORY_SIZE) historySpot = 0;
5956

6057
long avgDistance = 0;
6158
for (int x = 0 ; x < HISTORY_SIZE ; x++)

0 commit comments

Comments
 (0)