Help CenterHelp Center
Write data to I2C device register
writeRegister(dev,register,dataIn)
writeRegister(dev,register,dataIn,precision)
example
writeRegister(dev,register,dataIn)writes data to the I2C device register.
dev
register
dataIn
writeRegister(dev,register,dataIn,precision)also specifies the data precision.
precision
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);
Write value 10 to the I2C device register at address 20 with the precision of uint16.
writeRegister(dev,20,10,'uint16');
I2C device connection, specified as adeviceobject.
device
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 theprecision.
'uint8'
'int8'
'uint16'
'int16'
'uint32'
'int32'
'uint64'
'int64'
Data precision, specified as one of the following character vectors:
Data can be also be specified in the following formats:
hexadecimal
binary
char
string
UsewriteRegisterin a MATLAB®Function block with the万博1manbetx®万博1manbetx支持包Arduino®Hardwareto generate code that can be deployed on Arduino Hardware.
writeRegister
Values ofdataInis not validated against theprecision. ThedataInvalues will be saturated when it goes beyond the range of the specifiedprecision.
readRegister|arduino|write|read
readRegister
arduino
write
read
You have a modified version of this example. Do you want to open this example with your edits?
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office