Main Content

read

Read data from I2C bus

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

Description

example

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.

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

Code Generation Using MATLAB Function Block

  • Use read in a MATLAB® Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.

Version History

Introduced in R2014b