Skip to content

Commit 000c786

Browse files
Merge pull request #11 from AndyEngland521/master
updating config block to only be called once
2 parents a124757 + 82a5ddb commit 000c786

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
SparkFun VL53L1X Distance Sensor Library
2-
===========================================================
1+
SparkFun Qwiic 4m Distance Sensor with VL53L1X
2+
========================================
33

4-
![SparkFun VL53L1X Distance Sensor](https://cdn.sparkfun.com//assets/parts/1/2/8/6/3/14667-ToF_Laser_Distance_Sensor__Qwiic__-_VL53L1X-01.jpg)
4+
![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)
55

6-
[*SparkX Qwiic Distance Sensor - VL532L1X (SPX-14667)*](https://www.sparkfun.com/products/14667)
6+
[*SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)(SEN-14722)*](https://www.sparkfun.com/products/14722)
77

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

@@ -12,32 +12,34 @@ We’re far from done: The VL53L1X is a highly complex sensor with a multitude o
1212
We’ve found the precision of the sensor to be 1mm but the accuracy is around +/-5mm.
1313

1414
SparkFun labored with love to create this code. Feel like supporting open source hardware?
15-
Buy a [breakout board](https://www.sparkfun.com/products/14667) from SparkFun!
16-
17-
Library written by Nathan Seidle ([SparkFun](http://www.sparkfun.com)).
15+
Buy a [breakout board](https://www.sparkfun.com/products/14722) from SparkFun!
1816

1917
Repository Contents
2018
-------------------
2119

22-
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
23-
* **/src** - Source files for the library (.cpp, .h).
24-
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
25-
* **library.properties** - General library properties for the Arduino package manager.
20+
* **/Documents** - Datasheet and User Manual
21+
* **/Hardware** - Eagle design files (.brd, .sch)
22+
* **/Production** - .brd files
2623

2724
Documentation
2825
--------------
26+
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide)**
2927

30-
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
31-
* **[Product Repository](https://github.com/sparkfunX/Qwiic_Distance_VL53L1X)** - Main repository (including hardware files)
28+
Product Versions
29+
--------------
30+
* **[SEN-14722](https://www.sparkfun.com/products/14722)** - SparkFun red version
31+
* **[SPX-14667](https://www.sparkfun.com/products/14667)** - SparkX Version
3232

3333
License Information
3434
-------------------
3535

3636
This product is _**open source**_!
3737

38-
Various bits of the code have different licenses applied. Anything SparkFun wrote is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
38+
Please review the LICENSE.md file for license information.
39+
40+
If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com.
3941

40-
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.
42+
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release any derivative under the same license.
4143

4244
Distributed as-is; no warranty is given.
4345

examples/Example1_ReadDistance/Example1_ReadDistance.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ void setup(void)
2727

2828
if (distanceSensor.begin() == false)
2929
Serial.println("Sensor offline!");
30-
3130
}
3231

3332
void loop(void)
3433
{
35-
distanceSensor.startMeasurement(); //Write configuration bytes to initiate measurement
36-
3734
//Poll for completion of measurement. Takes 40-50ms.
3835
while (distanceSensor.newDataReady() == false)
3936
delay(5);

examples/Example2_SetDistanceMode/Example2_SetDistanceMode.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ void setup(void)
3434
Serial.println("Sensor offline!");
3535
}
3636
//Call setDistanceMode with 0, 1, or 2 to change the sensing range.
37-
distanceSensor.setDistanceMode(shortRange);
37+
distanceSensor.setDistanceMode(longRange);
3838
}
3939

4040
void loop(void)
4141
{
42-
distanceSensor.startMeasurement(); //Write configuration bytes to initiate measurement
43-
4442
//Poll for completion of measurement. Takes 40-50ms.
4543
while (distanceSensor.newDataReady() == false)
4644
delay(5);

examples/Example3_StatusAndRate/Example3_StatusAndRate.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ void setup(void)
4141
void loop(void)
4242
{
4343
long startTime = millis();
44-
distanceSensor.startMeasurement(); //Write configuration block of 135 bytes to setup a measurement
4544

4645
//Poll for completion of measurement. Takes 40-50ms.
4746
while (distanceSensor.newDataReady() == false)

src/SparkFun_VL53L1X_Arduino_Library.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//device against this set of bytes and write only the ones that are different but it's faster,
4545
//easier, and perhaps fewer code words to write the config block as is.
4646
//The block was obtained via inspection of the ST P-NUCLEO-53L1A1
47-
const PROGMEM uint8_t configBlock[] = {
47+
uint8_t configBlock[] = {
4848
0x29, 0x02, 0x10, 0x00, 0x28, 0xBC, 0x7A, 0x81, //8
4949
0x80, 0x07, 0x95, 0x00, 0xED, 0xFF, 0xF7, 0xFD, //16
5050
0x9E, 0x0E, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, //24
@@ -95,6 +95,13 @@ boolean VL53L1X::begin(uint8_t deviceAddress, TwoWire &wirePort)
9595
result = (result & 0xFE) | 0x01;
9696
writeRegister16(VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, result);
9797

98+
//Gets trim resistors from chip
99+
for (uint16_t i = 0; i < 36; i++) {
100+
uint8_t regVal = readRegister(i + 1);
101+
configBlock[i] = regVal;
102+
}
103+
startMeasurement();
104+
98105
return (true); //Sensor online!
99106
}
100107

@@ -106,7 +113,6 @@ boolean VL53L1X::begin(uint8_t deviceAddress, TwoWire &wirePort)
106113
void VL53L1X::startMeasurement(uint8_t offset)
107114
{
108115
uint8_t address = 1 + offset; //Start at memory location 0x01, add offset
109-
110116
uint8_t leftToSend = sizeof(configBlock) - offset;
111117
while (leftToSend > 0)
112118
{
@@ -119,7 +125,7 @@ void VL53L1X::startMeasurement(uint8_t offset)
119125
_i2cPort->write(address);
120126

121127
for (byte x = 0 ; x < toSend ; x++)
122-
_i2cPort->write(pgm_read_byte_near(configBlock + address + x - 1 - offset));
128+
_i2cPort->write(configBlock[address + x - 1 - offset]);
123129

124130
_i2cPort->endTransmission();
125131

@@ -388,5 +394,4 @@ boolean VL53L1X::writeRegister16(uint16_t addr, uint16_t val)
388394
if (_i2cPort->endTransmission() != 0)
389395
return (0); //Error: Sensor did not ACK
390396
return (1); //All done!
391-
}
392-
397+
}

0 commit comments

Comments
 (0)