-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cparata/master
First release of the X-NUCLEO-53L0A1 library
- Loading branch information
Showing
10 changed files
with
1,253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
COPYRIGHT(c) 2017 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,48 @@ | ||
# X-NUCLEO-53L0A1 | ||
|
||
Arduino library to support the X-NUCLEO-53L0A1 based on VL53L0X Time-of-Flight and gesture-detection sensor | ||
This sensor uses I2C to communicate. An I2C instance is required to access to the sensor. | ||
The APIs provide simple distance measure, single swipe gesture detection, | ||
directional (left/right) swipe gesture detection and single tap gesture detection. | ||
|
||
## Examples | ||
|
||
There are 4 examples with the X-NUCLEO-53L0A1 library. | ||
* X_NUCLEO_53L0A1_HelloWorld: This example code is to show how to get proximity | ||
values of the onboard VL53L0X sensor and eventually of the two satellites | ||
|
||
* X_NUCLEO_53L0A1_Gesture_DirSwipe: This example code is to show how to combine the | ||
proximity values of the two VL53L0X sensor satellites together with the gesture library | ||
in order to detect a directional swipe gesture. | ||
|
||
* X_NUCLEO_53L0A1_Gesture_Swipe1: This example code is to show how to combine the | ||
proximity value of the onboard VL53L0X sensor together with the gesture library | ||
in order to detect a simple swipe gesture without considering the direction. | ||
|
||
* X_NUCLEO_53L0A1_Gesture_Tap1: This example code is to show how to combine the | ||
proximity value of the onboard VL53L0X sensor together with the gesture | ||
library in order to detect a simple tap gesture. | ||
|
||
##Dependencies | ||
|
||
This package requires the following Arduino libraries: | ||
* VL53L0X: https://github.com/stm32duino/VL53L0X | ||
* Proximity_Gesture: https://github.com/stm32duino/Proximity_Gesture | ||
|
||
## Note | ||
|
||
The maximum detection distance is influenced by the color of the target and | ||
the indoor or outdoor situation due to absence or presence of external | ||
infrared. | ||
The detection range can be comprise between ~40cm and ~120cm. (see chapter 5 of | ||
the VL53L0X datasheet). | ||
If you need an higher accuracy (up to +200cm), you should implement your own | ||
function. | ||
|
||
## Documentation | ||
|
||
You can find the source files at | ||
https://github.com/stm32duino/X-NUCLEO-53L0A1 | ||
|
||
The VL53L0X datasheet is available at | ||
http://www.st.com/content/st_com/en/products/imaging-and-photonics-solutions/proximity-sensors/vl53l0x.html |
287 changes: 287 additions & 0 deletions
287
examples/X_NUCLEO_53L0A1_Gesture_DirSwipe/X_NUCLEO_53L0A1_Gesture_DirSwipe.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,287 @@ | ||
/** | ||
****************************************************************************** | ||
* @file X_NUCLEO_53L0A1_Gesture_DirSwipe.ino | ||
* @author AST | ||
* @version V1.0.0 | ||
* @date 21 April 2017 | ||
* @brief Arduino test application for the STMicrolectronics X-NUCLEO-53L0A1 | ||
* proximity sensor expansion board based on FlightSense and gesture library. | ||
* This application makes use of C++ classes obtained from the C | ||
* components' drivers. | ||
****************************************************************************** | ||
* @attention | ||
* | ||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> | ||
* | ||
* 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. | ||
* | ||
****************************************************************************** | ||
*/ | ||
|
||
|
||
/* Includes ------------------------------------------------------------------*/ | ||
#include <Arduino.h> | ||
#include <Wire.h> | ||
#include <vl53l0x_x_nucleo_53l0a1_class.h> | ||
#include <stmpe1600_class.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <assert.h> | ||
#include <tof_gestures.h> | ||
#include <tof_gestures_DIRSWIPE_1.h> | ||
|
||
#define DEV_I2C Wire | ||
#define SerialPort Serial | ||
|
||
// Components. | ||
STMPE1600DigiOut *xshutdown_top; | ||
STMPE1600DigiOut *xshutdown_left; | ||
STMPE1600DigiOut *xshutdown_right; | ||
VL53L0X_X_NUCLEO_53L0A1 *sensor_vl53l0x_top; | ||
VL53L0X_X_NUCLEO_53L0A1 *sensor_vl53l0x_left; | ||
VL53L0X_X_NUCLEO_53L0A1 *sensor_vl53l0x_right; | ||
|
||
// Gesture structure. | ||
Gesture_DIRSWIPE_1_Data_t gestureDirSwipeData; | ||
|
||
// Range values | ||
uint32_t distance_left, distance_right; | ||
|
||
/** | ||
* Setup all sensors for single shot mode | ||
*/ | ||
void SetupSingleShot(void){ | ||
int status; | ||
uint8_t VhvSettings; | ||
uint8_t PhaseCal; | ||
uint32_t refSpadCount; | ||
uint8_t isApertureSpads; | ||
|
||
status = sensor_vl53l0x_left->StaticInit(); | ||
if( status ){ | ||
SerialPort.println("StaticInit left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_left->PerformRefCalibration(&VhvSettings, &PhaseCal); | ||
if( status ){ | ||
SerialPort.println("PerformRefCalibration left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_left->PerformRefSpadManagement(&refSpadCount, &isApertureSpads); | ||
if( status ){ | ||
SerialPort.println("PerformRefSpadManagement left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_left->SetDeviceMode(VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode | ||
if( status ){ | ||
SerialPort.println("SetDeviceMode left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_left->SetMeasurementTimingBudgetMicroSeconds(20*1000); | ||
if( status ){ | ||
SerialPort.println("SetMeasurementTimingBudgetMicroSeconds left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->StaticInit(); | ||
if( status ){ | ||
SerialPort.println("StaticInit right sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->PerformRefCalibration(&VhvSettings, &PhaseCal); | ||
if( status ){ | ||
SerialPort.println("PerformRefCalibration right sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->PerformRefSpadManagement(&refSpadCount, &isApertureSpads); | ||
if( status ){ | ||
SerialPort.println("PerformRefSpadManagement right sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->SetDeviceMode(VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode | ||
if( status ){ | ||
SerialPort.println("SetDeviceMode right sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->SetMeasurementTimingBudgetMicroSeconds(20*1000); | ||
if( status ){ | ||
SerialPort.println("SetMeasurementTimingBudgetMicroSeconds right sensor failed"); | ||
} | ||
} | ||
|
||
/* Setup ---------------------------------------------------------------------*/ | ||
|
||
void setup() { | ||
int status; | ||
// Led. | ||
pinMode(13, OUTPUT); | ||
|
||
// Initialize serial for output. | ||
SerialPort.begin(115200); | ||
|
||
// Initialize I2C bus. | ||
DEV_I2C.begin(); | ||
DEV_I2C.setClock(400000); | ||
|
||
// Create VL53L0X top component. | ||
xshutdown_top = new STMPE1600DigiOut(&DEV_I2C, GPIO_15, (0x42 * 2)); | ||
sensor_vl53l0x_top = new VL53L0X_X_NUCLEO_53L0A1(&DEV_I2C, xshutdown_top, A2); | ||
|
||
// Switch off VL53L0X top component. | ||
sensor_vl53l0x_top->VL53L0X_Off(); | ||
|
||
// Create (if present) VL53L0X left component. | ||
xshutdown_left = new STMPE1600DigiOut(&DEV_I2C, GPIO_14, (0x43 * 2)); | ||
sensor_vl53l0x_left = new VL53L0X_X_NUCLEO_53L0A1(&DEV_I2C, xshutdown_left, D8); | ||
|
||
// Switch off (if present) VL53L0X left component. | ||
sensor_vl53l0x_left->VL53L0X_Off(); | ||
|
||
// Create (if present) VL53L0X right component. | ||
xshutdown_right = new STMPE1600DigiOut(&DEV_I2C, GPIO_15, (0x43 * 2)); | ||
sensor_vl53l0x_right = new VL53L0X_X_NUCLEO_53L0A1(&DEV_I2C, xshutdown_right, D2); | ||
|
||
// Switch off (if present) VL53L0X right component. | ||
sensor_vl53l0x_right->VL53L0X_Off(); | ||
|
||
// Initialize VL53L0X left component. | ||
status = sensor_vl53l0x_left->InitSensor(0x12); | ||
if(status) | ||
{ | ||
SerialPort.println("Init sensor_vl53l0x_left failed..."); | ||
} | ||
|
||
// Initialize VL53L0X right component. | ||
status = sensor_vl53l0x_right->InitSensor(0x14); | ||
if(status) | ||
{ | ||
SerialPort.println("Init sensor_vl53l0x_right failed..."); | ||
} | ||
|
||
// Initialize VL6180X gesture library. | ||
tof_gestures_initDIRSWIPE_1(400, 0, 1000, &gestureDirSwipeData); | ||
|
||
SetupSingleShot(); | ||
} | ||
|
||
|
||
/* Loop ----------------------------------------------------------------------*/ | ||
|
||
void loop() { | ||
int gesture_code; | ||
int status; | ||
|
||
sensor_vl53l0x_left->StartMeasurement(); | ||
sensor_vl53l0x_right->StartMeasurement(); | ||
|
||
int left_done = 0; | ||
int right_done = 0; | ||
uint8_t NewDataReady=0; | ||
VL53L0X_RangingMeasurementData_t pRangingMeasurementData; | ||
|
||
do | ||
{ | ||
if(left_done == 0) | ||
{ | ||
NewDataReady = 0; | ||
int status = sensor_vl53l0x_left->GetMeasurementDataReady(&NewDataReady); | ||
|
||
if( status ){ | ||
SerialPort.println("GetMeasurementDataReady left sensor failed"); | ||
} | ||
|
||
if(NewDataReady) | ||
{ | ||
status = sensor_vl53l0x_left->ClearInterruptMask(0); | ||
if( status ){ | ||
SerialPort.println("ClearInterruptMask left sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_left->GetRangingMeasurementData(&pRangingMeasurementData); | ||
if( status ){ | ||
SerialPort.println("GetRangingMeasurementData left sensor failed"); | ||
} | ||
|
||
if (pRangingMeasurementData.RangeStatus == 0) { | ||
// we have a valid range. | ||
distance_left = pRangingMeasurementData.RangeMilliMeter; | ||
}else { | ||
distance_left = 1200; | ||
} | ||
|
||
left_done = 1; | ||
} | ||
} | ||
|
||
if(right_done == 0) | ||
{ | ||
NewDataReady = 0; | ||
int status = sensor_vl53l0x_right->GetMeasurementDataReady(&NewDataReady); | ||
|
||
if( status ){ | ||
SerialPort.println("GetMeasurementDataReady right sensor failed"); | ||
} | ||
|
||
if(NewDataReady) | ||
{ | ||
status = sensor_vl53l0x_right->ClearInterruptMask(0); | ||
if( status ){ | ||
SerialPort.println("ClearInterruptMask right sensor failed"); | ||
} | ||
|
||
status = sensor_vl53l0x_right->GetRangingMeasurementData(&pRangingMeasurementData); | ||
if( status ){ | ||
SerialPort.println("GetRangingMeasurementData right sensor failed"); | ||
} | ||
|
||
if (pRangingMeasurementData.RangeStatus == 0) { | ||
// we have a valid range. | ||
distance_right = pRangingMeasurementData.RangeMilliMeter; | ||
}else { | ||
distance_right = 1200; | ||
} | ||
|
||
right_done = 1; | ||
} | ||
} | ||
}while(left_done == 0 || right_done == 0); | ||
|
||
// Launch gesture detection algorithm. | ||
gesture_code = tof_gestures_detectDIRSWIPE_1(distance_left, distance_right, &gestureDirSwipeData); | ||
|
||
// Check the result of the gesture detection algorithm. | ||
switch(gesture_code) | ||
{ | ||
case GESTURES_SWIPE_LEFT_RIGHT: | ||
SerialPort.println("From LEFT to RIGHT --->"); | ||
break; | ||
case GESTURES_SWIPE_RIGHT_LEFT: | ||
SerialPort.println("From RIGHT to LEFT <---"); | ||
break; | ||
default: | ||
// Do nothing | ||
break; | ||
} | ||
} | ||
|
Oops, something went wrong.