Skip to content

WPISmartmouse/vl6180x-arduino

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VL6180X library for Arduino

Version: 1.0.1
Release date: 2016 March 14
www.pololu.com

Summary

This is a library for the Arduino IDE that helps interface with ST's VL6180X time-of-flight distance and ambient light sensor. The library makes it simple to configure the sensor and read range and ambient light level data from it via I²C.

Supported platforms

This library is designed to work with the Arduino IDE versions 1.6.x or later; we have not tested it with earlier versions. This library should support any Arduino-compatible board, including the Pololu A-Star 32U4 controllers.

Getting started

Hardware

A VL6180X carrier can be purchased from Pololu's website. Before continuing, careful reading of the product page as well as the VL6180X datasheet and application notes is recommended.

Make the following connections between the Arduino and the VL6180X board:

5V Arduino boards

(including Arduino Uno, Leonardo, Mega; Pololu A-Star 32U4)

Arduino   VL6180X board
-------   -------------
     5V - VIN
    GND - GND
    SDA - SDA
    SCL - SCL

3.3V Arduino boards

(including Arduino Due)

Arduino   VL6180X board
-------   -------------
    3V3 - VIN
    GND - GND
    SDA - SDA
    SCL - SCL

Software

If you are using version 1.6.2 or later of the Arduino software (IDE), you can use the Library Manager to install this library:

  1. In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
  2. Search for "VL6180X".
  3. Click the VL6180X entry in the list.
  4. Click "Install".

If this does not work, you can manually install the library:

  1. Download the latest release archive from GitHub and decompress it.
  2. Rename the folder "vl6180x-arduino-master" to "VL6180X".
  3. Move the "VL6180X" folder into the "libraries" directory inside your Arduino sketchbook directory. You can view your sketchbook location by opening the "File" menu and selecting "Preferences" in the Arduino IDE. If there is not already a "libraries" folder in that location, you should make the folder yourself.
  4. After installing the library, restart the Arduino IDE.

Examples

Several example sketches are available that show how to use the library. You can access them from the Arduino IDE by opening the "File" menu, selecting "Examples", and then selecting "VL6180X". If you cannot find these examples, the library was probably installed incorrectly and you should retry the installation instructions above.

Library reference

  • uint8_t last_status
    The status of the last I²C write transmission. See the Wire.endTransmission() documentation for return values.

  • VL6180X(void)
    Constructor.

  • void setAddress(uint8_t new_addr)
    Changes the I²C slave device address of the VL6180X to the given value (7-bit).

  • void init(void)
    Loads required settings onto the VL6180X to initialize the sensor.

  • void configureDefault(void)
    Configures some settings for the sensor's default behavior. See the comments in VL6180X.cpp for a full explanation of the settings.

  • void writeReg(uint16_t reg, uint8_t value)
    Writes an 8-bit sensor register with the given value.

    Register address constants are defined by the regAddr enumeration type in VL6180X.h.
    Example use: sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);

  • void writeReg16Bit(uint16_t reg, uint16_t value)
    Writes a 16-bit sensor register with the given value.

  • void writeReg32Bit(uint16_t reg, uint32_t value)
    Writes a 32-bit sensor register with the given value.

  • uint8_t readReg(uint16_t reg)
    Reads an 8-bit sensor register and returns the value read.

  • uint16_t readReg16Bit(uint16_t reg)
    Reads a 16-bit sensor register and returns the value read.

  • uint32_t readReg32Bit(uint16_t reg)
    Reads a 32-bit sensor register and returns the value read.

  • uint8_t readRangeSingle(void)
    Performs a single-shot ranging measurement and returns the reading (distance in millimeters).

  • uint16_t readAmbientSingle(void)
    Performs a single-shot ambient light measurement and returns the reading.

  • void startRangeContinuous(uint16_t period)
    Starts continuous ranging measurements with the given period in milliseconds (10 ms resolution; defaults to 100 ms if not specified).

    In all continuous modes, the period must be greater than the time it takes to perform the measurement(s). See section 2.4.4 ("Continuous mode limits") in the datasheet for details.

  • void startAmbientContinuous(uint16_t period)
    Starts continuous ambient light measurements with the given period in milliseconds (10 ms resolution; defaults to 500 ms if not specified).

  • void startInterleavedContinuous(uint16_t period)
    Starts continuous interleaved measurements with the given period in milliseconds (10 ms resolution; defaults to 500 ms if not specified).

    In this mode, each ambient light measurement is immediately followed by a range measurement. You should use this mode instead of enabling continuous mode for ranging and ambient light independently.

  • void stopContinuous(void)
    Stops continuous mode.

  • uint8_t readRangeContinuous(void)
    Returns a range reading when continuous mode is active (distance in millimeters).

  • uint16_t readAmbientContinuous(void)
    Returns an ambient light reading when continuous mode is active.

  • void setTimeout(uint16_t timeout)
    Sets a timeout period in milliseconds after which the read functions will abort if the sensor is not ready. A value of 0 disables the timeout.

  • uint16_t getTimeout(void)
    Returns the current timeout period setting.

  • bool timeoutOccurred(void)
    Indicates whether a read timeout has occurred since the last call to timeoutOccurred().

Version history

  • 1.0.1 (2016 Mar 14): Added missing Serial.begin() to examples and changed configureDefault() to reset some additional registers to power-on defaults.
  • 1.0.0 (2015 Sep 24): Original release.

About

Pololu Arduino library for VL6180X distance and ambient light sensor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%