Main Content

aardvark

Total Phase Aardvark Adapter connection

Since R2023a

    Description

    An aardvark object represents a connection to a Total Phase® Aardvark I2C/SPI™ Host Adapter. The Aardvark™ controller can have one or more I2C peripheral devices connected to it. To configure and communicate with a peripheral device on the Aardvark controller, you must first create an aardvark object and then use the device function. You can connect to multiple peripheral devices with a single aardvark object. The aardvark object in MATLAB® always has the I2C controller role and cannot be used in the peripheral role.

    Note

    To use the aardvark interface, you must have the Instrument Control Toolbox™ Support Package for Total Phase Aardvark I2C/SPI Interface installed. For more information, see Install Instrument Control Toolbox Support Package for Total Phase Aardvark I2C/SPI Interface.

    Creation

    Description

    example

    controller = aardvark(serialNumber) creates a connection to the Total Phase Aardvark I2C/SPI Host Adapter specified by the serial number serialNumber. You can find the serial number for your Aardvark controller by calling the aardvarklist function.

    The input serialNumber sets the SerialNumber property.

    controller = aardvark(serialNumber,Name=Value) creates a connection to the Aardvark controller board and sets properties using one or more name-value arguments, where Name is the property name and Value is the corresponding value. Set the EnablePullupResistors and EnableTargetPower properties using name-value arguments as Name1=Value1,...,NameN=ValueN, where Name is the property name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the arguments does not matter.

    example

    controller = aardvark, without arguments, attempts to create a connection to the last successfully connected Aardvark controller board. If you have not previously connected to an Aardvark controller, using this syntax creates a connection to the first available controller in the aardvarklist output.

    Properties

    expand all

    This property is read-only.

    Controller board model, specified as Total Phase Aardvark.

    Example: controller.Model returns the model Total Phase Aardvark.

    Data Types: string

    This property is read-only.

    Unique numeric identifier of the Total Phase Aardvark controller board, specified as a string scalar. This property can be set only at object creation.

    Example: controller.SerialNumber returns the unique identifier of the Aardvark controller.

    Data Types: string

    Since R2024a

    Label for identifying connection, specified as a string. Use Tag to apply a label to a connection that you can use later to access the connection using aardvarkfind. Doing so can be useful when you open a connection in one function and use a different function to perform operations on the connection. It is also useful for locating and accessing connections in app callbacks.

    Example: controller.Tag = "pSupply"

    Data Types: string

    This property is read-only.

    Digital pins available on Aardvark controller, specified as a string array. Connect your I2C peripheral devices to the controller using these pins. Refer to the Aardvark documentation for a description of each pin. Configure and communicate with these pins using configureDigitalPin, readDigitalPin, and writeDigitalPin.

    Example: controller.AvailableDigitalPins returns the digital pins of the Aardvark controller.

    Data Types: string

    This property is read-only.

    Voltage level of pins in volts, specified as 3.3. This is the only possible voltage level of the pins on the Aardvark controller.

    Example: controller.VoltageLevel returns the voltage level of the Aardvark pins.

    Data Types: double

    Setting to enable or disable internal pullup resistors for I2C lines, specified as a numeric or logical 1 (true) or 0 (false). Each I2C line (SCL and SDA) has a 2.2 kΩ resistor. When enabled, they are pulled up to 3.3 V, resulting in approximately 1.5 mA of pullup current.

    Example: controller.EnablePullupResistors = false disables internal pullup resistors.

    Data Types: logical

    Setting to allow target power on pins 4 and 6 of the Aardvark controller, specified as a numeric or logical 1 (true) or 0 (false).

    Example: controller.EnableTargetPower = false disables target power on pins 4 and 6.

    Data Types: logical

    This property is read-only.

    Modes of digital pins of Aardvark controller, specified as a table. The table has the columns Pin and Mode. Pin lists the digital pins specified by AvailableDigitalPins and Mode lists the pin mode of each of these pins as input or output.

    When you create an aardvark object, all the pins are input by default. Change pin modes using configureDigitalPin. You can read logic values from input pins using readDigitalPin and send logic level values to output pins using writeDigitalPin.

    Example: controller.DigitalPinModes returns a table with the pin modes of the digital pins on the Aardvark controller.

    Data Types: table

    Object Functions

    configureDigitalPinSet digital pin mode on controller
    readDigitalPinRead logic level value of digital pin on controller
    writeDigitalPinWrite logic level value to digital pin on controller
    scanI2CBusScan for I2C peripheral devices connected to controller board

    Examples

    collapse all

    Discover and connect to a Total Phase Aardvark I2C/SPI Host Adapter controller board on your machine.

    Use aardvarklist to list all available Total Phase Aardvark I2C/SPI Host Adapter controller boards connected to your machine.

    list = aardvarklist
    list = 
    
      1×2 table
    
                     Model             SerialNumber
             ______________________    ____________
    
        1    "Total Phase Aardvark"    "2239143731" 
    
    

    Use the value of SerialNumber to create a connection to your Aardvark.

    controller = aardvark(list.SerialNumber(1))
    controller = 
    
      Aardvark with properties:
    
                       Model: "Total Phase Aardvark"
                SerialNumber: "2239143731"
        AvailableDigitalPins: ["Pin1"    "Pin3"    "Pin5"    "Pin7"    "Pin8"    "Pin9"]
    
    

    You can now connect to any I2C peripheral devices on the Aardvark controller by using the device function.

    Connect to a Total Phase Aardvark I2C/SPI Host Adapter and configure the pins on it.

    Connect to the Total Phase Aardvark using its serial number. In this example, the Aardvark controller board that is connected to the computer has a serial number 2239143731.

    controller = aardvark("2239143731");

    View the available digital pins on the controller and their respective pin modes by using the DigitalPinModes property.

    controller.DigitalPinModes
    ans =
    
      6×2 table
    
         Pin       Mode  
        ______    _______
    
        "Pin1"    "input"
        "Pin3"    "input"
        "Pin5"    "input"
        "Pin7"    "input"
        "Pin8"    "input"
        "Pin9"    "input"
    

    Configure pin 5 as output.

    configureDigitalPin(controller,"Pin5","output")

    Since pin 5 is an output pin, you can now send it a logic high level using writeDigitalPin.

    Connect to a Total Phase Aardvark I2C/SPI Host Adapter and scan for I2C peripheral devices connected to it.

    Connect to the Total Phase Aardvark using its serial number. In this example, the Aardvark controller board that is connected to the computer has a serial number 2239143731.

    controller = aardvark("2239143731");

    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
    
        "0x38"    "0x50"

    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.

    When you use aardvark in a script or at the MATLAB command line, the result is a connection to an Aardvark controller, represented by an object in the MATLAB workspace.

    a1 = aardvark("2239143731")
    a1 = 
    
      Aardvark with properties:
    
                       Model: "Total Phase Aardvark"
                SerialNumber: "2239143731"
                         Tag: "" 
        AvailableDigitalPins: ["Pin1"    "Pin3"    "Pin5"    "Pin7"    "Pin8"    "Pin9"]
    

    When no references to the same connection exist in other variables, you can disconnect the controller by clearing the workspace variable.

    clear(a1)

    Use aardvarkfind to confirm that the connection is closed.

    aardvarkfind
    ans =
    
         []

    When you have an aardvark connection that exists in the MATLAB workspace or is saved as a class property or app property, the aardvark object might not be accessible in a different function or app callback. In this case, you can use aardvarkfind to find and delete the connection.

    A = aardvarkfind
    A = 
    
      Aardvark with properties:
    
                       Model: "Total Phase Aardvark"
                SerialNumber: "2239143731"
                         Tag: ""
        AvailableDigitalPins: ["Pin1"    "Pin3"    "Pin5"    "Pin7"    "Pin8"    "Pin9"]
    

    To close this connection, delete A.

    delete(A)

    This command deletes the aardvark object and disconnects the device. If you subsequently want to reconnect to the device, you must create a new connection with aardvark.

    After the deletion, calling aardvarkfind confirms that there are no existing connections.

    aardvarkfind
    ans =
    
         []

    Note that the variable A is still present in the workspace, but it is now an invalid handle.

    A
    A = 
    
      handle to deleted Aardvark

    The variable persists after deletion of the interface because aardvark is a handle object. (For more information about this type of object, see Handle Object Behavior.) You can use clear to remove the invalid handle from the workspace.

    clear A

    Version History

    Introduced in R2023a

    expand all