SolarOS 4.13.4 manual · api
Lua gpio and peripherals API
API overview · Python gpio and peripherals
solaros.battery
solaros.battery:statuswith voltage, percentage, external-power,
charging, and charging_known fields when battery support is compiled
solaros.sensors
list(): return registered providers withname,driver,temperature,environment([name]): return temperature and humidity from one namedtemperature([name]): return degrees Celsius from the default or namedhumidity([name]): return relative humidity as a percentage from the default
and humidity fields.
provider. Without a name, use a combined provider when possible, then the default provider for each value.
provider, or nil when unavailable.
or named provider, or nil when unavailable.
for _, sensor in ipairs(solaros.sensors.list()) do
print(sensor.name, sensor.driver)
end
print(solaros.sensors.temperature())
print(solaros.sensors.humidity())
solaros.gnss
list(): return registered receivers withname,driver,power_control,power(enabled[, name]): change a driver-managed receiver power rail,fix([name[, timeout_ms]]): poll a receiver, defaulting to the first one and
and powered.
defaulting to the first receiver, and return the requested state.
a 1000 ms timeout. The result includes scaled-integer position, accuracy, motion, fix, satellites_valid, satellite count, and UTC fields.
local fix = solaros.gnss.fix()
if fix.valid then
print(fix.latitude_deg_e7, fix.longitude_deg_e7)
end
solaros.haptic
list(): return registered haptic devices withname,driver, and theplay(effect[, name]): play an effect from1through the device'sstop([name]): stop the active effect, defaulting to the first device.
number of supported numbered effects.
reported effect count, defaulting to the first haptic device.
solaros.haptic.play(15)
solaros.charger
list(): return registered chargers, concrete drivers, and supported ranges.status([name]): return charger state, input flags, configured values, andenable(enabled[, name]): enable or disable charging.set_input_limit(mA[, name]),set_current(mA[, name]), and
the raw fault byte.
set_voltage(mV[, name]): set an exact value in the advertised range.
OTG/boost mode and battery-chemistry policy are not exposed.
local status = solaros.charger.status()
print(status.state)
solaros.nfc
list(): return registered readers withname,driver,power_control,power(enabled[, name]): change a driver-managed reader power rail,scan([name[, timeout_ms]]): discover one collision-free NFC-A tag. The
and powered.
defaulting to the first reader, and return the requested state.
returned uid and atqa strings are binary-safe; sak is numeric and technology is "nfca".
solaros.imu
list(): return registered motion sensors withname,driver, and booleansample([name[, timeout_ms]]): read one sample, defaulting to the first
acceleration, angular_velocity, and orientation capabilities.
sensor and a 1000 ms timeout. The result contains timestamp_us and any available acceleration_m_s2, angular_velocity_rad_s, and orientation tables. Vectors use x, y, and z; orientation is a unit quaternion with w, x, y, and z.
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.gpio: constantsINPUT,OUTPUT,PULL_NONE,PULL_UP,PULL_DOWN; functionspins,allowed,mode,configure,read,write,releasewhen GPIO support is compiled. Pin tables includeexpansion,allowed,available,claimed,owner, andpolicy(free,releasable, orfixed).
solaros.onewire
solaros.onewire:allowed,reset,scan,xferfor the direct-pin compatibility API when OneWire support is compiled
solaros.led
solaros.led:status,set,on,off,togglewhen GPIO support is compiled
solaros.adc
solaros.adc:pins,readwhen ADC support is compiled
solaros.pwm
solaros.pwm: constantsFREQ_MIN,FREQ_MAX; functionsstatus,set,offwhen PWM support is compiled
solaros.neopixel
solaros.neopixel:list,set,fill,show,clearwhen the NeoPixel expansion package is compiled
solaros.i2c
solaros.i2c:info,probe,scan,read_reg,write_regwhen I2C support is compiled
solaros.spi
solaros.spi: constantsMODE0throughMODE3,DEFAULT_SPEED, andMAX_SPEED; functionsstatus,xfer,read,writewhen SPI support is compiled
solaros.uart
solaros.uart:status,baud,is_valid_baud,mode,write,readwhen UART support is compiled
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.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.