I2cDevice¶
Description¶
The I2cDevice object represents a generic I2C device operating on a parent I2cBus object. Data can be written to an I2C slave at address address using write() and read from a I2C slave using read().
› Inherits: | Object |
---|---|
› Inherited by: | I2cEeprom, Ltc2483Adc, Sht3x |
Properties¶
address¶
This property holds the bus address of the I2C device.
› Type: | UnsignedInteger |
---|---|
› Default: | 0 |
› Signal: | addressChanged() |
› Attributes: | Writable |
Methods¶
read(UnsignedInteger bytes)¶
This method reads the specified number of bytes from the I2C slave. Returns an empty buffer if the slave did not respond or an error occurred.
› Returns: | ArrayBuffer |
---|
write(ArrayBuffer data)¶
This method writes the specified bytes to the I2C slave. Returns false
if the slave did not respond (acknowledge) or an error occurred.
› Returns: | Boolean |
---|
Example¶
import InCore.Foundation 2.5
import InCore.IO 2.5
Application {
FtdiI2cBus {
I2cDevice {
id: eeprom
address: 0x50
}
}
ByteArray {
id: eepromCommandBuffer
data: [ 0x80 ]
}
ByteArray {
id: eepromReadBuffer
}
onCompleted: {
eeprom.write(eepromCommandBuffer.arrayBuffer)
eepromReadBuffer.arrayBuffer = eeprom.read(16)
console.log(eepromReadBuffer.hex)
}
}