i2c
Interact with I2C bus devices for reading sensors and controlling peripherals.Input Parameters
Action to perform:
detect- List available I2C busesscan- Find devices on a busread- Read bytes from devicewrite- Send bytes to device
I2C bus number (e.g., “1” for /dev/i2c-1). Required for scan/read/write.
7-bit I2C device address (0x03-0x77). Required for read/write.
Register address to read from or write to. If set, sends register byte before read/write.
Bytes to write (0-255 each). Required for write action.
Number of bytes to read (1-256). Used with read action.
Must be
true for write operations. Safety guard to prevent accidental writes.Actions
detect
List available I2C buses by scanning/dev/i2c-* devices.
Example:
scan
Scan an I2C bus for connected devices (addresses 0x03-0x77). Example:read
Read bytes from an I2C device. Read from device (no register):write
Write bytes to an I2C device. Requiresconfirm: true for safety.
Write to device:
Error Conditions
I2C is only supported on Linux- Non-Linux OS detectedaction is required- Missing action parameterunknown action: {action}- Invalid action valuebus is required- Missing bus for scan/read/writeinvalid bus identifier- Bus must be numeric (e.g., “1”)address is required- Missing address for read/writeaddress must be in valid 7-bit range (0x03-0x77)- Invalid addressdata is required for write- Missing data arrayconfirm must be true for write operations- Safety confirmation missing
Platform Requirements
Kernel modules:spi
Interact with SPI bus devices for high-speed peripheral communication.Input Parameters
Action to perform:
list- Find available SPI devicestransfer- Full-duplex send/receiveread- Receive bytes (sends zeros)
SPI device identifier (e.g., “2.0” for /dev/spidev2.0). Required for transfer/read.
SPI clock speed in Hz (1 Hz - 125 MHz). Default: 1 MHz.
SPI mode (0-3). Sets CPOL and CPHA:
- Mode 0: CPOL=0, CPHA=0
- Mode 1: CPOL=0, CPHA=1
- Mode 2: CPOL=1, CPHA=0
- Mode 3: CPOL=1, CPHA=1
Bits per word (1-32). Default: 8.
Bytes to send (0-255 each). Required for transfer action.
Number of bytes to read (1-4096). Required for read action.
Must be
true for transfer operations. Safety guard to prevent accidental writes.Actions
list
Find available SPI devices by scanning/dev/spidev*.
Example:
transfer
Full-duplex SPI transfer (simultaneous send and receive). Example:read
Read bytes from SPI device (sends zeros during read). Example:Error Conditions
SPI is only supported on Linux- Non-Linux OS detectedaction is required- Missing action parameterunknown action: {action}- Invalid action valuedevice is required- Missing device for transfer/readinvalid device identifier: must be in format "X.Y"- Invalid device formatspeed must be between 1 Hz and 125 MHz- Invalid speedmode must be 0-3- Invalid modebits must be between 1 and 32- Invalid bits per worddata is required for transfer- Missing data arraylength is required for read- Missing length parameterconfirm must be true for transfer operations- Safety confirmation missing
Platform Requirements
Kernel modules:SPI Mode Reference
| Mode | CPOL | CPHA | Clock Polarity | Clock Phase |
|---|---|---|---|---|
| 0 | 0 | 0 | Idle low | Sample on leading edge |
| 1 | 0 | 1 | Idle low | Sample on trailing edge |
| 2 | 1 | 0 | Idle high | Sample on leading edge |
| 3 | 1 | 1 | Idle high | Sample on trailing edge |