write
Description
write(
writes the row or column vector peripheral
,data
)data
to the I2C peripheral device
peripheral
.
write(
writes peripheral
,data
,datatype
)data
in the form specified by datatype
,
regardless of the format in data
.
Examples
Write Data to I2C Peripheral Device on NI USB-845x Controller
Connect to an I2C peripheral device on an NI™ USB-845x controller and write data to it.
Connect to the NI USB-845x using its serial number. In this example, the NI USB-845x controller board that is connected to the computer has the serial
number 01F26E0A
.
controller = ni845x("01F26E0A");
Connect to an I2C peripheral device on the controller board. In this example, the
peripheral has an address of 0x48
.
peripheral = device(controller,I2CAddress="0x48");
Write the values [1,2,3,4,5]
to the I2C peripheral device as
uint8
values.
write(peripheral,1:5)
Input Arguments
peripheral
— I2C peripheral device
device
object
I2C peripheral device, specified as a device
object.
Example: write(peripheral,data)
writes data to the I2C peripheral
device object peripheral
connected to an Aardvark™ or NI USB-845x controller.
data
— Data to write
numeric | character vector | string scalar
Data to write to the I2C peripheral device, specified as a row
(1-by-N
) or column (N
-by-1) vector of numeric
values or as a character vector or string scalar of text. Refer to the peripheral device
documentation or data sheet for more information about the commands or data you can
write to the peripheral device.
Example: write(peripheral,1:5)
writes the values
[1,2,3,4,5]
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| char
| string
datatype
— Size and format of each value
"uint8"
(default) | "int8"
| "uint16"
| "int16"
| "uint32"
| "int32"
| "uint64"
| "int64"
| "single"
| "double"
| "char"
Size and format of each value, specified as a character vector or string.
datatype
determines the number of bytes to write for each value
and the interpretation of those bytes as a MATLAB® data type. For ASCII text, you can specify datatype
as "char"
.
Example: write(peripheral,data,"uint32")
writes the data as
uint32
.
Data Types: char
| string
Version History
Introduced in R2023a
See Also
device
| read
| readRegister
| writeRegister
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)