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.
Dependencies: MCP23017 WattBob_TextLCD
VL6180.h
00001 /****************************************************************************** 00002 * SFE_VL6180.h 00003 * Library for VL6180 time of flight range finder. 00004 * Casey Kuhns @ SparkFun Electronics 00005 * 10/29/2014 00006 * https://github.com/sparkfun/ 00007 * 00008 * The VL6180 by ST micro is a time of flight range finder that 00009 * uses pulsed IR light to determine distances from object at close 00010 * range. The average range of a sensor is between 0-200mm 00011 * 00012 * In this file are the function prototypes in the VL6180 class 00013 * 00014 * Resources: 00015 * This library uses the Arduino Wire.h to complete I2C transactions. 00016 * 00017 * Development environment specifics: 00018 * IDE: Arduino 1.0.5 00019 * Hardware Platform: Arduino Pro 3.3V/8MHz 00020 * VL6180 Breakout Version: 1.0 00021 * 00022 * Some settings and initial values come from code written by Kris Winer 00023 * VL6180_t3 Basic Example Code 00024 * by: Kris Winer 00025 * date: September 1, 2014 00026 * license: Beerware - Use this code however you'd like. If you 00027 * find it useful you can buy me a beer some time. 00028 * 00029 * This code is beerware. If you see me (or any other SparkFun employee) at the 00030 * local pub, and you've found our code helpful, please buy us a round! 00031 * 00032 * Distributed as-is; no warranty is given. 00033 ******************************************************************************/ 00034 00035 #ifndef SFE_VL6180_h 00036 #define SFE_VL6180_h 00037 00038 #include "mbed.h" 00039 #include "stdint.h" 00040 00041 #define VL6180_DEF_ADDR 0x52 00042 00043 #define VL6180_FAILURE_RESET -1 00044 00045 #define VL6180_IDENTIFICATION_MODEL_ID 0x0000 00046 #define VL6180_IDENTIFICATION_MODEL_REV_MAJOR 0x0001 00047 #define VL6180_IDENTIFICATION_MODEL_REV_MINOR 0x0002 00048 #define VL6180_IDENTIFICATION_MODULE_REV_MAJOR 0x0003 00049 #define VL6180_IDENTIFICATION_MODULE_REV_MINOR 0x0004 00050 #define VL6180_IDENTIFICATION_DATE 0x0006 //16bit value 00051 #define VL6180_IDENTIFICATION_TIME 0x0008 //16bit value 00052 00053 #define VL6180_SYSTEM_MODE_GPIO0 0x0010 00054 #define VL6180_SYSTEM_MODE_GPIO1 0x0011 00055 #define VL6180_SYSTEM_HISTORY_CTRL 0x0012 00056 #define VL6180_SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014 00057 #define VL6180_SYSTEM_INTERRUPT_CLEAR 0x0015 00058 #define VL6180_SYSTEM_FRESH_OUT_OF_RESET 0x0016 00059 #define VL6180_SYSTEM_GROUPED_PARAMETER_HOLD 0x0017 00060 00061 #define VL6180_SYSRANGE_START 0x0018 00062 #define VL6180_SYSRANGE_THRESH_HIGH 0x0019 00063 #define VL6180_SYSRANGE_THRESH_LOW 0x001A 00064 #define VL6180_SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B 00065 #define VL6180_SYSRANGE_MAX_CONVERGENCE_TIME 0x001C 00066 #define VL6180_SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E 00067 #define VL6180_SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021 00068 #define VL6180_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022 00069 #define VL6180_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024 00070 #define VL6180_SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025 00071 #define VL6180_SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026 00072 #define VL6180_SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C 00073 #define VL6180_SYSRANGE_RANGE_CHECK_ENABLES 0x002D 00074 #define VL6180_SYSRANGE_VHV_RECALIBRATE 0x002E 00075 #define VL6180_SYSRANGE_VHV_REPEAT_RATE 0x0031 00076 00077 #define VL6180_SYSALS_START 0x0038 00078 #define VL6180_SYSALS_THRESH_HIGH 0x003A 00079 #define VL6180_SYSALS_THRESH_LOW 0x003C 00080 #define VL6180_SYSALS_INTERMEASUREMENT_PERIOD 0x003E 00081 #define VL6180_SYSALS_ANALOGUE_GAIN 0x003F 00082 #define VL6180_SYSALS_INTEGRATION_PERIOD 0x0040 00083 00084 #define VL6180_RESULT_RANGE_STATUS 0x004D 00085 #define VL6180_RESULT_ALS_STATUS 0x004E 00086 #define VL6180_RESULT_INTERRUPT_STATUS_GPIO 0x004F 00087 #define VL6180_RESULT_ALS_VAL 0x0050 00088 #define VL6180_RESULT_HISTORY_BUFFER 0x0052 00089 #define VL6180_RESULT_RANGE_VAL 0x0062 00090 #define VL6180_RESULT_RANGE_RAW 0x0064 00091 #define VL6180_RESULT_RANGE_RETURN_RATE 0x0066 00092 #define VL6180_RESULT_RANGE_REFERENCE_RATE 0x0068 00093 #define VL6180_RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C 00094 #define VL6180_RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070 00095 #define VL6180_RESULT_RANGE_RETURN_AMB_COUNT 0x0074 00096 #define VL6180_RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078 00097 #define VL6180_RESULT_RANGE_RETURN_CONV_TIME 0x007C 00098 #define VL6180_RESULT_RANGE_REFERENCE_CONV_TIME 0x0080 00099 00100 #define VL6180_READOUT_AVERAGING_SAMPLE_PERIOD 0x010A 00101 #define VL6180_FIRMWARE_BOOTUP 0x0119 00102 #define VL6180_FIRMWARE_RESULT_SCALER 0x0120 00103 #define VL6180_I2C_SLAVE_DEVICE_ADDRESS 0x0212 00104 #define VL6180_INTERLEAVED_MODE_ENABLE 0x02A3 00105 00106 00107 enum VL6180_als_gain { //Data sheet shows gain values as binary list 00108 00109 GAIN_20 = 0, // Actual ALS Gain of 20 00110 GAIN_10, // Actual ALS Gain of 10.32 00111 GAIN_5, // Actual ALS Gain of 5.21 00112 GAIN_2_5, // Actual ALS Gain of 2.60 00113 GAIN_1_67, // Actual ALS Gain of 1.72 00114 GAIN_1_25, // Actual ALS Gain of 1.28 00115 GAIN_1 , // Actual ALS Gain of 1.01 00116 GAIN_40, // Actual ALS Gain of 40 00117 00118 }; 00119 00120 struct VL6180Identification { 00121 uint8_t idModel; 00122 uint8_t idModelRevMajor; 00123 uint8_t idModelRevMinor; 00124 uint8_t idModuleRevMajor; 00125 uint8_t idModuleRevMinor; 00126 uint16_t idDate; 00127 uint16_t idTime; 00128 }; 00129 00130 00131 class VL6180 00132 { 00133 public: 00134 /** Create VL6180 instance 00135 * 00136 * @param sda sda pin for I2C 00137 * @param scl scl pin for I2C 00138 */ 00139 VL6180( PinName sda, PinName scl ); 00140 VL6180( PinName sda, PinName scl , int i2c_address); 00141 00142 /** Destructor 00143 */ 00144 ~VL6180(); 00145 00146 /** Read red, green, blue and clear values into array 00147 * 00148 * @param readings Array of four integers to store the read data 00149 */ 00150 //Initalize library with default address 00151 // VL6180(uint8_t address); 00152 //Send manditory settings as stated in ST datasheet. 00153 // http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf (Section 1.3) 00154 int8_t VL6180_Init(void); 00155 // Use default settings from ST data sheet section 9. 00156 // http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf 00157 void VL6180_DefautSettings(void); 00158 00159 // Get Range distance in (mm) 00160 uint8_t getDistance(); 00161 // Get ALS level in Lux 00162 float getAmbientLight(VL6180_als_gain VL6180_ALS_GAIN); 00163 00164 //Load structure provided by the user with identification info 00165 //Structure example: 00166 // struct VL6180Identification 00167 // { 00168 // uint8_t idModel; 00169 // uint8_t idModelRevMajor; 00170 // uint8_t idModelRevMinor; 00171 // uint8_t idModuleRevMajor; 00172 // uint8_t idModuleRevMinor; 00173 // uint16_t idDate; 00174 // uint16_t idTime; 00175 // }; 00176 void getIdentification(struct VL6180Identification *temp); 00177 00178 //Change the default address of the device to allow multiple 00179 //sensors on the bus. Can use up to 127 sensors. New address 00180 //is saved in non-volatile device memory. 00181 uint8_t changeAddress(uint8_t old_address, uint8_t new_address); 00182 00183 int writeSingleRegister( uint16_t reg_address, uint8_t data ); 00184 00185 00186 private: 00187 //Store address given when the class is initialized. 00188 //This value can be changed by the changeAddress() function 00189 I2C i2c; 00190 int VL6180_i2cAddress; 00191 uint8_t VL6180_error_no; 00192 00193 uint8_t VL6180_getRegister(uint16_t registerAddr); 00194 uint16_t VL6180_getRegister16bit(uint16_t registerAddr); 00195 00196 void VL6180_setRegister(uint16_t registerAddr, uint8_t value); 00197 void VL6180_setRegister16bit(uint16_t registerAddr, uint16_t value); 00198 00199 00200 }; 00201 00202 #endif
Generated on Fri Jul 15 2022 13:08:56 by
1.7.2