📦 Archived documentation: r1 (committed 2026-07-24) View current documentation →

serial.init()

serial.init(port, baud) → number

Initialises a serial port at the given baud rate.

Specify a parameter object for advanced usage

serial.init(port,{baud:9600,stopBits:1,parity:"odd",mode:"0,swap:false,invert:false});

:Mode 0: tx+rx, 1: rx only, 2: tx only, 3: Activates direction signalling on the expansion IO port for use with RS485 transceivers

:Swap Swap the TX RX lines on the expansion port

:Invert Invert the RS485 high low signaling (Experimental)

Arguments

NameTypeRequiredDefaultDescription
port number yes 1 = isolated RS-485, 2 = non-isolated RS-485.
baud | config number | object yes Baud rate, e.g. 9600, 19200. for standard 8n1 settings otherwise supply a json object with parameters

Returns

number Status code — 0 on success.

Example

let port = 1;             // isolated RS-485
serial.init(port, 19200);