SolarOS

SolarOS 4.17.7 manual · api

Lua gpio and peripherals API

API overview · Python gpio and peripherals

solaros.battery

solaros.sensors

for _, sensor in ipairs(solaros.sensors.list()) do
    print(sensor.name, sensor.driver)
end

print(solaros.sensors.temperature())
print(solaros.sensors.humidity())

solaros.gnss

local fix = solaros.gnss.fix()
if fix.valid then
    print(fix.latitude_deg_e7, fix.longitude_deg_e7)
end

solaros.encoder

Available when the common encoder service is compiled. list() returns metadata records with name, driver, integer mode, and can_reset. status(name) adds signed integer count; read(name) returns that count. reset(name) sets it to zero when supported. Names are required and service errors raise errors. MODE_X1, MODE_X2, and MODE_X4 equal 1, 2, and 4. See Encoder counts for attachment, wiring, and count limits.

solaros.motor

Available when the common motor service is compiled. list() returns endpoint metadata; status(name) returns normalized state and optional driver diagnostics. Use drive(name, value) with a finite signed value from -1.0 to 1.0. Zero coasts. coast(name), brake(name), and clear(name) share the shell semantics; optional unsupported operations raise an error. Names are required.

The same API works with all registered motor drivers. A normalized command is not a measured speed or voltage. See Motor control for record fields, fault-mask constants, driver scaling, lifecycle, and examples.

solaros.haptic

solaros.haptic.play(15)

solaros.charger

OTG/boost mode and battery-chemistry policy are not exposed.

local status = solaros.charger.status()
print(status.state)

solaros.nfc

solaros.imu

local sample = solaros.imu.sample()
if sample.acceleration_m_s2 then
    print(sample.acceleration_m_s2.x,
          sample.acceleration_m_s2.y,
          sample.acceleration_m_s2.z)
end

solaros.gpio

solaros.onewire

solaros.led

solaros.adc

solaros.pwm

Pass an output string such as "native:1" to set, pulse, and off. An integer selects a native GPIO. Providers enforce their own shared frequency groups; conflicting requests are rejected within a group.

solaros.servo

Available when the servo service is compiled. Use list(), status(name), open(name, output, min_us, max_us, min_deg, max_deg[, freq_hz[, inverted]]), set(name, angle_deg), pulse(name, pulse_us), disable(name), and close(name) for calibrated positional outputs. Use a boolean for inversion. Opening sends no pulses; commands start output. Outputs belong to their creating runtime and are closed on interpreter exit. Status reports commanded position.

See Servo outputs for calibration, record fields, examples, and resource limits.

solaros.neopixel

solaros.i2c

solaros.spi

solaros.uart

Direct-pin OneWire

solaros.onewire.scan(pin) returns tables containing a 16-digit hexadecimal address and numeric family code. solaros.onewire.xfer(pin, read_len[, data]) resets the bus, writes the binary-safe data string, and returns read_len bytes. Reads and writes are each limited to 64 bytes.

Default UART

solaros.uart is the default uart0 compatibility table; use solaros.buses.uart_* for another named UART and solaros.buses.attach() or detach() for lifecycle control. solaros.uart.status() includes the bus name, attached, rx_buffered, and rx_buffered_valid. When another owner is actively using the UART, rx_buffered_valid is false because the live RX count is not sampled.

Quick reference

Use solaros.gpio, solaros.onewire, solaros.led, solaros.adc, solaros.pwm, solaros.servo, solaros.motor, solaros.encoder, solaros.i2c, solaros.spi, solaros.uart, solaros.neopixel, solaros.battery, solaros.charger, solaros.sensors, solaros.gnss, solaros.haptic, solaros.imu, and solaros.nfc for gpio and peripherals. See man lua for runtime conventions and service availability.