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: BigBot_v1 PololuDistanceSensorTest Lidar Ares test ... more
VL53L0X.h
00001 /** 00002 * @file VL53L0X.h 00003 * @author Joel von Rotz (joel.vonrotz@maxonmotor.com) 00004 * @brief 00005 * @version 0.1 00006 * @date 2019-07-30 00007 * 00008 * @copyright Copyright (c) 2019, maxon motor ag - all rights reserved 00009 * 00010 */ 00011 #ifndef VL53L0X_H 00012 #define VL53L0X_H 00013 00014 #include "mbed.h" 00015 #include "vl53l0x_platform.h" 00016 #include "vl53l0x_def.h" 00017 00018 #define ADDRESS_DEFAULT (0x29) 00019 00020 /** 00021 * @brief Class for Proximity Sensor VL53L0X 00022 * 00023 * The VL53L0X is a laser based proximity sensor which can measure up to 2m. 00024 * This library is a wrapper for the API from STMicrocontrollers and the goal of this 00025 * library is the easier access to this sensor. 00026 * 00027 * Something really cool about these sensors is the ability to change the I2C-address. 00028 * So you can hook multiple, identical sensors on the same I2C-line. 00029 * 00030 * <h2>Examples</h2> 00031 * 00032 * <h3>One Sensor</h3> 00033 * Using one sensor is pretty simple, connect the I2C-pins to the sensor (Shutdown should be pulled high 00034 * using a pull-up resistor). 00035 * 00036 * @code 00037 * #include "mbed.h" 00038 * #include "VL53L0X.h" 00039 * 00040 * I2C i2c(p9, p10); 00041 * VL53L0X vl_sensor(&i2c); 00042 * DigitalOut vl_shutdown(p11); 00043 * Serial usb(USBTX, USBRX, 115200); 00044 * 00045 * int main(void) 00046 * { 00047 * usb.printf("Single VL53L0X\n\n\r"); 00048 * 00049 * vl_shutdown = 1; //turn VL53L0X on 00050 * vl_sensor.init(); 00051 * vl_sensor.setModeContinuous(); 00052 * vl_sensor.startContinuous(); 00053 * while(1) 00054 * { 00055 * usb.printf("%4imm\n\r", vl_sensor.getRangeMillimeters()); 00056 * } 00057 * } 00058 * @endcode 00059 * 00060 * <h3>Multiple Sensors</h3> 00061 * To use multiple sensors, at the start of the programm every sensor needs to be 00062 * turned off by setting their shutdown pin to low. Now one sensor is turned on, 00063 * and configured with the new address. After that's done, the next sensor can be 00064 * configured. 00065 * 00066 * @code 00067 * #include "mbed.h" 00068 * #include "VL53L0X.h" 00069 * 00070 * I2C i2c(p9, p10); 00071 * VL53L0X vl_sensors[6] = {(&i2c),(&i2c),(&i2c),(&i2c),(&i2c),(&i2c)}; 00072 * BusOut vl_shutdown(p11,p12,p13,p14,p15,p16); 00073 * Serial usb(USBTX, USBRX, 115200); 00074 * 00075 * int main(void) 00076 * { 00077 * usb.printf("Multiple VL53L0X\n\n\r"); 00078 * 00079 * uint8_t expander_shutdown_mask = 1; 00080 * for(uint8_t i = 0; i < 6 ; i++) 00081 * { 00082 * vl_shutdown = expander_shutdown_mask; 00083 * expander_shutdown_mask = (expander_shutdown_mask << 1) + 1; 00084 * vl_sensors[i].init(); 00085 * vl_sensors[i].setDeviceAddress(0x40 + i); 00086 * vl_sensors[i].setModeContinuous(); 00087 * vl_sensors[i].startContinuous(); 00088 * } 00089 * uint16_t results[6]; 00090 * while(1) 00091 * { 00092 * for(uint8_t i = 0; i < 6 ; i++) 00093 * { 00094 * results[i] = vl_sensors[i].getRangeMillimeters(); 00095 * } 00096 * usb.printf("1: %4imm 2: %4imm 3: %4imm) 4: %4imm 5: %4imm 6: %4imm)\n\r", results[0], results[1], results[2], results[3], results[4], results[5]); 00097 * } 00098 * } 00099 * @endcode 00100 * 00101 * <strong>NOTE</strong> - The library is gigantic, so it is recommended to use this library 00102 * on devices with enough storage. 00103 * 00104 */ 00105 class VL53L0X 00106 { 00107 public: 00108 VL53L0X(I2C* p_i2c_device); 00109 00110 bool setDeviceAddress(uint8_t address = ADDRESS_DEFAULT); 00111 00112 bool init(); 00113 00114 bool setModeContinuous(); 00115 bool startContinuous(); 00116 uint16_t getRangeMillimeters(); 00117 private: 00118 VL53L0X_Dev_t m_vl_dev; 00119 VL53L0X_RangingMeasurementData_t m_vl_results,m_old_results; 00120 00121 VL53L0X_Version_t m_vl_version; 00122 VL53L0X_DeviceInfo_t m_vl_deviceinfo; 00123 00124 }; 00125 00126 #endif /* */
Generated on Wed Jul 13 2022 23:40:16 by
