This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

read

Read data from I2C bus

Syntax

out = read(dev,numBytes)
out = read(dev,numBytes,precision)

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

Copyright 2014 The MathWorks, Inc.,

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

Copyright 2014 The MathWorks, Inc.,

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