Vous êtes sur la page 1sur 4

SIMULINK SUPPORT PACKAGE FOR ARDUINO (also known as Arduino Target)

===============================================================
====
Version 1.2 (R2011b), November 2011

This support package allows you to automatically generate an application


(from a Simulink model) that runs autonomously on an Arduino board. For
more information, see:
http://www.mathworks.com/academia/arduino-software/arduino-simulink.html

Questions and comments may be sent to classroom-resources@mathworks.com

QUICK START
-----------

1. Download and install the Arduino IDE and Driver. Detailed instructions
can be found at http://arduino.cc/en/Guide/HomePage
Ensure that you select the right IDE and Board on the Tools menu.

2. Delete any previous version of Arduino target

3. Unzip arduino.zip to a folder without spaces in its


name, e.g. c:\ArduinoTarget

4. Add the subfolders arduino, demos and blocks to your MATLABPATH, e.g. by
typing the following commands in the MATLAB comand window:

>> cd c:\ArduinoTarget
>> addpath(fullfile(pwd,'arduino'),fullfile(pwd,'blocks'),fullfile(pwd,'demos'))
>> savepath

If the savepath command does not work, you may need to invoke MATLAB in
administrator mode. For more information, see
http://www.mathworks.com/support/solutions/en/data/1-9574H9/

5. Type the following command to refresh Simulink customizations:

>> sl_refresh_customizations

6. Connect your Arduino board to the USB port

7. Set up preferences. These are persistent across MATLAB sessions, so


you don't have to specify them each time you start MATLAB.
a) Specify location of the Arduino IDE

>> arduino.Prefs.setArduinoPath('c:\Program Files\arduino\arduino-0022')

b) Specify Arduino board (Duemilanove, Uno, Mega, etc.)

>> arduino.Prefs.setBoard % see list of board options


>> arduino.Prefs.setBoard('uno') % choose a specific board

c) Find the COM port associated with Arduino

>> comPorts=arduino.Prefs.searchForComPort

If the above command doesn't show any ports, open Windows Device
Manager (http://technet.microsoft.com/en-us/library/cc754081.aspx),
navigate to "Ports (COM & LPT)", and look for ports labeled
"USB Serial Port" or "Arduino"

d) Specify the COM port

>> arduino.Prefs.setComPort('COM9');

8. Open a demo model:

>> demo_arduino_blink

9. Build and deploy the executable by pressing Ctrl+B, or choosing


Tools > Code Generation > Build Model. If the deployment is
successful, you should see the LED connected to PIN 13 blinking
once per second.

DEMO MODELS AND DEVICE DRIVER LIBRARY BLOCKS


--------------------------------------------

The available demo models are briefly described below. More details are
available by opening the models and reading their documentation.

* This model flashes a single LED on the board:

>> demo_arduino_blink

* This model implements the blink challenge described in the LadyAda


Arduino tutorial:
>> demo_arduino_blink_challenge

* This model is a Stateflow implementation of the blink challenge:

>> demo_arduino_blink_challenge_stateflow

* These two models illustrates the use of serial port to communicate


between the Arduino and a host PC.

demo_arduino_serial_communication
demo_arduino_serial_communication_host

a) Open demo_arduino_serial_communication, and deploy to the Arduino


using Ctrl+B

b) Keep the Arduino connected to your PC with the USB cable

c) Open demo_arduino_serial_communication_host. It uses serial I/O


blocks from the Instrument Control Toolbox to communicate with the
Arduino. Ensure that the I/O blocks are configured with the correct
COM port.

d) Start the simulation for demo_arduino_serial_communication_host


(by pressing the "Play" button, or choosing Simulation > Start).

* This model illustrates how to run a non-real-time processor-in-the-loop (PIL)


simulation to verify the behavior of your algorithm on-target and collect
execution time measurements

>> demo_arduino_pil

NOTE: The PIL capability requires R2011b or later.

To open the Arduino library of device driver blocks, type:

>> arduino_lib

PRODUCT REQUIREMENTS
--------------------

Required MathWorks products:


R2011a or later:
* MATLAB
* Simulink
* MATLAB Coder
* Simulink Coder
* Embedded Coder

pre-R2011a:
* MATLAB
* Simulink
* Real-Time Workshop
* Embedded Coder

Note: PIL mode requires R2011b. Regular (non-PIL) deployment


should work in R2010b, R2011a and R2011b.

Recommended MathWorks products:

* Instrument Control Toolbox (required for host-side


Serial Send and Serial Receive blocks)
* Stateflow
* Stateflow Coder (pre-R2011a)

Supported platforms:

* Microsoft Windows 32-bit or 64-bit

Supported Arduino software:

* The supported version of Arduino software is arduino-0022.


However arduino-0018 should work as well.

Supported Arduino Hardware:

* Arduino Uno
* Arduino Duemilanove (ATmega168 or ATmega328p)
* Arduino Mega (ATmega1280)
* Arduino Mega (ATmega2560)

You will also need a USB cable for connection to your PC.

Copyright 2010-2011 The MathWorks, Inc.

Vous aimerez peut-être aussi