i2c Read Register
Read a number value from a device register at an address on the I2C bus.
pins.i2cReadRegister(0, 0)
Devices connected to an I2C bus will often have registers where data values are set as status or action requests. Although the device is accessed at a single address, it can have multiple registers. Each register has an index so a register read operation can get the data value from the correct place. Registers are like mailslots at a post office that hold a single number value.
Parameters
- address: a number between
8
and123
that is the address of a chip on the I2C bus. - register: a number that is the index of the device register to write to.
- valueFormat: An optional format specifier for the number you will write to the register, like:
UInt16LE
. The default isUInt8LE
.
Returns
- a number to that is read from the register at the address on the I2C bus. It’s size (number of bytes) depends on what you say in valueFormat.
Example
Read a value from a temperature sensor connected to the I2C bus, The sensor is connected at address 41
and the temperature value register is at index 3
.
let sensor = 41
let register = 3
let temperature = 0
temperature = pins.i2cReadRegister(sensor, register)