主要内容

read

Read from I2C device connected to NVIDIA Jetson board

Since R2026a

Description

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

data = read(i2cObj) returns a single uint8 value from the I2C device represented by i2cObj.

data = read(i2cObj,count) reads the number of uint8 values specified by count from the I2C device.

example

data = read(i2cObj,count,dataPrecision) reads the value as the data type dataPrecision.

example

Examples

collapse all

Create a jetson object namedhwObj. Use the scanI2CBus function to scan the I2C buses on the Jetson™ board. In this example, the Jetson board has two I2C buses, i2c-1 and i2c-8. Each bus has a device at address 0x74.

hwObj = jetson;
addresses = scanI2CBus(hwObj);
Devices on i2c-1: 74.
Devices on i2c-8: 74.

Create an i2cdev object, i2cObj, connecting to the device on the i2c-1 bus.

i2cObj = i2cdev(hwObj,"i2c-1",0x74);
Connected to device at address 116 on bus i2c-1.

Read 9 elements from the I2C device. By default, the read function reads the elements as the uint8 data type.

out2 = read(i2cObj,9)
out2 =

  1×9 uint8 row vector

    0    0    0    0    0    0    0    0   89

Read 5 elements from the I2C device. Specify the dataPrecision as "uint32" to read the data as the uint32 data type.

out2 = read(i2cObj,5,"uint32")
out2 =

  1×5 uint32 row vector

    0    0   89    0    0

Input Arguments

collapse all

Connection to the I2C device, specified as an i2cdev object.

Number of elements to read from the I2C device, specified as a positive integer.

Data type, specified as "uint8", "int8", "uint16", "int16", "uint32", "int32", "uint64", or "int64".

Output Arguments

collapse all

Data read from I2C device, returned as a scalar or vector. The count argument determines the length of the output data, and the dataPrecision argument determines the data type of the output data.

Version History

Introduced in R2026a

See Also

Objects

Functions