MojoScale Studio Docs
API Reference

gpio

GPIO native Berry module.

Studio Docs Sensors & I/O

import gpio

The gpio module controls ESP32 digital pins. Use it for simple inputs, outputs, edge callbacks, relays, LEDs, buttons, and other low-level digital IO.

Quick example

import gpio
gpio.setup(2, "out")
gpio.write(2, 1)
value = gpio.read(0)

importgpio

GPIO native Berry module.

The gpio module controls ESP32 digital pins. Use it for simple inputs, outputs, edge callbacks, relays, LEDs, buttons, and other low-level digital IO.

API 5 available

gpio.setup(pin: int, mode: str) -> any

Configure a GPIO pin mode.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO number.
mode str positional or keyword Yes Native mode such as "in", "out", or a firmware-specific mode.
Returns

any Native success value, if the firmware returns one.

gpio.write(pin: int, value: any) -> any

Write a digital value to a GPIO pin.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO number.
value any positional or keyword Yes Digital value, usually 0 or 1.
Returns

any Native success value, if the firmware returns one.

gpio.read(pin: int) -> int

Read a digital value from a GPIO pin.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO number.
Returns

int Integer digital level, usually 0 or 1.

gpio.on_change(pin: int, callback: callback, mode: str = None) -> str

Register a callback for GPIO level changes.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO number.
callback callback positional or keyword Yes Function name or callable accepted by the firmware.
mode str positional or keyword No Optional native edge or trigger mode.
Returns

str Native registration result.

gpio.remove_change(pin: int) -> any

Remove a GPIO change callback.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO number to detach from change notifications.
Returns

any Native removal result.