13.1.2. Scripts, examples, and the documents folder

13.1.2.1. New files

Create a new file and the IDE opens an untitled_N.py buffer preloaded with a minimal capture loop – reset the sensor, configure the pixel format and frame size, then snapshot and print the frame rate forever. The starter script is adapted to the connected board, so it runs as created. The buffer lives in memory only: you can edit and run it repeatedly without ever saving it, which makes new files the cheapest way to test an idea. Save it to disk and it becomes an ordinary script.

13.1.2.2. The examples menu

File → Examples holds a categorized library of example scripts covering essentially every feature the camera has – one folder per topic, from basic snapshots through colour tracking, machine learning, and board peripherals. Opening an example loads it into a memory buffer like a new file, so you can modify and run it freely without touching the installed copy.

By default the menu is filtered to the connected board and its sensor: examples that need hardware your camera does not have are hidden, and the menu asks for a connection before showing anything at all. Tools → Filter examples by board and sensor type turns the filter off when you want to browse the full set.

Examples are also adapted as they open. The scripts are written against a typical colour sensor, so when the connected camera differs – a thermal or event sensor, a board with a different native resolution – the IDE adjusts the pixel format and frame size lines to values your hardware supports while loading, and the example runs as opened.

Working through the examples menu is the fastest way to learn what the camera can do; most applications start as an example that grew.

13.1.2.3. The documents folder

For your own scripts, the IDE watches an OpenMV directory inside your documents folder (Documents/OpenMV). Everything you store there appears under File → Documents Folder, including subdirectories, so your script collection is one menu away. The menu reads the directory live – files you add outside the IDE show up the next time the menu opens.

The IDE runs as a single instance: open a .py file from your file manager, or drop one onto the IDE window, and it opens in the running window rather than launching a second copy.

13.1.2.4. Cross-compiling a script

Tools → MicroPython Tools → Copy/Convert Python File copies a .py file to a destination – the camera’s drive, when one is connected – and lets you choose what happens on the way: copy it unchanged, strip whitespace and/or comments to shrink it, or compile it to a .mpy bytecode file with the mpy-cross compiler matched to the target board. A .mpy file imports exactly like the .py it came from, loads faster, and does not ship its source – the form to use when distributing a library module to the camera’s filesystem. With a camera connected the IDE picks the target board automatically; otherwise the dialog asks which board to compile for. The board choice matters because it sets the processor architecture the compiler targets: a .mpy file is matched to the camera it will run on, and one compiled for a different board family is not guaranteed to load.

See also

MicroPython tools for mpy-cross and mpremote as standalone command-line tools, and MicroPython .mpy files for the .mpy file format itself.