MojoScale Studio Docs
API Reference

uart

UART native Berry module.

Studio Docs Buses & Protocols

import uart

The uart module exposes serial communication from firmware. Use it to talk to external controllers, sensors, modems, and protocol adapters over TX/RX pins.

Quick example

import uart
    uart.begin(9600, 17, 16)
    uart.write("AT
")
    uart.on_data("handle_uart")

importuart

UART native Berry module.

The uart module exposes serial communication from firmware. Use it to talk to external controllers, sensors, modems, and protocol adapters over TX/RX pins.

API 5 available

uart.begin(baud: int, tx: any, rx: any) -> any

Initialize UART pins and baud rate.

Parameters
Name Type Pass as Required Description
baud int positional or keyword Yes Serial baud rate.
tx any positional or keyword Yes GPIO used for transmit.
rx any positional or keyword Yes GPIO used for receive.
Returns

any Native initialization result.

uart.write(data: any) -> any

Write text or bytes to UART.

Parameters
Name Type Pass as Required Description
data any positional or keyword Yes String or byte payload to send.
Returns

any Native write result, if provided.

uart.on_data(callback: callback) -> str

Register a callback for received UART data.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

uart.off_data() -> any

Remove the UART receive callback.

Returns

any Native removal result.

uart.stats() -> dict

Return UART traffic counters.

Returns

dict Native map-like value with RX and TX counts.