Contenu principal

Register Custom Arduino Library

R2026b

To register your custom Arduino® library, add the working folder that contains it to the MATLAB® path. If you are using arduinoio.customLibrary.createLibraryTemplate to create the library template, you do not need to resister the library.

addpath ('C:\Work');

MATLAB Current Folder browser showing the folder structure: Work > +arduinoioaddons > +LCDAddonFolder > src > LCDAddon.h, with LCDAddon.m at the +LCDAddonFolder level.

The files are now listed in the MATLAB Current Folder browser. Make sure that your custom Arduino library is available. Use listArduinoLibraries to check if the custom Arduino library is available. For example, the available custom Arduino libraries in the Enable Support for LCD Using Custom Arduino Library are as follows.

listArduinoLibraries
ans =

    'Adafruit/MotorShieldV2'
    'I2C'
    'LCDAddonFolder/LCDAddon'
    'SPI'
    'Servo'

You can now write your MATLAB code by incorporating the new custom Arduino library.

Create an arduino object, include the new custom Arduino library, and set ForceBuildOn to true to reprogram the board. Arduino devices reuse cached code if the specified library matches a library name in the source code. Reprogramming forces the device to download the latest header file. For example, in the Enable Support for LCD Using Custom Arduino Library, create an arduino object by including the custom Arduino library.

a = arduino('com5','uno','Libraries','LCDAddonFolder/LCDAddon,'ForceBuildOn',true);
a =

  arduino with properties:

                    Port: 'COM5'
                   Board: 'Uno'
           AvailablePins: {'D2-D13', 'A0-A5'}
    AvailableDigitalPins: {'D2-D13', 'A0-A5'}
        AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'}
     AvailableAnalogPins: {'A0-A5'}
      AvailableI2CBusIDs: [0]
             Libraries: {'LCDAddonFolder/LCDAddon}

Create an add-on object by specifying the custom Arduino library and other arguments based on your requirements.

For example, in the Enable Support for LCD Using Custom Arduino Library, create an LCD add-on object by specifying the custom Arduino library and the pins configured on the Arduino device.

lcd = addon(a,'LCDAddonFolder/LCDAddon','RegisterSelectPin','D7','EnablePin','D6','DataPins',{'D5','D4','D3','D2'});

You can write the relevant commands based on your requirement and then run your MATLAB code.

See Also

| |

Topics