# Running tof\_camera\_1.py results in error: ImportError: no module named 'tof'

**URL:** <https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410>\
**Category:** OpenMV Boards\
**Created:** [August 14, 2022, 2:36pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410 "2022-08-14T14:36:25Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfitzgerald](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@tfitzgerald](https://forums.openmv.io/u/tfitzgerald)\
**Post date:** [August 14, 2022, 2:36pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/1 "2022-08-14T14:36:25Z")

</div>

While trying to run tof\_camera\_1.py from the examples directory, I get the following error message:

Traceback (most recent call last):  
File “”, line 6, in   
ImportError: no module named ‘tof’  
MicroPython: v1.18-omv-r6 OpenMV: v4.3.1 HAL: v1.9.0 BOARD: NICLAV-STM32H747  
Type “help()” for more information.

Any ideas to fix this issue?  
Thank you,  
Thane

---

<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:** [August 14, 2022, 8:52pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/2 "2022-08-14T20:52:29Z")

</div>

That example is not valid anymore. We need to remove it.

---

<div class="post-metadata">

**Author:** ![tfitzgerald](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@tfitzgerald](https://forums.openmv.io/u/tfitzgerald)\
**Post date:** [August 15, 2022, 12:34am UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/3 "2022-08-15T00:34:23Z")

</div>

Hi Kwabena,

thank you for the response.  
Thane

---

<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:** [August 18, 2022, 8:10pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/4 "2022-08-18T20:10:43Z")

</div>

This example is for the `tof` module which is not enabled for all cameras by default, and it currently only supports the `VL53L5CX` ToF sensor.

---

<div class="post-metadata">

**Author:** ![tfitzgerald](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@tfitzgerald](https://forums.openmv.io/u/tfitzgerald)\
**Post date:** [August 19, 2022, 1:59pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/5 "2022-08-19T13:59:33Z")

</div>

Hi ,

thank you for your response.

Thane

---

<div class="post-metadata">

**Author:** ![Greg-L](https://avatars.discourse-cdn.com/v4/letter/g/97f17d/32.png) [@Greg-L](https://forums.openmv.io/u/Greg-L)\
**Post date:** [September 10, 2023, 10:44pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/6 "2023-09-10T22:44:49Z")

</div>

Sorry to revive this, but if I happen to have that sensor, is there a way to incorporate it? Or is it intended for a shield with that sensor?

---

<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 11, 2023, 7:59pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/7 "2023-09-11T19:59:11Z")

</div>

We don’t have any shields with that sensor. What are you trying to do? We haven’t released a product with it yet as it’s… very expensive to add to the camera system.

---

<div class="post-metadata">

**Author:** ![wedge](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wedge](https://forums.openmv.io/u/wedge)\
**Post date:** [February 14, 2025, 2:23pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/8 "2025-02-14T14:23:43Z")

</div>

I once was in the situation to deal with that sensor in combination with openMV cams. I did not manage to get in running and ended up with a workaround.  
However release notes state that for the drivers “vl53l5cx: Add shutdown function and fix deinit.” That pretty much sounds like there is still development done in that direction, docs mention vl53l5cx (though no electrical information can be found) and the examples (I’ve just checked) still don’t work. Mysterious I think. 🙂

---

<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:** [February 14, 2025, 6:06pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/9 "2025-02-14T18:06:08Z")

</div>

All will be revealed soon. 😉

---

<div class="post-metadata">

**Author:** ![joddern](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@joddern](https://forums.openmv.io/u/joddern)\
**Post date:** [February 24, 2025, 3:51pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/10 "2025-02-24T15:51:56Z")

</div>

So the tof\_camera\_1.py will be working soon? How soon? What does this example do exactly?

---

<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:** [February 24, 2025, 9:07pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/11 "2025-02-24T21:07:08Z")

</div>

It’s for a new product. Please wait until the product launch.

---

<div class="post-metadata">

**Author:** ![NicoGerman](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@NicoGerman](https://forums.openmv.io/u/NicoGerman)\
**Post date:** [June 2, 2026, 8:25pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/12 "2026-06-02T20:25:43Z")

</div>

Could you please let me know if there are any updates, or if not, when one is expected? I intend to use the sensor for my master’s thesis.

---

<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:** [June 2, 2026, 8:26pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/13 "2026-06-02T20:26:23Z")

</div>

Yeah, it works on the AE3: [OpenMV AE3 - OpenMV MicroPython 1.28 documentation](https://docs.openmv.io/openmvcam/quickref/openmv-ae3.html#timeofflight-sensor)

---

<div class="post-metadata">

**Author:** ![NicoGerman](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@NicoGerman](https://forums.openmv.io/u/NicoGerman)\
**Post date:** [June 2, 2026, 10:00pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/14 "2026-06-02T22:00:32Z")

</div>

I would also like to ask whether the ToF module can be imported on the N6, or whether the firmware would need to be modified as well.

---

<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:** [June 2, 2026, 10:15pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/15 "2026-06-02T22:15:47Z")

</div>

There’s no ToF module on the N6.

---

<div class="post-metadata">

**Author:** ![NicoGerman](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@NicoGerman](https://forums.openmv.io/u/NicoGerman)\
**Post date:** [June 2, 2026, 11:05pm UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/16 "2026-06-02T23:05:24Z")

</div>

Thanks. To be absolutely sure: if I connect a VL53L8CX via I²C, could I use the ToF driver [tof — time-of-flight sensor driver - OpenMV MicroPython 1.28 documentation](https://docs.openmv.io/library/omv.tof.html) on the N6, or would the firmware need to be modified/rewritten? You said there’s no ToF module on the N6 — does that only refer to an integrated module, or is external ToF hardware over I²C generally unsupported? If firmware changes are required, are there existing driver examples or guidance on the expected effort?

---

<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:** [June 3, 2026, 12:28am UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/17 "2026-06-03T00:28:49Z")

</div>

You can just create a new driver using I2C for any ToF sensor: [6.23. I2C basics - OpenMV MicroPython 1.28 documentation](https://docs.openmv.io/openmvcam/tutorial/hardware/i2c/i2c-basics.html)

If you point Claude Code at the C driver and ask it to rewrite it in Python for the OpenMV Cam using the machine module, it can generate the code very quickly.

---

<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:** [June 3, 2026, 12:50am UTC](https://forums.openmv.io/t/running-tof-camera-1-py-results-in-error-importerror-no-module-named-tof/7410/18 "2026-06-03T00:50:50Z")

</div>

[vl53l8cx\_tof.py](https://forums.openmv.io/uploads/short-url/itxRKBmCreQrnRnAgqrmweFqKOJ.py) (145.3 KB)

It looks like there’s quite a binary package for this driver… so you might want to restructure this code. But here’s the result. From the AI:

## What it is

A single, self-contained MicroPython driver that reproduces OpenMV’s built-in `tof` C module (modules/py\_tof.c) for the **VL53L8CX** using only `machine.I2C` — no firmware rebuild needed. It’s a faithful port of ST’s ULD (drivers/vl53l8cx): `vl53l8cx_init`, the firmware download, DCI read/write/replace, offset/xtalk buffer fix-ups, `start_ranging`, `check_data_ready`, and `get_ranging_data`.

Per your choices: **VL53L8CX only** , **single self-contained file** (the ~86 KB sensor firmware + config/xtalk/NVM blobs are embedded as base64 and decoded at import — file is ~145 KB), **core ranging only** (no image-drawing helpers).

## API (mirrors the `tof` module)

```python
from vl53l8cx_tof import VL53L8CX

tof = VL53L8CX(bus=3) # AE3 = I2C3; uploads FW, starts 8x8/15Hz continuous
grid, lo, hi = tof.read_depth() # grid = 64 floats (mm), row-major 8x8
tof.width(); tof.height(); tof.refresh() # 8, 8, 15
tof.reset() # stop ranging

```

`read_depth(hmirror=False, vflip=False, transpose=False, timeout=100)` returns `(list, min, max)` and applies the same orientation logic (including the default mirror-on) as `py_tof_read_depth`. Running the file directly prints the live 8×8 grid.

## Verification

The blobs extract byte-exact from the C headers (firmware = 0x15000, config = 972, xtalk = 776, NVM = 40). I unit-tested the trickiest ported paths against the C semantics with a mock I2C:

- `start_ranging` computes `data_read_size = 184` and patches the distance block size to 64 ✓
- `_get_ranging_data` word-swap + int16 extraction + header/footer corruption check ✓
- negative distance truncates toward zero (matching C `int16 /= 4`) ✓
- orientation + min/max ✓

## Caveats worth noting

- **Not run on real hardware here** — the bring-up is a line-by-line port, but I couldn’t exercise the actual I2C bus from this environment.
- Default wiring is `bus=3` (AE3 I2C3); the sensor’s 8-bit address `0x52` is the 7-bit `0x29` machine.I2C expects (both forms accepted).
- Firmware is chunked to `VL53L8CX.CHUNK = 1024` bytes per I2C burst; lower it if a board’s I2C driver rejects large transfers. Python firmware upload is slower than the C path (one-time, at startup).
- It assumes no XSHUT/reset line; `_recover()` re-runs the full firmware bring-up on a ranging timeout.

* * *

Note that it took Claude about 10 minutes to make the above driver. If you use the AI tools they can do pretty much all the Python you want.
