Вы находитесь на странице: 1из 9

7/30/13

Simulink Target for Arduino | ERF

Simulink Target for Arduino


Programming Arduino using MATLAB/Simulink

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software Simulink is a block diagram environment for multidomain simulation and Model-Based Design. It supports system-level design, simulation, automatic code generation, and continuous test and verification of embedded systems.

This tutorial explains step by step procedure to configure MATLAB/Simulink to program Arduino Uno/Mega Requirements: 1. A Laptop (Windows OS recommended) with MATLAB 2012a/2012b Note: Lower version of MATLAB does not support Targets for Arduino. Linux and OS X are not recommended. 1. Arduino Uno or Arduino Mega Note: No other Arduino board is supported by this method. However Uno/Mega clones such as InduinoX can be used. Step 1: Configuring Simulink: Open MATLAB window and on the command window type targetinstaller.If you are in Simulink window select Tools Run on Target Hardware Install/Update support package. Doing this will open Target installer window

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

1/9

7/30/13

Simulink Target for Arduino | ERF

Select Internet (recommended) and click Next. On the next screen select Arduino (in action first check box) and press Next. If required you can change the installation folder before going to the next step.

On the next screen you can verify your installation details. Press Install to install the software.

Note for SSN Students: You cannot install this package via SSN wifi network. Even though you configure your MATLAB network proxy to proxy.ssn.net:8080 you will get the following error.

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

2/9

7/30/13

Simulink Target for Arduino | ERF

The reason is that the arduino software (arduino-1.0-windows.zip) is around 90MB and our network download size is limited to 50MB. I tried to install from the folder after downloading the arduino software manually but that doesnt worked. So if you find a solution for this problem please share it. It will be useful to SSNites.

This installation will install the support package for Arduino Uno/Mega 2560 along with the arduino software for windows.

Once your installation is successful you will be getting the follwowing window.

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

3/9

7/30/13

Simulink Target for Arduino | ERF

You can close this window now. If you would like to open the target exmples type demo simulink Target for Use with Arduino in the command window. Step 2: Opening Arduino block library To open the arduino blocks library you may type arduinolib in the command window or open Simulink library browser and click Target for use with Arduino.

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

4/9

7/30/13

Simulink Target for Arduino | ERF

Step 3: Creating a model Let us create a model to blink the blue LED of InduinoX board for one second. The blue LED is connected to the pin 12 of this board. For the purpose of blinking I need to turn on the LED (+5V in Pin 12) for one second and turn off the LED (0V in Pin 12) for one second. To achieve this we can use the pulse generator block of simulink connected to Digital Pin block of arduino block as shown in the figure below.

The Pulse Generator block should be configured for a period of 2 (2 seconds) and a pulse width of 50%. This will create a turn on pulse for one second and off pulse for one second.

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

5/9

7/30/13

Simulink Target for Arduino | ERF

Since our blue LED is connected to the digital pin 12 open Arduino Digital Output block and enter 12 in pin number and press OK.

You can simulate the model and view the result in the scope connected to the Pulse Generator Block. You cannot connect the scope to the Digital output as it is meant for the arduino board.

The result as viewed in the scope is shown below.


www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/ 6/9

7/30/13

Simulink Target for Arduino | ERF

Step 4: Running on Target Hardware If you are using your arduino board for the first time you need to install driver. The procedure for installing the driver is given here. Once you install the driver software succesfully, note down the com port number and then select Tools > Run on Target hardware > Prepare to run in the simulink model window.

This will open the Configuration Parameters window. In the Run on Targets section, select your appropriate hardware (in my case Arduino Uno since InduinoX is a clone of Uno). Set the Host COM port to Manual selection and give the appropriate COM port number noted
www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/ 7/9

7/30/13

Simulink Target for Arduino | ERF

from the device manager window. Once you are done press OK to close the window.

In order to upload and run the model on the hardware select Tools > Run on Target Hardware > Run. Or you can press Incremental Build button on the toolbar.

In a few second the model will be uploaded on the target hardware and the LED must blink now. Note: Once you upload press Incremental Build button, a folder in the name of Your_Model_Name_rtt will be created in your current working directory of MATLAB.
www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/ 8/9

7/30/13

Simulink Target for Arduino | ERF

Note: If you get any error while simulating, stating that the call backs are not found or something, type the following the the command window:

r t w i n t g ts e t u p

Press y and hit enter.

Contributor: Vijayenthiran

ONE THOUGHT ON SIMULINK TARGET FOR ARDUINO

srihari on July 27, 2013 at 11:01 PM said:

cool! B)

www.erfssn.org/tutorials/arduino/simulink-target-for-arduino/

9/9

Вам также может понравиться