主要内容

i2cdev

Connection to I2C device on 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.

i2cdev objects represent a connection between an I2C device and an NVIDIA® Jetson™ board. Use I2C device objects to read from and write to the I2C device, or read from and write to specific registers on the device.

Creation

Description

i2cobj = i2cdev(hwObj,bus,deviceAddress) creates an I2C device object for the NVIDIA Jetson hardware, hwObj, from the I2C bus, bus, to the I2C device at the address deviceAddress.

example

i2cobj = i2cdev(hwObj,bus,deviceAddress,forceBus=forceBusOption) connects to an I2C bus that is not listed in the available buses.

Input Arguments

expand all

NVIDIA Jetson connection, specified as a jetson object.

This argument sets the HwHandle property.

I2C bus identifier, specified as a string scalar or character array.

This argument sets the Bus property.

Example: "i2c-1"

Data Types: char | string

I2C device address, specified as a nonnegative integer in the inclusive range 0 to 127, or as a character vector or string scalar that specifies a hexadecimal number starting with 0x.

This argument sets the deviceAddress property.

Example: 45

Example: "0x2D"

Whether to connect to a bus not listed in the AvailableI2CBuses property of the jetson object, specified as a numeric or logical 1 (true) or 0 (false).

Example: i2cdev(hwObj,"i2c-7",45,forceBus=true)

Properties

expand all

NVIDIA Jetson hardware board handle, returned as a jetson object.

I2C bus identifier, returned as a string scalar.

I2C device address, returned as a positive integer.

Object Functions

readRead from I2C device connected to NVIDIA Jetson board
writeWrite to I2C device connected to NVIDIA Jetson board
readRegisterRead register of I2C device connected to NVIDIA Jetson
writeRegisterWrite to register of I2C device connected to NVIDIA Jetson board

Examples

collapse all

Connect to an I2C device connected to an NVIDIA Jetson board.

To connect to the Jetson board, create a jetson object.

hwObj = jetson;

Scan the I2C buses on the hardware board using the scanI2CBus function. The function displays the addresses of the devices on each I2C bus in a hexadecimal format. In this example, the i2c-0 bus has no I2C devices, while i2c-7 has devices at the addresses 2D and 3E.

addresses = scanI2CBus(hwObj);
Devices on i2c-0: .
Devices on i2c-7: 2D, 3E.

Connect to the I2C device on i2c-7 at address 2D.

i2cObj = i2cdev(hwObj,"i2c-7",0x2D);
Connected to device at address 45 on bus i2c-7.

Version History

Introduced in R2026a

See Also

Objects

Functions