Main Content

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 pre-written 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 pre-written 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 Function (MATLAB Compiler) and Manage Support Packages (MATLAB Compiler).

Install and Run Standalone Application on Target Computer

To run the generated LCDAddOnExample_deploy application on the target computer:

  1. Download the Arduino CLI 0.33.0 from here.

    Operating SystemArduino CLI 0.33.0
    Windows®arduino-cli_0.33.0_Windows_64bit.zip
    Mac with Intel® Processorarduino-cli_0.33.0_macOS_64bit.tar.gz
    Mac with Apple Silicon Processorarduino-cli_0.33.0_macOS_ARM64.tar.gz
    Linux®arduino-cli_0.33.0_Linux_64bit.tar.gz

  2. Extract the files to a location like 'C:\Arduino' for Windows, '~/Documents/Arduino' for Mac and '/home/<userName>/Documents/Arduino' for Linux.

  3. Open the command terminal from the location mentioned in the previous step and execute the following configuration commands:

    Operating SystemConfiguration Commands
    Windows

    arduino-cli config init --overwrite --dest-file arduino-cli.yaml

    arduino-cli config set directories.data data --config-file arduino-cli.yaml

    arduino-cli config set directories.user user --config-file arduino-cli.yaml

    arduino-cli config set directories.downloads downloads --config-file arduino-cli.yaml

    Mac with Intel or Apple Silicon Processor and Linux

    ./arduino-cli config init --overwrite --dest-file arduino-cli.yaml

    ./arduino-cli config set directories.data data --config-file arduino-cli.yaml

    ./arduino-cli config set directories.user user --config-file arduino-cli.yaml

    ./arduino-cli config set directories.downloads downloads --config-file arduino-cli.yaml

  4. Install these cores using the following commands:

    • AVR 1.8.3, SAM 1.6.12, SAMD 1.8.13, Arduino Mbed Nano 4.0.4, and Arduino Renesas 1.0.2

      Operating SystemCoreCore VersionCommands to Install the Core
      WindowsAVR1.8.3

      arduino-cli core install arduino:avr@1.8.3 --config-file arduino-cli.yaml

      SAM1.6.12

      arduino-cli core install arduino:sam@1.6.12 --config-file arduino-cli.yaml

      SAMD1.8.13

      arduino-cli core install arduino:samd@1.8.13 --config-file arduino-cli.yaml

      Arduino Mbed Nano4.0.4

      arduino-cli core install arduino:mbed_nano@4.0.4 --config-file arduino-cli.yaml

      Arduino Renesas1.0.2arduino-cli core install arduino: renesas_uno @1.0.2 --config-file arduino-cli.yaml
      Mac with Intel or Apple Silicon Processor and LinuxAVR1.8.3

      ./arduino-cli core install arduino:avr@1.8.3 --config-file arduino-cli.yaml

      SAM1.6.12

      ./arduino-cli core install arduino:sam@1.6.12 --config-file arduino-cli.yaml

      SAMD1.8.13

      ./arduino-cli core install arduino:samd@1.8.13 --config-file arduino-cli.yaml

      Arduino Mbed Nano 4.0.4

      ./arduino-cli core install arduino:mbed_nano@4.0.4 --config-file arduino-cli.yaml

      Arduino Renesas1.0.2./arduino-cli core install arduino: renesas_uno @1.0.2 --config-file arduino-cli.yaml
    • ESP32 2.0.11 (only if you are using an ESP32 board)

      Operating SystemCommands to Install the Core
      Windows

      arduino-cli config set board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json --config-file arduino-cli.yaml

      arduino-cli core search esp32 --config-file arduino-cli.yaml

      arduino-cli core install esp32:esp32@2.0.11 --config-file arduino-cli.yaml

      Mac with Intel or Apple Silicon Processor and Linux

      ./arduino-cli config set board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json --config-file arduino-cli.yaml

      ./arduino-cli core search esp32 --config-file arduino-cli.yaml

      ./arduino-cli core install esp32:esp32@1.0.6 --config-file arduino-cli.yaml

  5. Install these libraries using the following commands:

    Operating SystemLibraryCommand to Install the Libraries
    Windows

    Servo 1.1.8

    arduino-cli lib install Servo@1.1.8 --config-file arduino-cli.yaml

    ACAN2515 2.0.2

    arduino-cli lib install ACAN2515@2.0.2 --config-file arduino-cli.yaml

    Adafruit Motor Shield V2 Library 1.0.4

    arduino-cli lib install "Adafruit Motor Shield V2 Library"@1.0.4 --config-file arduino-cli.yaml

    ArduinoBLE 1.2.0

    arduino-cli lib install ArduinoBLE@1.2.0 --config-file arduino-cli.yaml

    ArduinoMotorCarrier 2.0.0

    arduino-cli lib install ArduinoMotorCarrier@2.0.0 --config-file arduino-cli.yaml

    MKRMotorCarrier 1.0.1

    arduino-cli lib install MKRMotorCarrier@1.0.1 --config-file arduino-cli.yaml

    ServoESP32 1.0.3

    arduino-cli lib install ServoESP32@1.0.3 --config-file arduino-cli.yaml

    WiFi101 0.16.0

    arduino-cli lib install WiFi101@0.16.0 --config-file arduino-cli.yaml

    WiFiNINA 1.8.8

    arduino-cli lib install WiFiNINA@1.8.8 --config-file arduino-cli.yaml

    Mac with Intel or Apple Silicon Processor and Linux

    Servo 1.1.8

    ./arduino-cli lib install Servo@1.1.8 --config-file arduino-cli.yaml

    ACAN2515 2.0.2

    ./arduino-cli lib install ACAN2515@2.0.2 --config-file arduino-cli.yaml

    Adafruit Motor Shield V2 Library 1.0.4

    ./arduino-cli lib install "Adafruit Motor Shield V2 Library"@1.0.4 --config-file arduino-cli.yaml

    ArduinoBLE 1.2.0

    ./arduino-cli lib install ArduinoBLE@1.2.0 --config-file arduino-cli.yaml

    ArduinoMotorCarrier 2.0.0

    ./arduino-cli lib install ArduinoMotorCarrier@2.0.0 --config-file arduino-cli.yaml

    MKRMotorCarrier 1.0.1

    ./arduino-cli lib install MKRMotorCarrier@1.0.1 --config-file arduino-cli.yaml

    ServoESP32 1.0.3

    ./arduino-cli lib install ServoESP32@1.0.3 --config-file arduino-cli.yaml

    WiFi101 0.16.0

    ./arduino-cli lib install WiFi101@0.16.0 --config-file arduino-cli.yaml

    WiFiNINA 1.8.8

    ./arduino-cli lib install WiFiNINA@1.8.8 --config-file arduino-cli.yaml

  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 Windowssystem, 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 CLI path as shown in step 2 and click Submit.