Create Standalone Applications for Arduino Hardware

This example shows how to create a standalone application by using the LCD add-on library from the MATLAB® Support Package for Arduino® Hardware. You can install and run the generated application on target computers that do not have MATLAB installed.

In this example, you will:

  1. Generate the standalone application with a prewritten function that displays “Hello World!” on an LCD.

  2. Run the application on the target computer that does not have MATLAB installed.

LCD Add-on

To create the LCD add-on, see Create LCD Add-on.

Generate Standalone Application by Using Application Compiler App

Package a prewritten function that displays “Hello World!” on an LCD.

Required Products

These products must be installed on your computer:

  • MATLAB Support Package for Arduino Hardware

  • MATLAB Compiler™

This example uses a function called LCDAddOnExample_deploy.

To create the LCDAddOnExample_deploy standalone application:

  1. Set up the hardware as described in Connect Arduino to LCD.

  2. Add the ExampleLCD/LCDAddon Add-on Library to path.

  3. Save the LCDAddOnExample_deploy function. The function displays 'Hello World!' on the LCD.

    function LCDAddOnExample_deploy()
       a = arduino('COM5','Uno','Libraries','ExampleLCD/LCDAddon','ForceBuildOn',true);
       lcd = addon(a,'ExampleLCD/LCDAddon','RegisterSelectPin','D7','EnablePin','D6','DataPins',{'D5','D4','D3','D2'});
       initializeLCD(lcd);
       printLCD(lcd,'Hello World!');
       clearLCD(lcd);
    end
    

  4. In the Application Compiler project window, in the Main File section on the toolstrip, add the LCDAddOnExample_deploy function as the main file of the MATLAB application that you want to deploy. The Suggested Support Packages section of the app displays MATLAB Support Package for Arduino Hardware.

  5. In the Files required for your application to run section of the app, add ExampleLCD/LCDAddon, the folder in which the LCD add-on library is present.

  6. To generate the packaged application, click Package.

If Create log file is enabled in the Additional runtime settings section of the app before packaging, the log file records display outputs in the log file.

MATLAB Compiler produces an installer that installs the standalone application and all the required dependencies on a target computer.

For more details on the application compiler app, see Create Standalone Application from MATLAB and Manage Support Packages.

Install and Run Standalone Application on Target Computer

To run the generated LCDAddOnExample_deploy application on the target computer:

  1. Download the Arduino 1.8.8 from here.

  2. Extract the files to a location like 'C:\Arduino\arduino-1.8.8'.

  3. Create a portable folder inside Arduino\arduino-1.8.8.

  4. Start the Arduino IDE.

  5. Install SAM boards 1.6.11 and SAMD boards 1.6.20 by navigating to Tools > Board > Boards Manager.

  6. Set up the hardware as described in Connect Arduino to LCD.

  7. Execute the application.

  8. In the Configure Arduino window, select the serial port to which the board is connected. On your Windows®system, to find the serial port, navigate to Start menu > Control Panel > Device Manager > Ports (COM & LPT). To find the serial port on Linux® and Mac systems, see Find Arduino Port on Windows, Mac, and Linux.

  9. Select the name of the board.

  10. Enter the Arduino IDE path and click Submit.

Supported Third-Party Libraries

The third-party library versions listed in the table are supported.

LibraryVersion
Adafruit_Motor_Shield_V2_Library1.0.4
Adafruit_BNO0551.1.8
Adafruit_Sensor1.0.3

If you are using any third-party library with your add-on, install it in this path:

  • Windows and Linux — Arduino IDE path/portable/sketchbook/libraries/

  • Mac — ~/Documents/Arduino/libraries/