Git Product home page Git Product logo

vl6180x-arduino's Introduction

VL6180X library for Arduino

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 setBus(TwoWire * bus)
    Configures this object to use the specified I²C bus. bus should be a pointer to a TwoWire object; the default bus is Wire, which is typically the first or only I²C bus on an Arduino. If your Arduino has more than one I²C bus and you have the VL6180X connected to the second bus, which is typically called Wire1, you can call sensor.setBus(&Wire1);.

  • TwoWire * getBus()
    Returns a pointer to the I²C bus this object is using.

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

  • uint8_t getAddress()
    Returns the current I²C address.

  • void init()
    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.

  • void setScaling(uint8_t new_scaling)
    Sets range scaling factor. The sensor uses 1x scaling by default, giving range measurements in units of mm. Increasing the scaling to 2x or 3x makes it give raw values in units of 2 mm or 3 mm instead. In other words, a bigger scaling factor increases the sensor's potential maximum range but reduces its resolution.

  • uint8_t getScaling(void)
    Returns the current range scaling factor.

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

  • uint16_t readRangeSingleMillimeters(void)
    Performs a single-shot ranging measurement and returns the reading in millimeters, taking the range scaling setting into account.

  • 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 "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 raw range reading when continuous mode is active.

  • uint16_t readRangeContinuousMillimeters(void)
    Returns a range reading in millimeters, taking the range scaling setting into account, when continuous mode is active.

  • 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().

  • uint8_t readRangeStatus()
    Get ranging success/error status code (Use it before using a measurement).

Version history

  • 1.4.0 (2024-01-26): Fixed issue with scaling factor being applied to negative offsets improperly. Improved timeout behavior and added readRangeStatus() (thanks celestinmetral and ysard).
  • 1.3.1 (2021-06-29): Fixed compilation errors with Arduino mbed core.
  • 1.3.0 (2021-01-12): Added support for alternative I²C buses (thanks mjs513) and getAddress(). Fixed some minor code and documentation issues.
  • 1.2.0 (2016-05-18): Added functions for reading range in millimeters, taking range scaling factor into account. Changed example sketches to use these functions.
  • 1.1.0 (2016-05-12): Added functions to set range scaling factor and example sketch to demonstrate scaling.
  • 1.0.1 (2016-03-14): Added missing Serial.begin() to examples and changed configureDefault() to reset some additional registers to power-on defaults.
  • 1.0.0 (2015-09-24): Original release.

vl6180x-arduino's People

Contributors

davidegrayson avatar kevin-pololu avatar ryantm avatar ysard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vl6180x-arduino's Issues

"Timeout" not triggered when module disconnected

Hello,

I've made some tests with your module and RangeSensorDriver example of your library, specifically around the "timeout" feature. I've found out that when I disconnect your module from the I²C bus, the "timeout" does not trigger. It triggers only when computation takes too much times, but I think it could be great if it triggered when module is disconnected.

After digging inside your library, I think I've found the culprit, in VL6180X.cpp, line 346:
while ((readReg(RESULT__INTERRUPT_STATUS_GPIO) & 0x04) == 0)

  • while computation is ongoing, the register is set to 0x00 (program looping inside while)
  • when computation is finished, the register is set to 0x04 (source (page 5, bullet 10)) (program exiting while loop)
  • but when module is disconnected, the register is read as 0xFF (255)!

As you can see in the code line above, the condition evaluates as false when the module is disconnected, so the program does not even enter the while loop, range is read and timeout does not triggers.

My suggestion is to edit the line as :
while ((readReg(RESULT__INTERRUPT_STATUS_GPIO) != 0x04)

Do you find this a good idea or do I forgot a use case ? If you think we could edit the library, could I make a pull request (I've never made one !) ?

Thanks, Célestin

Increase I2C clock frequency ?

Hi, Great and in-depth Library for this sensor. I loved it!
However, I am so busted as I am setting up a series of them and reading all of them currently takes a quite long time. I measured the I2C protocol used for the library has defaulted at a clock frequency of 100000.
I have tried many attempts to improve the sample rate, such as changing the wire library clock frequency in my code, as well as in the library code (VL6180X.cpp) or even in macro library code but none worked. I also tried the method mentioned here, but it does not help as well.
Is there any way to improve the time takes to read multiple VL6180Xs? I'd appreciate any help

How to calculate time with Time of Flight sensor

Thank you for your tutorial, they were really helpful to get me started.
However i have quite a simple question but i do not know how to get my mind around it.

And according to the datasheet, Effective max convergence time depends on the actual convergence time plus readout averaging sample period setting. Please i want to know how to calculate the convergence time.

This is simply because i want to be able to calculate speed. Since the sensor reads distance, if i know the time, then i can calculate speed.
Thank you

VL6180x...

Hello.....
I used the library given for VL6180x breakout board of Pololu, and it works fine with my Aruino Uno.
The only issue is, the sampling rate of 10Hz is not enough for my application.
In all the reading appear on the serial monitor screen after half second approx.

I require speed of at least 100Hz or more, and readings must appear after 10ms.

I am not exactly sure how to achieve this, and which parameters must be changed or controlled to get this much speed smoothly,
Could I get some help please?

Also, what is the meaning of 'convergence time'?

Serial.Begin() Missing

FYI: Both example programs are missing the Serial.Begin statement needed to output to the serial monitor:

  // Initialize serial communications:
  Serial.begin(9600);

Can't getting 0 value from Range sensor

Hello my sensor is working just fine between 255-10mm values but when i put something closer than 10mm sensor doesn't show it and values are not stable it can say for same object in same spot 22mm 23mm or 20mm. What sould I do ? Thanks

Vl 6180

Hi, I wanted to see if you could help me with the VL6180x sensor, I tried in many ways but I always get stuck in the 0x18 register, it never gets 0x4. Thank you
y.zip

.....

Please delete this issue!

Update datasheet references in comments for latest datasheet

The comments in the InterleavedContinuous example (and possibly other places) refer to section numbers that were apparently correct for Rev 6 of the VL6180X datasheet but have changed in the latest (Rev 7). We need to fix these, possibly by removing the section numbers and just referring to the sections by name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.