File Exchange Pick of the Week

Our best user submissions

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

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.

Contents

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.

    Comments

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

    Published with MATLAB® 7.11

    |
    • print

    댓글

    댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.