Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: VL6180X VL6180X_Explorer VL6180X_Explorer VL6180X ... more
VL6180x Class Reference
VL6180x tof/als sensor example. More...
#include <VL6180x.h>
| Public Member Functions | |
| VL6180x (PinName sda, PinName scl, uint8_t addr) | |
| VL6180x constructor. | |
| ~VL6180x () | |
| VL6180x destructor. | |
| int | VL6180xInit (void) | 
| Send mandatory settings as stated in ST datasheet. | |
| void | VL6180xDefautSettings (void) | 
| Use default settings from ST data sheet section 9. | |
| uint8_t | getDistance () | 
| Get Range distance in (mm) | |
| float | getDistance_m () | 
| Get Range distance in meters. | |
| float | getAmbientLight (vl6180x_als_gain VL6180X_ALS_GAIN) | 
| Get ALS level in Lux. | |
| void | getIdentification (struct VL6180xIdentification *temp) | 
| Load structure provided by the user with identification info Structure example: struct VL6180xIdentification. | |
| uint8_t | changeAddress (uint8_t old_address, uint8_t new_address) | 
| Change the default address of the device to allow multiple sensors on the bus. | |
Detailed Description
VL6180x tof/als sensor example.
#include "mbed.h" #include <VL6180x.h> const float GAIN_1 = 1.01; // Actual ALS Gain of 1.01 const float GAIN_1_25 = 1.28; // Actual ALS Gain of 1.28 const float GAIN_1_67 = 1.72; // Actual ALS Gain of 1.72 const float GAIN_2_5 = 2.6; // Actual ALS Gain of 2.60 const float GAIN_5 = 5.21; // Actual ALS Gain of 5.21 const float GAIN_10 = 10.32; // Actual ALS Gain of 10.32 const float GAIN_20 = 20; // Actual ALS Gain of 20 const float GAIN_40 = 40; // Actual ALS Gain of 40 #define VL6180X_ADDRESS 0x29 VL6180xIdentification identification; // mbed uses 8bit addresses shift address by 1 bit left VL6180x sensor(D14, D15, VL6180X_ADDRESS<<1); void printIdentification(struct VL6180xIdentification *temp){ printf("Model ID = "); printf("%d\n",temp->idModel); printf("Model Rev = "); printf("%d",temp->idModelRevMajor); printf("."); printf("%d\n",temp->idModelRevMinor); printf("Module Rev = "); printf("%d",temp->idModuleRevMajor); printf("."); printf("%d\n",temp->idModuleRevMinor); printf("Manufacture Date = "); printf("%d",((temp->idDate >> 3) & 0x001F)); printf("/"); printf("%d",((temp->idDate >> 8) & 0x000F)); printf("/1"); printf("%d\n",((temp->idDate >> 12) & 0x000F)); printf(" Phase: "); printf("%d\n",(temp->idDate & 0x0007)); printf("Manufacture Time (s)= "); printf("%d\n",(temp->idTime * 2)); printf("\n\n"); } int main() { wait_ms(100); // delay .1s sensor.getIdentification(&identification); // Retrieve manufacture info from device memory printIdentification(&identification); // Helper function to print all the Module information if(sensor.VL6180xInit() != 0){ printf("FAILED TO INITALIZE\n"); //Initialize device and check for errors }; sensor.VL6180xDefautSettings(); //Load default settings to get started. wait_ms(1000); // delay 1s while(1) { //Get Ambient Light level and report in LUX printf("Ambient Light Level (Lux) = "); //Input GAIN for light levels, // GAIN_20 // Actual ALS Gain of 20 // GAIN_10 // Actual ALS Gain of 10.32 // GAIN_5 // Actual ALS Gain of 5.21 // GAIN_2_5 // Actual ALS Gain of 2.60 // GAIN_1_67 // Actual ALS Gain of 1.72 // GAIN_1_25 // Actual ALS Gain of 1.28 // GAIN_1 // Actual ALS Gain of 1.01 // GAIN_40 // Actual ALS Gain of 40 printf("%f\n",sensor.getAmbientLight(GAIN_1) ); //Get Distance and report in mm printf("Distance measured (mm) = "); printf("%d\n", sensor.getDistance() ); wait_ms(500); } }
Definition at line 232 of file VL6180x.h.
Constructor & Destructor Documentation
| VL6180x | ( | PinName | sda, | 
| PinName | scl, | ||
| uint8_t | addr | ||
| ) | 
VL6180x constructor.
- Parameters:
- 
  sda SDA pin sdl SCL pin addr (7 bit) address of the I2C peripheral 
Definition at line 33 of file VL6180x.cpp.
| ~VL6180x | ( | void | ) | 
VL6180x destructor.
Definition at line 76 of file VL6180x.cpp.
Member Function Documentation
| uint8_t changeAddress | ( | uint8_t | old_address, | 
| uint8_t | new_address | ||
| ) | 
Change the default address of the device to allow multiple sensors on the bus.
Can use up to 127 sensors. New address is saved in non-volatile device memory.
- Parameters:
- 
  old_address current address new_address desired new address 
- Returns:
- new address
Definition at line 121 of file VL6180x.cpp.
| float getAmbientLight | ( | vl6180x_als_gain | VL6180X_ALS_GAIN ) | 
Get ALS level in Lux.
- Parameters:
- 
  vl6180x_als_gain gain setting for sensor 
- Returns:
- light level in Lux
Definition at line 155 of file VL6180x.cpp.
| uint8_t getDistance | ( | ) | 
| float getDistance_m | ( | ) | 
Get Range distance in meters.
- Returns:
- TOF distance in meters
Definition at line 146 of file VL6180x.cpp.
| void getIdentification | ( | struct VL6180xIdentification * | temp ) | 
Load structure provided by the user with identification info Structure example: struct VL6180xIdentification.
void printIdentification(struct VL6180xIdentification *temp){ printf("Model ID = "); printf("%d\n",temp->idModel); printf("Model Rev = "); printf("%d",temp->idModelRevMajor); printf("."); printf("%d\n",temp->idModelRevMinor); printf("Module Rev = "); printf("%d",temp->idModuleRevMajor); printf("."); printf("%d\n",temp->idModuleRevMinor); printf("Manufacture Date = "); printf("%d",((temp->idDate >> 3) & 0x001F)); printf("/"); printf("%d",((temp->idDate >> 8) & 0x000F)); printf("/1"); printf("%d\n",((temp->idDate >> 12) & 0x000F)); printf(" Phase: "); printf("%d\n",(temp->idDate & 0x0007)); printf("Manufacture Time (s)= "); printf("%d\n",(temp->idTime * 2)); printf("\n\n"); *
Definition at line 108 of file VL6180x.cpp.
| void VL6180xDefautSettings | ( | void | ) | 
Use default settings from ST data sheet section 9.
Definition at line 79 of file VL6180x.cpp.
| int VL6180xInit | ( | void | ) | 
Send mandatory settings as stated in ST datasheet.
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf (Section 1.3)
- Returns:
- 0 if ok
- -1 on error
Definition at line 34 of file VL6180x.cpp.
Generated on Tue Jul 12 2022 21:16:02 by
 1.7.2
 1.7.2