Main Content

write

Write data to an I2C device connected to BBC micro:bit board

Description

example

write(i2cdevObj,dataIn) writes data to the I2C device, specified as a device object.

example

write(i2cdevObj,dataIn,precision) writes data to the I2C device, specified as a device object, based on the data precision.

Examples

collapse all

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')

Input Arguments

collapse all

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 device function.

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.

Data Types: double

Precision of data to be written to the I2C device.

Version History

Introduced in R2017b

See Also

|