Hauptinhalt

read

R2026b

Read data from I2C bus

Description

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

out = read(dev,numBytes) returns data read from the I2C bus based on the number of bytes.

example

out = read(dev,numBytes,precision) also specifies the data precision.

example

Examples

collapse all

Create an Arduino object and attach an I2C device object to it.

a = arduino();

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55');

Read data from the I2C device.

out = read(dev,1)
out = 
4

Create an Arduino object and attach an I2C device object to it.

a = arduino();

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55');

Read data from the I2C device with the precision of uint16.

out = read(dev,1,'uint16')
out = 
4

Input Arguments

collapse all

I2C device connection, specified as a device object.

Number of bytes of data to read from the I2C device, specified as a scalar.

Data precision, specified as one of the following character vectors:

  • 'uint8'

  • 'int8'

  • 'uint16'

  • 'int16'

  • 'uint32'

  • 'int32'

  • 'uint64'

  • 'int64'

Output Arguments

collapse all

Value of data stored at the I2C device register, returned as a scalar or vector based on the precision.

More About

collapse all

Alternative Functionality

App

Use Arduino Explorer to configure the I2C peripherals and read data from I2C bus. You can use the app in the installed version of MATLAB and MATLAB Online™. For more information, see Connect to I2C Device Using Arduino Explorer App.

Version History

Introduced in R2014b