Contenido principal

i2cdev

R2026b

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.

An i2cdev object represents a connection between an I2C device and an NVIDIA® Jetson™ board. Use I2C device objects to read from and write to the I2C 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.

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

This property is read-only.

I2C bus identifier, represented as a string scalar.

This property is read-only.

I2C device address, represented 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 Jetson board has two I2C buses, i2c-1 and i2c-8. Each bus has a device at address 0x74.

addresses = scanI2CBus(hwObj);
addresses{:}
ans = 

  struct with fields:

        Bus: 'i2c-1'
    Devices: {'74'}


ans = 

  struct with fields:

        Bus: 'i2c-8'
    Devices: {'74'}

Connect to the I2C device on i2c-1 at address 74.

i2cObj = i2cdev(hwObj,"i2c-1",0x74);

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2026a

expand all

See Also

Objects

Functions