Write data to an I2C device connected to BBC micro:bit board
Create object for an I2C device that is already connected to I2C bus.
microbitObj = microbit('COM3'); scanI2CBus(microbitObj)
ans = 1×2 string array "0xE" "0x1D"
i2cdev1 = device(microbitObj, 'I2CAddress',"0xE");
i2cdev1 = device with properties: Interface: "I2C" I2CAddress: 14 ("0xE") SCLPin: "P19" SDAPin: "P20" BitRate: 100000 (bits/s)
Write data to the I2C device.
dataIn = [0 1 2 3 4 5]; write(i2cdev1, dataIn)
Write data to the I2C device with a precision of uint16.
dataIn = [0 500]; write(i2cdev1, dataIn, 'uint16')
i2cdevObj— I2C device connection
Device connection to an I2C device, specified as a device object, connected to the
I2C bus on the BBC micro:bit board. The I2C device object is created using the
dataIn— Data to be written
Data to be written to the I2C device, specified as a scalar or vector. The range of the values in the array is based on the precision.
precision— Data precision
Precision of data to be written to the I2C device.