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

Fix interrupt and waiting #41

Open
badVibes-- opened this issue Apr 1, 2020 · 1 comment
Open

Fix interrupt and waiting #41

badVibes-- opened this issue Apr 1, 2020 · 1 comment

Comments

@badVibes--
Copy link

badVibes-- commented Apr 1, 2020

Sorry, I don't yet know hot to make a pull request but i thought this might be useful to others.

In the cpp file init method change line 239 to:
writeReg(GPIO_HV_MUX_ACTIVE_HIGH, readReg(GPIO_HV_MUX_ACTIVE_HIGH) & 0xEF);

this will make the GPIO pin go low when a measurement is done.

I would also add this two methods (maybe you have a better name for the second one) which splits the continuous read in two parts.

bool VL53L0X::dataAvailable(void)
{
if((readReg(RESULT_INTERRUPT_STATUS) & 0x07) == 0)
return false;
else return true;
}

uint16_t VL53L0X::readRangeDataContinuous(void)
{
uint16_t range = readReg16Bit(RESULT_RANGE_STATUS + 10);
writeReg(SYSTEM_INTERRUPT_CLEAR, 0x01);
return range;
}

You can use it like so:

if(sensor.dataAvailable())
{
Serial.println(sensor.readRangeDataContinuous());
}

Reading the sensor like this is leaves much more time for other stuff. Checking for data takes about 120 us and reading takes 230us on a tennsy 3.2. The original way takes around 20 ms. Using the interrupt pin makes checking even faster:). I measured this with the Wire clock at 400000.

@badVibes--
Copy link
Author

Well, I learned how to make a pull request and did it...

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

1 participant