Main Content

arduinoio.customLibrary.createLibraryTemplate

R2026b

Create custom library template

Since R2026b

    Description

    arduinoio.customLibrary.createLibraryTemplate(libraryName) creates a template for developing a custom library for use with the MATLAB® Support Package for Arduino® Hardware. The function generates MATLAB and C++ source file templates that establish communication between MATLAB and Arduino hardware. The generated files provide a starter template that can be extended to implement the required device behavior. Modify the generated MATLAB and C++ files to implement hardware‑specific behavior. For more information about this template, see Generated MATLAB Class and Generated C++ Header File.

    The function stores the generated files in +arduinoioaddons in a folder called +<LibraryName>Folder. You can rename this folder after creation. For more information about the file organization within <LibraryName>Folder, see Generated Folder Structure.

    example

    Examples

    collapse all

    Create a template for a custom library named MyLCD to communicate with an LCD display connected to the Arduino board.

    arduinoio.customLibrary.createLibraryTemplate("MyLCD")

    MATLAB creates a new folder named +LCDFolder that contains templates for the MATLAB and C++ files required for the custom library.

    Connect to an Arduino board and send it the custom library.

    a = arduino("COM5","uno","Libraries","MyLCDFolder/MyLCD");

    MATLAB programs the Arduino board with the generated library and registers the library.

    Connect to the LCD display using the custom library. To do so, create an addon object.

    addonObject = addon(a,"MyLCDFolder/MyLCD");

    To test the connection, call a method defined in the custom library. By default, the generated library template includes a testRead that returns Hello from Arduino from the Arduino.

    addonObject.testRead
    ans = 
    
        'Hello from Arduino'

    You can modify the generated MATLAB and C++ files to implement your own custom functionalities.

    Input Arguments

    collapse all

    Name of custom library, specified as a string or character vector.

    Example: arduinoio.customLibrary.createLibraryTemplate("MyLCD")

    Data Types: string | char

    More About

    collapse all

    Version History

    Introduced in R2026b