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

Interrupt Example don't work #60

Open
cablesky opened this issue Dec 18, 2022 · 11 comments
Open

Interrupt Example don't work #60

cablesky opened this issue Dec 18, 2022 · 11 comments

Comments

@cablesky
Copy link

The interrupt example doesn't work. The interrupt is simply ignored. I.e. the distance is displayed although only the range of 50-100mm should be displayed.

@caternuson
Copy link
Contributor

The description is confusing. Can you post the output you are seeing in the Serial Monitor when running the example.

@cablesky
Copy link
Author

Set GPIO Config so if range is lower the LowThreshold trigger Gpio Pin
Set Interrupt Threasholds...
sVL53L0X: setInterruptThresholds
Set Mode VL53L0X_DEVICEMODE_CONTINUOUS_RANGING...
StartMeasurement...
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 57
Reading a measurement... Distance (mm): 58
Reading a measurement... Distance (mm): 58
Reading a measurement... Distance (mm): 58
Reading a measurement... Distance (mm): 58
Reading a measurement... Distance (mm): 58
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55
Reading a measurement... Distance (mm): 55

@caternuson
Copy link
Contributor

Thanks. The output looks generally as expected. Is the issue that the distance value is not changing?

Does the non-interrupt example work OK on the same setup?
https://github.com/adafruit/Adafruit_VL53L0X/blob/master/examples/vl53l0x/vl53l0x.ino

@cablesky
Copy link
Author

Thank you for your quick answer!
Yes, the example without an interrupt works perfectly.
The example with interrupt also outputs the distance values. Only the interrupt is not triggered.

@caternuson
Copy link
Contributor

The interrupt must be triggering, otherwise there would not be any output. The output is surrounded by a conditional that will only occur if the interrupt has fired.

The behavior of the interrupt with respect to the high/low limits is configurable.
image

The example sketch configures it to trigger when Level Low:

  lox.setGpioConfig(VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
                    VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
                    VL53L0X_INTERRUPTPOLARITY_LOW);

To make sure this is working, tested here and ran the example sketch on a QT PY M0 and get this output:

VL53L0X API Interrupt Ranging example


Set GPIO Config so if range is lower the LowThreshold trigger Gpio Pin 
Set Interrupt Threasholds... 
sVL53L0X: setInterruptThresholds
Set Mode VL53L0X_DEVICEMODE_CONTINUOUS_RANGING... 
StartMeasurement... 
Reading a measurement... Distance (mm): 48
Reading a measurement... Distance (mm): 50
Reading a measurement... Distance (mm): 49
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 44
Reading a measurement... Distance (mm): 41
Reading a measurement... Distance (mm): 45
Reading a measurement... Distance (mm): 45
Reading a measurement... Distance (mm): 39
Reading a measurement... Distance (mm): 41
Reading a measurement... Distance (mm): 39
Reading a measurement... Distance (mm): 39

Note none of the values are above 50mm.

You are getting values above 50mm in your output. That would be an indication of false triggers. Not lack of trigger.

Double check your wiring and make sure the VL53L0X's GPIO pin is connected to the pin referenced in the sketch.

@cablesky
Copy link
Author

Hi!
Thank you very much for your detailed answer. I have exactly the problem that the trigger (interrupt) is not executed. wiring is correct. I use an Arduino Mini Pro with 8MHZ for this.

Is it possible that I am using a VL53L0X V2 (https://de.aliexpress.com/item/32851036504.html)?
Actually I thought that the VL52LOX chip is the same as version 1.

@caternuson
Copy link
Contributor

Please post in the forums with photos of your setup showing how everything is connected.
https://forums.adafruit.com/

@awong1900
Copy link

The interrupt must be triggering, otherwise there would not be any output. The output is surrounded by a conditional that will only occur if the interrupt has fired.

The behavior of the interrupt with respect to the high/low limits is configurable. image

The example sketch configures it to trigger when Level Low:

  lox.setGpioConfig(VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
                    VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
                    VL53L0X_INTERRUPTPOLARITY_LOW);

To make sure this is working, tested here and ran the example sketch on a QT PY M0 and get this output:

VL53L0X API Interrupt Ranging example


Set GPIO Config so if range is lower the LowThreshold trigger Gpio Pin 
Set Interrupt Threasholds... 
sVL53L0X: setInterruptThresholds
Set Mode VL53L0X_DEVICEMODE_CONTINUOUS_RANGING... 
StartMeasurement... 
Reading a measurement... Distance (mm): 48
Reading a measurement... Distance (mm): 50
Reading a measurement... Distance (mm): 49
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 46
Reading a measurement... Distance (mm): 44
Reading a measurement... Distance (mm): 41
Reading a measurement... Distance (mm): 45
Reading a measurement... Distance (mm): 45
Reading a measurement... Distance (mm): 39
Reading a measurement... Distance (mm): 41
Reading a measurement... Distance (mm): 39
Reading a measurement... Distance (mm): 39

Note none of the values are above 50mm.

You are getting values above 50mm in your output. That would be an indication of false triggers. Not lack of trigger.

Double check your wiring and make sure the VL53L0X's GPIO pin is connected to the pin referenced in the sketch.

How to set trigger if i want get above 50mm?

@disq
Copy link

disq commented Feb 10, 2024

The issue with the example is the high threshold is not used and it should trigger when the ranged value is BELOW the low threshold (5cm)... because VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW is set.

The API details and how the thresholds can be defined is explained in the UM2039 API User Manual

@caternuson
Copy link
Contributor

Is there an actual issue with the example? Or is this just confusion about the interrupt behavior?

@matteogrisenti
Copy link

`#define INTERRUPT_PIN P1_5

Adafruit_VL53L0X sensor = Adafruit_VL53L0X();

void setup() {
Serial.begin(115200);

// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}

pinMode(INTERRUPT_PIN, INPUT_PULLUP); // Configura il pin di interruzione come input
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), interruptHandler, FALLING); // Associa l'ISR alla caduta dell'interruzione
Wire.begin();

if (!sensor.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}

// Configura il sensore per abilitare l'interruzione su nuova misurazione
sensor.setInterruptThresholds(0, 100); // Imposta soglie di interruzione
sensor.startMeasurement(); // Avvia le misurazioni continue

sensor.setGpioConfig( VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
VL53L0X_INTERRUPTPOLARITY_LOW);

}

void loop() {
VL53L0X_RangingMeasurementData_t measure;
sensor.rangingTest(&measure);

Serial.print("Reading a measurement... ");

if (measure.RangeStatus != 4) { // phase failures have incorrect data
Serial.print("Distance (mm): "); Serial.print(measure.RangeMilliMeter);
Serial.print("Range: "); Serial.println(measure.RangeStatus);
} else {
Serial.println(" out of range ");
}

delay(1000);
}

void interruptHandler(){
Serial.print("YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa ");
sensor.clearInterruptMask(false);
}`

This is my code, I use a MSP432P401 board and coding on Energia IDE; if I comment the attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), interruptHandler, FALLING); line all work, if Itry to use interrupt uncomment this line i can't see anything on the serial console

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

5 participants