Simulator: This function needs real hardware to work with. It’s not supported in the simulator.
i2c Read Number
Read one number from an I2C address using a specified number format.
pins.i2cReadNumber(0, NumberFormat.Int8LE, false);
Parameters
- address: the 7-bit I2C address of the device you want to read a number from.
- format: the NumberFormat of the number value to read.
- repeated: if
true
, don’t send a stop condition after the read. Otherwise, a stop condition is sent whenfalse
(the default).
Returns
- a number from the device with the NumberFormat you asked for.
Examples
Read a big endian number from a device
The following example reads a number in big-endian, 16-bit, unsigned integer
format from the 7-bit I2C address 32
.
Read a number from the device at a 7-bit I2C address as a 16-bit number. The 16
, big-endian, and integer chosen for the format.
let inValue = pins.i2cReadNumber(32, NumberFormat.UInt16BE, false);
Repeated reads
Read three bytes from a device at address 33
at one time.
let nums: number[] = []
nums[0] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, true)
nums[1] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, true)
nums[2] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, false)