Main Content

writeRegister

Write data to I2C device register

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

example

writeRegister(dev,register,dataIn) writes data to the I2C device register.

example

writeRegister(dev,register,dataIn,precision) also specifies the data precision.

Examples

collapse all

Create an Arduino object and attach an I2C device object to it.

a = arduino('COM9','Uno','Libraries','I2C');

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55');

Write value 10 to the I2C device register at address 20.

writeRegister(dev,20,10);

Create an Arduino object and attach an I2C device object to it.

a = arduino('COM9','Uno','Libraries','I2C');

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55');

Write value 10 to the I2C device register at address 20 with the precision of uint16.

writeRegister(dev,20,10,'uint16');

Input Arguments

collapse all

I2C device connection, specified as a device object.

Address of the I2C device register, specified as a scalar integer from 0 through 255, hexadecimal, or binary.

Data to write, specified as a scalar, vector, hexadecimal, or binary. The range of the values in the array is based on the precision.

Data precision, specified as one of the following character vectors:

  • 'uint8'

  • 'int8'

  • 'uint16'

  • 'int16'

  • 'uint32'

  • 'int32'

  • 'uint64'

  • 'int64'

Data can be also be specified in the following formats:

  • hexadecimal

  • binary

  • char

  • string

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use writeRegister in a MATLAB® Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.

  • Values of dataIn is not validated against the precision. The dataIn values will be saturated when it goes beyond the range of the specified precision.

Version History

Introduced in R2014b