File Exchange Pick of the Week

Our best user submissions

Deploy Auto-Generated C-Code from Simulink to Arduino Development Board 4

Posted by Greg Wolff,

Today's Pick comes to us from guest blogger Greg Wolff.

Greg's pick of the week is Embedded Coder Target for Arduino by MathWorks' Embedded Coder Team.

Did you know that you can quickly implement your design ideas that you simulated in Simulink on a microprocessor? The Arduino Target provides a push-button solution to execute your Simulink algorithm on the Arduino development boards.

I use Arduino hardware and this File Exchange entry to demonstrate C-code generation from Simulink models to many of our customers.

While Doug Eastman wrote and posted the original version, the actual file download is now hosted from our academic section of the MathWorks website.

Special Announcement: MathWorks Virtual Career Fair

The MathWorks Virtual Career Fair is on Thursday November 11th. This event provides you the opportunity to talk directly with Engineers and Hiring Managers at MathWorks.


What Is An Arduino?

Simply stated, an Arduino is an inexpensive, practical, simple hardware development package that includes an Atmel microprocessor. It is often considered a hobbyist's development board, but professionals also use this board to prototype new system hardware designs.

What Features Does the Arduino Target Have?

The Arduino Target has a couple key features that I really like for quickly testing my design ideas in hardware:

Push-Button Approach to Implementation

The Arduino Target structures the generated C-code so that it can be compiled and used on the Arduino development boards. In addition it automates the process of:  generating the C-code, associating the necessary source and header files, compiling the C-code to object code, downloading the object code to the processor.

Interact With Sensors and Actuators with Peripheral Drivers

The Arduino Target provides a few peripheral driver blocks for Simulink that that allow you to specify how the algorithm executing on the processor will interact with sensors and actuators. For example it provides a block for the analog-to-digital converters, and blocks for digital input/output pins.

Start-up Guide in Documentation

When you download the Arduino Target it provides documentation on where to obtain the compiler, how to install the Arduino Target, as well as making the target peripheral blocks available in the Simulink Library Browser.

How Do You Use the Arduino Target?

If you have never generated code before from a Simulink model for a real-time application, there are a few key things to keep in mind:

Use a Fixed-Step Solver

I usually recommend the Discrete version of the fixed-step solver. However if you choose this option, you cannot use Continuous Time blocks in your Simulink model, but you can use Discrete Time blocks.

Set the System Target File to Arduino

  • Select Simulation -> Configuration Parameters ... from the Simulink menu bar.
  • In the configuration parameters dialog, select Real-Time Workshop from the parameter selection tree in the left-hand pane.
  • Next to the System Target File on the right-hand pane, click on Browse. This will open a dialog where you can select available code generation targets.
  • Remember Processor Resources are Limited

    Compared to using your desktop or laptop computer, these microprocessors do not have the same extensive computing power or memory storage capabilities. Embedded software design is a constant balance of desired features against limited processor resources, so you may need to make algorithm design changes in order to properly execute on the Arduino hardware.


    If you would like to leave any comments regarding this post, please click here.

    Get the MATLAB code Published with MATLAB® 7.11


    Comments are closed.

    4 CommentsOldest to Newest

    joshua replied on : 1 of 4

    hi im a beginner to the arduino simulink interface, i would like to know if there are any tutorials that would help me get started with it.

    joshua replied on : 2 of 4

    hi im a beginner to the arduino simulink interface, i would like to know if there are any tutorials and examples that will help me get started with it. thanks.

    cham replied on : 4 of 4

    hi im trying to transmit serial data from arduino to simulink for real time monitoring and control (motor speed). however i found that there is some delay in the display. im using serial receive in control instrument toolbox because i dont really know how to display the data directly using arduino toolbox (serial receive). would you give me some advice on this? thanks in advance