Skip to main content

I2C

The I2C service is used internally by the @devicescript/i2c package.

Usage

Read-write register byte

import { i2c } from "@devicescript/i2c"

const address = 0x..
const register = 0x..
const value = 0x..

await i2c.writeReg(address, register, value)

const readValue = await i2c.readReg(address, register)

Read-write register buffer

import { i2c } from "@devicescript/i2c"

const address = 0x..
const register = 0x..
const size = 0x..

await i2c.writeRegBuf(address, register, hex`...`)

const readBuf = await i2c.readRegBuf(address, register, size)

Read-write raw buffer

import { i2c } from "@devicescript/i2c"

const address = 0x..
const size = 0x..

await i2c.writeBuf(address, hex`...`)

const readBuf = await i2c.readBuf(address, size)

Errors

I2C functions may throw a I2CError error if the operation fails.