write
Write data to I2C bus
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
Examples
Write Data to an I2C device on Arduino Hardware
Create a connection to an I2C device on Arduino hardware.
a = arduino('COM9','Uno','Libraries','I2C');
Updating server code on board Uno (COM9). This may take a few minutes.
Use an address to create the I2C device connection.
dev = device(a,'I2CAddress','0x55');
Write data to the I2C device.
dataIn = [0 1 2 3 4 5]; write(dev,dataIn);
Specify Precision to Write Data to an I2C Device on Arduino Hardware
Create a connection to an I2C device on Arduino hardware.
a = arduino('COM9','Uno','Libraries','I2C');
Use an address to create the I2C device connection.
dev = device(a,'I2CAddress','0x55');
Write data to the I2C device with the precision of uint16.
dataIn = [0 500];
write(dev,dataIn,'uint16');
Input Arguments
dev
— I2C device connection
device object
I2C device connection specified as a device
object.
dataIn
— Data to write to I2C device
scalar | vector
Data to write to the I2C device, specified as a scalar, vector, hexadecimal or binary. The
range of the values in the array is based on the precision
.
precision
— Data precision
'uint8'
(default) | 'int8'
| 'uint16'
| 'int16'
| 'uint32'
| 'int32'
| 'uint64'
| 'int64'
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
Code Generation Using MATLAB Function Block
Use
write
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 theprecision
. ThedataIn
values will be saturated when it goes beyond the range of the specifiedprecision
.
Version History
Introduced in R2014b
MATLAB Command
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.
Select a Web Site
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)