Custom Add-On Library Concepts

An add-on library is a collection of MATLAB® and C++ code that provides a user easy access to features on the Arduino® hardware or attached shields. Without the need to directly program the Arduino hardware work within the MATLAB environment, the exploration and development of projects can proceed at an accelerated rate.

This schematic shows the construction of a custom Arduino add-on library and its relation to the hardware.

The Custom Arduino Libraries provides the abstract matlabshared.addon.LibraryBase class in MATLAB and the C++ librarybase.h library. You create a custom add-on library by extending the MATLAB class and creating a C++ class that includes librarybase.h.

Command Handler

Communication between the Arduino hardware and MATLAB on the host computer operates in a server-client relationship, respectively.

The sendCommand function issues a command, known as a commandID, from the MATLAB on the host computer, which is acting as the client. A server object on the Arduino hardware, created by the ArduinoServer.ino library, receives the command in the Command Handler method in the C++ Header File. A switch statement determines which code segment to execute on the Arduino device. When complete, the Command Handler uses the sendResponseMsg() to return any data and validate that the specified commandID was executed.

Note

Communication between MATLAB on the host computer and the Arduino hardware incurs a 20 ms time delay.

Required Knowledge

To create custom add-on libraries, you should have a working knowledge in the following areas

  • MATLAB classes

  • C++

  • The functionality of your hardware device, and its associated application programming interfaces (APIs)

See Also

|