Main Content

scanI2CBus

Scan for I2C peripheral devices connected to controller board

Since R2023a

    Description

    example

    i2cAddress = scanI2CBus(controller) scans for connected I2C peripheral devices on the NI™ USB-845x or Total Phase® Aardvark™ controller specified by controller. It returns a list of the peripheral devices' I2C addresses as a string scalar or an array of string scalars. controller is the controller connection, specified as an aardvark or ni845x object.

    Examples

    collapse all

    Connect to an NI USB-845x controller board and scan it for connected I2C peripheral devices.

    Connect to the NI USB-845x using its serial number. In this example, the NI USB-845x controller board that is connected to the computer has a serial number 01F26E0A.

    controller = ni845x("01F26E0A");

    Make sure that your I2C peripheral devices are physically connected to the controller. Scan for connected I2C peripheral devices. The scanI2CBus function returns a list of the I2C addresses of these peripheral devices.

    i2cAddresses = scanI2CBus(controller)
    i2cAddresses = 
    
      1×2 string array
    
        "0x48"    "0x53"

    In this example, two peripheral devices are connected. You can now create a connection to one or more of them using the device function with one of the listed I2C addresses. Refer to your peripheral device's datasheet to determine its I2C address.

    Version History

    Introduced in R2023a

    See Also

    | |