# LIDARLite_v2_Arduino_Library (BETA)
***NOTE:*** *This library is created specifically for LIDAR-Lite version 2 with the "Blue Label". See [http://pulsedlight3d.com](http://pulsedlight3d.com) for more information.*
The purpose of this library is two-fold:
1. Quick access all the basic functions of LIDAR-Lite via Arduino without worrying about specifics
2. By reading through this library, users of any platform will get an explanation of how to use the various functions of LIDAR-Lite and see an Arduino example along side.
Visit http://pulsedlight3d.com for documentation and support requests
This readme has the following sections:
- [Installation](#installation)
- [Wiring Diagrams](#wiring-diagrams)
- [Basic I2C Wiring](#basic-i2c-wiring)
- [PWM Wiring](#pwm-wiring)
- [Continuous Mode Wiring](#continuous-mode-wiring)
- [Multi-sensor PWR_EN Wiring](#multi-sensor-pwr_en-wiring)
- [Example Sketches](#example-sketches)
- Single Sensor
- [Change_I2C_Address](#change_i2c_address)
- [Correlation_Record_to_Array](#correlation_record_to_array)
- [Correlation_Record_to_Serial](#correlation_record_to_serial)
- [Distance_as_Fast_as_Possible](#distance_as_fast_as_possible)
- [Distance_Continuous](#distance_continous)
- [Distance_Single](#distance_single)
- [PWM](#pwm)
- [PWM_and_I2C](#pwm_and_i2c)
- [Second_Return_Detect](#second_return_detect)
- [Second_Return_Disable_Strongest](#second_return_disable_strongest)
- [Velocity_Single](#velocity_single)
- Multiple Sensors
- [Change_I2C_Addresses](#change_i2c_addresses)
- [Library Functions](#library-functions)
- [begin](#begin)
- [configure](#configure)
- [beginContinuous](#begin-continuous)
- [fast](#fast)
- [distance](#distance)
- [distanceContinuous](#distance-continuous)
- [scale](#scale)
- [velocity](#velocity)
- [signalStrength](#signal-strength)
- [correlationRecordToArray](#correlation-record-to-array)
- [correlationRecordToSerial](#correlation-record-to-serial-port)
- [changeAddress](#change-i2c-address-for-single-sensor)
- [changeAddressMultiPwrEn](#change-i2c-address-for-multiple-sensors)
- write
- read
# Installation
To install, download this repo put the "LIDARLite" (**which is inside the "LIDARLite_v2_Arduino_Library-master"**) folder in your Arduino "libraries" folder (**make sure you put "LIDARLite at the root of the librarires folder and not the entire repo**). If you need help, follow the instructions here: [http://arduino.cc/en/Guide/Libraries](http://arduino.cc/en/Guide/Libraries)
# Wiring Diagrams
## Basic I2C Wiring
The capacitor shown in these diagrams was useful with version one of the sensor and now is a virtual requirement because of the higher speeds of the sensor.
### Pinout
![Basic I2C Wiring: Pinout](Diagrams/PinoutI2CWiring.png)
### Arduino
![Basic I2C Wiring: Arduino](Diagrams/ArduinoI2CWiring.png)
## PWM Wiring
### Pinout
![PWM Wiring: Pinout](Diagrams/PinoutPWMWiring.png)
### Arduino
![PWM Wiring: Arduino](Diagrams/ArduinoPWMWiring.png)
## Continuous Mode Wiring
### Pinout
![Continuous Mode Wiring: Arduino](Diagrams/PinoutContinuousModeWiring.png)
### Arduino
![Continuous Mode Wiring: Arduino](Diagrams/ArduinoContinuousModeWiring.png)
## Multi-sensor PWR_EN Wiring
### Pinout
![Multi-sensor PWR_EN Wiring: Arduino](Diagrams/PinoutMultiSensorPWR.png)
### Arduino
![Multi-sensor PWR_EN Wiring: Arduino](Diagrams/ArduinoMultiSensorPWR.png)
# Example Sketches
## Single Sensor
### [Change_I2C_Address](LIDARLite/examples/Single%20Sensor/Change_I2C_Address/Change_I2C_Address.ino)
This example demonstrates how to chage the i2c address of a single sensor.
### [Correlation_Record_to_Array](LIDARLite/examples/Single%20Sensor/Correlation_Record_to_Array/Correlation_Record_to_Array.ino)
This example demostrates how to get the correlation record as an array and print it to the serial port
### [Correlation_Record_to_Serial](LIDARLite/examples/Single%20Sensor/Correlation_Record_to_Serial/Correlation_Record_to_Serial.ino)
This library demostrates how to print the correlation record to the serial port
### [Distance_as_Fast_as_Possible](LIDARLite/examples/Single%20Sensor/Distance_as_Fast_as_Possible/Distance_as_Fast_as_Possible.ino)
This example file demonstrates how to take distance measurements as fast as possible, when you first plug-in a LIDAR-Lite into an Arduino it runs 250 measurements per second (250Hz). Then if we setup the sensor by reducing the aquisiton record count by 1/3 and incresing the i2c communication speed from 100kHz to 400kHz we get about 500 measurements per second (500Hz). Now if we throttle the reference and preamp stabilization processes during the distance measurement process we can increase the number of measurements to about 750 per second (750Hz).
### [Distance_Continuous](LIDARLite/examples/Single%20Sensor/Distance_Continuous/Distance_Continuous.ino)
This example file will demonstrate how to tell the sensor to take a continous set of readings by writing the speed and number of measruments directly to the sensor, freeing the micro-controller to read when it is ready. We will con- figure the MODE pin to pull low when a new measrument is available.
### [Distance_Single](LIDARLite/examples/Single%20Sensor/Distance_Single/Distance_Single.ino)
This example file demonstrates how to take a single distance measurement with LIDAR-Lite v2 "Blue Label".
### [PWM](LIDARLite/examples/Single%20Sensor/PWM/PWM.ino)
This example demonstrates how to read measurements from LIDAR-Lite v2 "Blue Label" using PWM
### [PWM_and_I2C (Coming Soon)](LIDARLite/examples/Single%20Sensor/PWM_and_I2C/PWM_and_I2C.ino)
This example file will demonstrate how to use PWM and I2C at the same time, an exciting new feature of LIDAR-Lite
### [Second_Return_Detect (Coming Soon)](LIDARLite/examples/Single%20Sensor/Second_Return_Detect/Second_Return_Detect.ino)
This example will demostrate how to detect a second return, and if detected print the value
### [Second_Return_Disable_Strongest (Coming Soon)](LIDARLite/examples/Single%20Sensor/Second_Return_Disable_Strongest/Second_Return_Disable_Strongest.ino)
This example will demostrate how to disable showing strongest signal return and print the second return if one is availble. This kind of approach can help with window and chain link fence detection situation (amungst others).
### [Velocity_Single](LIDARLite/examples/Single%20Sensor/Velocity_Single/Velocity_Single.ino)
This example show how to read velocity with LIDAR-Lite "Blue Label" (V2)
## Multiple Sensors
### Change_I2C_Addresses
This example demonstrates how to chage the i2c address of multiple sensors.
# Library Functions
## Begin
Starts the sensor and I2C
### Process
1. Turn on error reporting, off by default
2. Start Wire (i.e. turn on I2C)
3. Enable 400kHz I2C, 100kHz by default
4. Set configuration for sensor
### Parameters
- **configuration**: set the configuration for the sensor
- default or 0 = equivelent to writing 0x00 to 0x00, i.e. full reset of sensor, if you write nothing for configuration or 0, the sensor will initiate normally
- 1 = high speed setting, set the aquisition count to 1/3 the default (works great for stronger singles) can be a little noisier
- **fasti2c**: if true i2c frequency is 400kHz, default is 100kHz
- **showErrorReporting**: if true reads with errors will print the value of 0x40, used primarily for debugging purposes by PulsedLight
- **LidarLiteI2cAddress (optional)**: Default: 0x62, the default LIDAR-Lite address. If you change the address, fill it in here.
### Function
```c++
void LIDARLite::begin(int configuration, bool fasti2c, bool showErrorReporting, char LidarLiteI2cAddress){
errorReporting = showErrorReporting;
Wire.begin(); // Start I2C
if(fasti2c){
#if ARDUINO >= 157
Wire.setClock(400000UL); // Set I2C frequency to 400kHz, for the Due
#else
TWBR = ((F_CPU / 400000UL) - 16) / 2; // Set I2C frequency to 400kHz
#endif