Skip to content

Commit

Permalink
Merge pull request #18 from sparkfun/Intermeasurement-period
Browse files Browse the repository at this point in the history
updating to lite, wrapped version of ST library
  • Loading branch information
AndyEngland521 authored Dec 21, 2018
2 parents 0ad29f9 + 7a4755f commit 1773c55
Show file tree
Hide file tree
Showing 21 changed files with 2,695 additions and 12,879 deletions.
78 changes: 23 additions & 55 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,23 @@
SparkFun License Information
============================

SparkFun uses two different licenses for our files — one for hardware and one for code.

Hardware
---------

**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**

Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).

You are free to:

Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material
for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:

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.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Notices:

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.
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.


Code
--------

**SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**

The MIT License (MIT)

Copyright (c) 2016 SparkFun Electronics

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:

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.
COPYRIGHT(c) 2018 STMicroelectronics

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.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Reading distance from the laser based VL53L1X
By: Nathan Seidle
SparkFun Electronics
Date: April 4th, 2018
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 prints the distance to an object.
Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
*/

#include <Wire.h>
//#include "vl53l1x_class.h"
#include "SparkFun_VL53L1X.h"

SFEVL53L1X distanceSensor(Wire, 2, 3);
int distance;

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

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

if (distanceSensor.init() == 0)
{
Serial.println("Sensor online!");
}
}

void loop(void)
{
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
distanceSensor.stopRanging(); //Write configuration bytes to initiate measurement

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

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

Serial.println();

}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Date: April 4th, 2018
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?
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 prints the distance to an object.
Expand All @@ -14,9 +14,13 @@
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h"

#include "SparkFun_VL53L1X_Arduino_Library.h"
VL53L1X distanceSensor;
//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Expand All @@ -25,20 +29,16 @@ void setup(void)
Serial.begin(9600);
Serial.println("VL53L1X Qwiic Test");

if (distanceSensor.begin() == false)
Serial.println("Sensor offline!");
if (distanceSensor.init() == false)
Serial.println("Sensor online!");

}

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

//Poll for completion of measurement. Takes 40-50ms.
while (distanceSensor.newDataReady() == false)
delay(5);

distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
distanceSensor.stopRanging();

Serial.print("Distance(mm): ");
Serial.print(distance);
Expand Down
25 changes: 11 additions & 14 deletions examples/Example2_SetDistanceMode/Example2_SetDistanceMode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h"

#include "SparkFun_VL53L1X_Arduino_Library.h"
VL53L1X distanceSensor;
//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

uint8_t shortRange = 0;
uint8_t midRange = 1;
uint8_t longRange = 2;
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
Expand All @@ -29,21 +29,18 @@ void setup(void)
Serial.begin(9600);
Serial.println("VL53L1X Qwiic Test");

if (distanceSensor.begin() == false)
if (distanceSensor.init() == false)
{
Serial.println("Sensor offline!");
Serial.println("Sensor online!");
}
//Call setDistanceMode with 0, 1, or 2 to change the sensing range.
distanceSensor.setDistanceMode(shortRange);

distanceSensor.setDistanceModeShort();
//distanceSensor.setDistanceModeLong();
}

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

//Poll for completion of measurement. Takes 40-50ms.
while (distanceSensor.newDataReady() == false)
delay(5);
distanceSensor.startRanging(); //Write configuration bytes to initiate measurement

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

Expand Down
27 changes: 12 additions & 15 deletions examples/Example3_StatusAndRate/Example3_StatusAndRate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h"

#include "SparkFun_VL53L1X_Arduino_Library.h"
VL53L1X distanceSensor;
//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

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

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

if (distanceSensor.begin() == false)
Serial.println("Sensor offline!");
if (distanceSensor.init() == false)
Serial.println("Sensor online!");

for (int x = 0 ; x < HISTORY_SIZE ; x++)
history[x] = 0;
Expand All @@ -41,21 +44,15 @@ void setup(void)
void loop(void)
{
long startTime = millis();
distanceSensor.startMeasurement(); //Write configuration block of 135 bytes to setup a measurement

//Poll for completion of measurement. Takes 40-50ms.
while (distanceSensor.newDataReady() == false)
delay(5);

long endTime = millis();

distanceSensor.startRanging(); //Write configuration block of 135 bytes to setup a measurement
int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor

long endTime = millis();

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

history[historySpot] = distance;
if (historySpot++ == HISTORY_SIZE) historySpot = 0;
if (++historySpot == HISTORY_SIZE) historySpot = 0;

long avgDistance = 0;
for (int x = 0 ; x < HISTORY_SIZE ; x++)
Expand Down
Loading

0 comments on commit 1773c55

Please sign in to comment.