MojoScale
Writing Code

Write constrained Python for device behavior.

Studio code should be small, explicit, and built around supported firmware modules. The goal is Python readability with native firmware doing the heavy work.

Code shape

Import supported modulesUse only modules listed in the docs panel. Unknown imports are lint errors.
Initialize hardware onceSet up camera, displays, pins, buses, or network modules near the top of the script.
Put repeated work in functionsUse named top-level functions for timers and callbacks.
Schedule behaviorUse `system.schedule(...)` to create a named action that runs a function on an interval.
Keep native work inside modulesCall `camera`, `cv`, display, GPIO, storage, and communication APIs instead of recreating those systems in script code.

Useful patterns

Timer callbackDefine `tick`, then pass `tick` to the scheduling API. Studio converts it to the firmware callback name.
Camera loopBegin the camera with a preset or config, then capture or run model inference inside a scheduled function.
Display updateInitialize the display once, draw only changed values, and flush the frame when the module docs require it.
State storageUse key-value or storage modules for small device state instead of keeping everything in globals.

Example: timed status print

main.py
import system
def tick():
    print(system.heap())
system.schedule("tick", 1000, 1000, -1, tick)
For schedule callbacks, pass the named top-level function without quotes. Studio converts it to the firmware callback name.

Common lint failures

Unsupported importThe module is not available in Studio stubs or firmware.
Unsupported methodThe module exists, but the method is not exposed yet.
Nested functionCallbacks should be top-level named functions.
Bad model loadOnly one `cv.load(...)` is allowed and the name must exist in the model catalog.
Desktop Python featureSome Python constructs or libraries are intentionally unavailable on the board.
Invalid callback formFor scheduled actions, pass a named top-level function without quotes.