Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase I2C clock frequency ? #9

Open
EricWang12 opened this issue Mar 31, 2020 · 4 comments
Open

Increase I2C clock frequency ? #9

EricWang12 opened this issue Mar 31, 2020 · 4 comments

Comments

@EricWang12
Copy link

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

@dmsergeevich63
Copy link

How did you manage to connect multiple sensors?

@EricWang12
Copy link
Author

Just reset the module to different addresses in init() (it's in the library 😄 )

@dmsergeevich63
Copy link

Have you managed to increase or decrease the frequency at which the sensor operates? I've tried Wire.begin (21, 22, 100000); change the frequency, in Setup, but this only changes the frequency of the microcontroller and does not affect the sensor in any way.

@DavidEGrayson
Copy link
Member

To understand how long the VL6180X sensor takes to get a distance reading, I recommend reading the "Range timing" section of the VL6180X datasheet. This is independent of the I2C frequency, which is just the speed that the microcontroller uses to talk to the sensor.

This library sets SYSRANGE__MAX_CONVERGENCE_TIME to 49, so each reading takes up to 3.2 + 49 = 52.2 ms. You can use writeReg to decrease that number and get faster readings, but that means the sensor will receive less light, so that decreases its sensitivity (i.e. its ability to detect dark objects or objects that are far away decreases).

This library sets READOUT__AVERAGING_SAMPLE_PERIOD to 48, which is the value recommended by the datasheet. You can use writeReg to change it to something lower, like 0. Each time you decrease it by 1, you are reducing the time the sensor spends averaging the readings by 64 µs, so it can spend that extra time accumulating light instead, increasing its sensitivity. However, decreasing the averaging also makes the readings more noisy according to the datasheet.

If you are using continuous mode, you will also need to set the SYSRANGE__INTERMEASUREMENT_PERIOD register which specifies how frequently the sensor should start a new reading. The startRangeContinuous, startAmbientContinuous, and startInterleavedContinuous functions set this register for you. The datasheet says the intermeasurement period needs to bigger than the time it takes to get a measurement (see the "Continuous mode limits" section). That means that there will always be some period of time where the sensor is idle, waiting for the specified intermeasurement period to end. Therefore, if you want fast readings, it might make more sense to use single-shot mode instead of continuous mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants