read

Read data from I2C bus

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 .

Introduced in R2014b