i2c device
Talks to an I2C device that has no node of its own. Each message that arrives does one transfer.
Properties
- I2C bus — the bus the device is wired to. Required. See I2C bus.
- operation —
read bytes,write msg.payloadorscan the bus(read,write,scanin the flow file). Defaultread. - address — the device's 7-bit address, such as
0x29or41. Up to0x7f. Required except forscan. - register — the register to read or write, such as
0x80. Up to0xff. Leave it empty for a device without registers. - length (bytes) — for
read, how many bytes, 1 to 256. Default 1.
Wiring
Input — any message starts a transfer. For write, payload is what to send: bytes, a list of numbers 0 to 255,
or one number 0 to 255.
Output — the same message, with other fields kept:
read:payloadis the bytes read. Reading register0x92at address0x29(a TCS34725's ID) givesb'D'.write:payloadis unchanged.scan:payloadis the list of addresses that answer, as numbers.
Behavior
The status dot shows whether the device answers. A transfer that fails sends nothing, and the next message tries again.
Errors
- Nothing answers at the address. The dot shows disconnected,
no reply at 0x29 on I2C bus 0, and the message is dropped. Forscan,I2C bus 0 not responding. - A payload that can't be written, such as a bool or a number over 255. The dot shows error with the reason, and the message is dropped.
- No address, for
readorwrite. The first message fails with a[NODE_ERROR]:i2c: set the device address (7-bit, e.g. 0x29). - No bus, a bus without pins, or an address or register out of range. Deploy stops and says which.