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:
Generate the standalone application with a pre-written function that displays “Hello World!” on an LCD.
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:
Set up the hardware as described in Connect Arduino to LCD.
Add the
ExampleLCD/LCDAddon
Add-on Library to path.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
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.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.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:
Download the Arduino CLI 0.33.0 from here.
Operating System Arduino CLI 0.33.0 Windows® arduino-cli_0.33.0_Windows_64bit.zip Mac with Intel® Processor arduino-cli_0.33.0_macOS_64bit.tar.gz Mac with Apple Silicon Processor arduino-cli_0.33.0_macOS_ARM64.tar.gz Linux® arduino-cli_0.33.0_Linux_64bit.tar.gz Extract the files to a location like 'C:\Arduino' for Windows, '~/Documents/Arduino' for Mac and '/home/<userName>/Documents/Arduino' for Linux.
Install these cores using the following commands:
AVR Boards 1.8.3, SAM boards 1.6.12, SAMD boards 1.8.13, and Arduino Mbed OS Boards 1.3.2
Operating System Core Core Version Command to Download the Core Windows AVR Boards 1.8.3 arduino-cli core install arduino:avr@1.8.3
SAM boards 1.6.12 arduino-cli core install arduino:sam@1.6.12
SAMD boards 1.8.13 arduino-cli core install arduino:samd@1.8.13
Arduino Mbed OS Boards 1.3.2 arduino-cli core install arduino:mbed@1.3.2
Mac with Intel or Apple Silicon Processor and Linux AVR Boards 1.8.3 ./arduino-cli core install arduino:avr@1.8.3
SAM boards 1.6.12 ./arduino-cli core install arduino:sam@1.6.12
SAMD boards 1.8.13 ./arduino-cli core install arduino:samd@1.8.13
Arduino Mbed OS Boards 1.3.2 ./arduino-cli core install arduino:mbed@1.3.2
ESP32 2.0.11 (only if you are using an ESP32 board)
Operating System Command to Download the Core Windows arduino-cli config set board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-cli core search esp32
arduino-cli core install esp32:esp32@2.0.11
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
./arduino-cli core search esp32
./arduino-cli core install esp32:esp32@1.0.6
Install these libraries using the following commands:
Operating System Library Command to Install the Libraries Windows Servo 1.1.8
arduino-cli lib install Servo@1.1.8
ACAN2515 2.0.2
arduino-cli lib install ACAN2515@2.0.2
Adafruit Motor Shield V2 Library 1.0.4
arduino-cli lib install "Adafruit Motor Shield V2 Library"@1.0.4
ArduinoBLE 1.2.0
arduino-cli lib install ArduinoBLE@1.2.0
ArduinoMotorCarrier 2.0.0
arduino-cli lib install ArduinoMotorCarrier@2.0.0
MKRMotorCarrier 1.0.1
arduino-cli lib install MKRMotorCarrier@1.0.1
ServoESP32 1.0.3
arduino-cli lib install ServoESP32@1.0.3
WiFi101 0.16.0
arduino-cli lib install WiFi101@0.16.0
WiFiNINA 1.8.8
arduino-cli lib install WiFiNINA@1.8.8
Mac with Intel or Apple Silicon Processor and Linux Servo 1.1.8
./arduino-cli lib install Servo@1.1.8
ACAN2515 2.0.2
./arduino-cli lib install ACAN2515@2.0.2
Adafruit Motor Shield V2 Library 1.0.4
./arduino-cli lib install "Adafruit Motor Shield V2 Library"@1.0.4
ArduinoBLE 1.2.0
./arduino-cli lib install ArduinoBLE@1.2.0
ArduinoMotorCarrier 2.0.0
./arduino-cli lib install ArduinoMotorCarrier@2.0.0
MKRMotorCarrier 1.0.1
./arduino-cli lib install MKRMotorCarrier@1.0.1
ServoESP32 1.0.3
./arduino-cli lib install ServoESP32@1.0.3
WiFi101 0.16.0
./arduino-cli lib install WiFi101@0.16.0
WiFiNINA 1.8.8
./arduino-cli lib install WiFiNINA@1.8.8
Set up the hardware as described in Connect Arduino to LCD.
Execute the application.
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.
Select the name of the board.
Enter the Arduino CLI path as shown in step 2 and click Submit.