# Get microseconds with Interrupt

**URL:** <https://forum.xojo.com/t/get-microseconds-with-interrupt/87104>\
**Category:** Raspberry Pi\
**Created:** [November 26, 2025, 10:43pm UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104 "2025-11-26T22:43:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Dakin](https://forum.xojo.com/user_avatar/forum.xojo.com/eugene_dakin/32/178_2.png) [@Eugene\_Dakin](https://forum.xojo.com/u/Eugene_Dakin)\
**Post date:** [November 26, 2025, 10:43pm UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104/1 "2025-11-26T22:43:50Z")

</div>

Hello Everyone,

I am working with sonar (Raspberry Pi) and microsecond timing is important to measure the time-of-flight for the waves to bounce-off an object.

When I use the lguTime function ( [GitHub - eugenedakin/lgpio-GPIO: Wrapper uses the new C-language gpiochip functions for the Raspberry Pi](https://github.com/eugenedakin/lgpio-GPIO) ) in a loop, it work satisfactory. I am trying to get more precise microsecond timing and have implemented an Interrupt. When I try to use the lguTime in the interrupt method, I always get a returned value of zero. If I am outside of the interrupt method, I get the accurate microsecond time from the lguTime call.

I attempted to use System.Microsecond with Xojo, but the microsecond time is almost the same (about 2400 microseconds).

Is there another command or way to get the microseconds when using an interrupt that is able to accurately retrieve microseconds in Xojo?

Thank you.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [November 27, 2025, 9:04am UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104/2 "2025-11-27T09:04:45Z")

</div>

RPI is not really enough realtime for this.

You could try a consoleapp and then use isolate cpu to have that app use a single core.

or use an arduino via serial

or phidgets trough mbs or declares

---

<div class="post-metadata">

**Author:** ![Eugene\_Dakin](https://forum.xojo.com/user_avatar/forum.xojo.com/eugene_dakin/32/178_2.png) [@Eugene\_Dakin](https://forum.xojo.com/u/Eugene_Dakin)\
**Post date:** [November 27, 2025, 3:43pm UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104/3 "2025-11-27T15:43:18Z")

</div>

Hi @DerkJ,

Thanks for your comments.

> [@DerkJ](#):
>
> RPI is not really enough realtime for this.

I can run this on a Pi with C, C++, and Python, but not with Xojo due to Xojo’s stuttering issues. Its a long-time issue with Xojo, and I was hoping someone had a work-around.

> [@DerkJ](#):
>
> or phidgets trough mbs or declares

I tried some declares, and I’ll try a few more and see if I can make some progress.

> [@DerkJ](#):
>
> or use an arduino via serial

Yes, this would work. Although I could use an entire Arduino written with C for the project, and I am trying to get Xojo to work.

Once again, thanks for your helpful comments. 🙂

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [November 27, 2025, 8:35pm UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104/4 "2025-11-27T20:35:47Z")

</div>

Where do you setup the interrupt with ?

---

<div class="post-metadata">

**Author:** ![Eugene\_Dakin](https://forum.xojo.com/user_avatar/forum.xojo.com/eugene_dakin/32/178_2.png) [@Eugene\_Dakin](https://forum.xojo.com/u/Eugene_Dakin)\
**Post date:** [November 27, 2025, 8:58pm UTC](https://forum.xojo.com/t/get-microseconds-with-interrupt/87104/5 "2025-11-27T20:58:33Z")

</div>

Hi @DerkJ,

Pardon my unprofessional spaghetti-code, attached is an example that I am trying to get to work. When Pin 17 receives a High (3.3-volt) signal, the callback fires and the EchoAlertCallback method fires. I need to determine the measured time in microseconds to calculate the distance of the object for the time-of-flight calculation.

In this (of many examples that I have tried) example, I am trying to save the microsecond value with the lguTimestamp declare in the lgpio Module. The InterruptModule.FinishEchoInterruptTime has a value of zero, even though it should have the microsecond value of lguTimeStamp.

I hope this helps.

[HC-SR04Rev12Interrupt.xojo\_binary\_project.zip](https://forum.xojo.com/uploads/short-url/2QXPZtSEeo5H3XnsmovY7ZmjiD.zip) (25.6 KB)
