Skip to content

MicroPython Library

The nXPico M firmware exposes three high-level MicroPython modules. Import them directly — no installation required.

led

WS2812 RGB LED control — color presets, raw RGB, current state.
Full reference →

modem

nRF9151 LTE-M/NB-IoT modem — AT commands, MQTT, radio control, certificate storage.
Full reference →

x509gen

RSA/EC key generation and X.509 certificate creation — on-device, no external tooling.
Full reference →


from led import Led
rgb = Led()
FunctionSignatureDescription
ConstructorLed()Init LED on GPIO23, sets off.
set_colorset_color(value: list)Set color as [r, g, b] (0–255 each).
get_valueget_value() → listReturns current color as [r, g, b].
redred()Set red.
greengreen()Set green.
blueblue()Set blue.
whitewhite()Set white.
yellowyellow()Set yellow.
cyancyan()Set cyan.
magentamagenta()Set magenta.
orangeorange()Set orange.
offoff()Turn off.
rgb.red()
rgb.set_color([0, 100, 200])
print(rgb.get_value()) # [0, 100, 200]
rgb.off()

from modem import Modem
m = Modem() # singleton — same instance on every call
FunctionSignatureDescription
ConstructorModem()Init modem, flush RX buffer.
CFUNCFUN(mode: int) → boolSet radio mode: 0 off, 1 full, 4 flight.
m.CFUN(1) # enable full RF
m.CFUN(4) # flight mode
FunctionSignatureDescription
send_cmdsend_cmd(command, expected="OK", timeout_ms=1000, is_bool=True)Send AT command, wait for response.
sendsend(data: bytes)Send raw bytes to UART1.
readread(num_bytes: int) → bytesRead raw bytes from UART1.
wait_responsewait_response(expected="OK", timeout_ms=1000) → strPoll until expected string or timeout.
ok = m.send_cmd("AT") # True / False
ver = m.send_cmd("AT+CGMR", is_bool=False) # raw response string
FunctionSignatureDescription
mqtt_cfgmqtt_cfg(client_id, keep_alive=60, clean_session=0) → boolConfigure client ID and session.
get_mqtt_cfgget_mqtt_cfg() → strRead current MQTT configuration.
mqtt_connmqtt_conn(op, username, password, url, port, sec_tag=None) → boolConnect (op=1) or disconnect (op=0).
is_mqtt_connis_mqtt_conn() → boolCheck connection status.
mqtt_publishmqtt_publish(topic, msg, qos=0, retain=0) → boolPublish a message.
mqtt_subscribemqtt_subscribe(topic, qos=0) → boolSubscribe to a topic.
m.CFUN(1)
m.mqtt_cfg("my-device")
m.mqtt_conn(1, "user", "pass", "broker.example.com", 1883)
m.mqtt_publish("sensors/temp", "23.5")
m.mqtt_subscribe("commands/#")

Credentials (certificates, keys, PSKs) are stored in the modem’s internal secure storage and referenced by a sec_tag.

FunctionSignatureDescription
write_certificatewrite_certificate(sec_tag, cert_type, content, psw=None, sha256=None) → boolWrite a credential to secure storage.
list_certificatelist_certificate(sec_tag, cert_type=None) → strList credentials for a given sec_tag.
read_certificateread_certificate(sec_tag, cert_type) → strRead the content of a stored credential.
delete_certificatedelete_certificate(sec_tag, cert_type) → boolDelete a credential from secure storage.
m.CFUN(4) # flight mode while writing credentials
m.write_certificate(1, 0, ROOT_CA) # Root CA
m.write_certificate(1, 1, CLIENT_CERT) # Client certificate
m.write_certificate(1, 2, CLIENT_KEY) # Client private key
m.CFUN(1)
m.mqtt_conn(1, "", "", "broker.example.com", 8883, sec_tag=1)

See the full reference for credential type values and parameter details.


import powman, time
FunctionSignatureDescription
powmanInitpowmanInit(absTimeMs: int)Seed the 64-bit POWMAN timer. Call once before powmanOffForMs.
powmanOffForMspowmanOffForMs(sleepingMs: int)Enter dormant mode for N milliseconds, then reboot.
powmanOffUntilGPIOpowmanOffUntilGPIO(gpio: int)Enter dormant mode, wake when GPIO goes HIGH, then reboot.
# Timed sleep
powman.powmanInit(time.ticks_ms())
powman.powmanOffForMs(30_000) # sleep 30 s, then reboot
# GPIO wake-up
powman.powmanOffUntilGPIO(10) # sleep until GPIO10 goes HIGH

import x509gen
FunctionSignatureDescription
generate_rsa_keypairgenerate_rsa_keypair(bits=2048) → (str, str)Generate RSA key pair. May take 10–30 s on RP2350.
generate_ec_keypairgenerate_ec_keypair(curve_name="secp256r1") → (str, str)Generate EC key pair. Curves: secp256r1, secp384r1, secp521r1.
generate_self_signed_certgenerate_self_signed_cert(private_key_pem, subject, ...) → strGenerate a self-signed X.509 certificate.
generate_csrgenerate_csr(private_key_pem, subject, md_alg="sha256") → strGenerate a Certificate Signing Request.
import machine, x509gen
uid = machine.unique_id()
serial = ''.join('{:02X}'.format(b) for b in uid)
priv, _pub = x509gen.generate_rsa_keypair(2048)
cert = x509gen.generate_self_signed_cert(
priv,
subject=f"CN=rp2350-{serial},O=neXo,C=IT",
not_before="20250101000000",
not_after="20350101000000",
)

See the full reference for key usage constants, CSR generation, and the complete provisioning example.