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 and Manage Support Packages.
Install and Run Standalone Application on Target Computer
To run the generated LCDAddOnExample_deploy
application on the
target computer:
Download the Arduino 1.8.10 from here.
Extract the files to a location like 'C:\Arduino\arduino-1.8.10'.
Create a portable folder inside Arduino\arduino-1.8.10.
Start the Arduino IDE.
Go to Tools > Board > Boards Manager, and install these cores:
SAM boards 1.6.12 and SAMD boards 1.8.4
Arduino Mbed OS Boards 1.3.2
ESP32 1.0.6 (only if you are using an ESP32 board)
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 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.
Select the name of the board.
Enter the Arduino IDE path and click Submit.
Supported Third-Party Libraries
The third-party library versions listed in the table are supported.
Library | Version |
---|---|
Adafruit_Motor_Shield_V2_Library | 1.0.4 |
MKRMotorCarrier | 1.0.1 |
ACAN2515 | 2.0.2 |
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/