# TOF on ae3 is working eratic

**URL:** <https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880>\
**Category:** OpenMV Boards\
**Created:** [September 19, 2026, 3:02pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880 "2026-09-19T15:02:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ulf\_Andersson](https://avatars.discourse-cdn.com/v4/letter/u/c0e974/32.png) [@Ulf\_Andersson](https://forums.openmv.io/u/Ulf_Andersson)\
**Post date:** [September 19, 2026, 3:02pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/1 "2026-09-19T15:02:55Z")

</div>

I have a openmv ae3  
and I am trying to use the tof, it’s very nice that is possible to mesure in different directions  
but there is a 50 50 chance of success  
the initialization of tof works sometimes  
can one catch it with error handling or are there other alternatv  
My experimental code:

```python
import tof
import time

tof.reset()
time.sleep_ms(3000)
tof.init(1)
time.sleep_ms(2000)

# while True:
    # get dist
    # depth = tof.read_depth()

while True:
    try:
        # get dist
        depth = tof.read_depth()
        for pos in range(64):
            print("pos nummer:", pos)
            print(depth[0][pos])

    except OSError:
        # The sensor can occasionally fault on a specific frame read.
        # If it drops a packet, reset the stream buffer and continue.
        tof.reset()
        time.sleep_ms(2000)

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [September 20, 2026, 1:09am UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/2 "2026-09-20T01:09:23Z")

</div>

Which firmware version are you on and can you paste the exact exception text? All of the ToF fixes for the AE3 are in v5.0.0 and later. Two things in your script: the module raises `RuntimeError`, not `OSError`, so your `except` never runs. Also, `tof.init()` already power-cycles the sensor, so the `tof.reset()` and the sleeps before it aren’t needed. Try:

```python
import tof
tof.init()
while True:
    try:
        depth, dmin, dmax = tof.read_depth()
        print(depth)
    except RuntimeError as e:
        print("tof error:", e)

```

We’ve also made init and ranging more tolerant in the next release.

Please do Tools-\>Install the Latest Deve release to get the latest firmware on the AE3.

---

<div class="post-metadata">

**Author:** ![Ulf\_Andersson](https://avatars.discourse-cdn.com/v4/letter/u/c0e974/32.png) [@Ulf\_Andersson](https://forums.openmv.io/u/Ulf_Andersson)\
**Post date:** [September 20, 2026, 2:11pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/3 "2026-09-20T14:11:30Z")

</div>

Thanks kwagyeman

I have firmware 5.0.1  
It’s work fare bether but there is an runtime error some times

 ![image.png](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/e/e4b650b51fd05212f1d760e5a3ff97bb0a0f706e.png)

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [September 20, 2026, 2:32pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/4 "2026-09-20T14:32:58Z")

</div>

I’ve pushed many fixes to ToF recently, mainly to address recovery and stability (it was much worse before). However, the intermittent ToF failures still happen and they’re expected (hardware thing really, see below), so you should just ignore them just like the examples do:

```Python
    except RuntimeError:
        continue

```

The driver auto-recovers from this and the next frame should be captured successfully. The reason why it occasionally fails is that sometimes a read overlaps the sensors frame write to its internal buffer (it’s not double-buffered), so the driver finds a mismatching header and footer in one frame and reports a corrupted frame (called GO2 errors). When this happens I retry a read only once, if two frames are corrupted in a row it raises an exception. Perhaps there’s room for improvement here, like retry more times with a backoff/random delay.

---

<div class="post-metadata">

**Author:** ![Ulf\_Andersson](https://avatars.discourse-cdn.com/v4/letter/u/c0e974/32.png) [@Ulf\_Andersson](https://forums.openmv.io/u/Ulf_Andersson)\
**Post date:** [September 24, 2026, 3:15pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/5 "2026-09-24T15:15:11Z")

</div>

Thanks  
Is it possible to include tof.inith() in the error handling?

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [September 24, 2026, 4:31pm UTC](https://forums.openmv.io/t/tof-on-ae3-is-working-eratic/11880/6 "2026-09-24T16:31:04Z")

</div>

> [@Ulf\_Andersson](#):
>
> Is it possible to include tof.inith() in the error handling?

It’s not needed, the driver automatically resets/recovers on error, before raising, you’d just be slowing it down by doing it twice. Note we’ve made a couple more small fixes to improve things further. Please give the development firmware a try, if you like.
