Communicate with Hardware in Normal Mode Simulation Using Simulink IO

You can use Simulink IO to communicate with the IO peripherals on the hardware during Normal mode simulation.

Normal mode simulation with Simulink IO is an intermediate step in the Model-Based Design workflow that bridges the gap between simulation and code generation by enabling Simulink® to communicate with the hardware before deploying the model on the hardware. Simulink IO enables you to modify your model design and monitor the effect of the modified design using the peripheral data from the hardware in a near real-time environment. You are not required to deploy the model on the hardware to monitor the effect of the modified design, which accelerates the simulation process. This Simulink (software)-Arduino® (hardware) interaction is available in Normal mode simulation only when you enable Simulink IO.

These sections explain:

Supported Arduino Boards and Blocks with Simulink IO

The Simulink IO described here applies to the Simulink Support Package for Arduino Hardware on these Arduino boards and blocks:

  • Source blocks: Without Simulink IO, these source blocks output zero during Normal mode simulation. With Simulink IO, these blocks read data from the peripherals of the hardware during Normal mode simulation.

  • Sink blocks: Without Simulink IO, these sink blocks do not have any role during Normal mode simulation. With Simulink IO, these blocks write data to the peripherals of the hardware during Normal mode simulation.

    Arduino BoardsSource BlocksSink Blocks

    Arduino Due

    Arduino Leonardo

    Arduino MKR1000

    Arduino MKR WIFI 1010

    Arduino Mega 2560

    Arduino Mega-ADK

    Arduino Nano 3.0

    Arduino Uno

    Digital Input

    Analog Input

    I2C Read

    Digital Output

    PWM

    SPI WriteRead

    I2C Write

How Simulink IO Works

Simulink IO creates a communication interface that enables the Simulink model and the IO Server to communicate with each other. The Simulink model resides in your computer, and the IO Server is an engine on the hardware that contains all peripheral functions. The transport layer formats and transmits the data using the communication interface.

This diagram shows the connection that the Simulink IO creates between your computer and the hardware.

Communication in Normal Mode Simulation with Simulink IO

When you simulate a Simulink model in Normal mode with Simulink IO:

  1. The device driver blocks (for example, Digital Input and Digital Output blocks) in the model request peripheral data from the IO Server.

  2. The IO Server accepts the request and responds with the requested data. You can use any Simulink sink or dashboard block to view the received data. Using the peripheral data received, you can verify that your model design meets the requirements.

  3. If necessary, you can modify the design by adding, removing, or replacing any block in the Simulink model.

  4. After the model is modified, resimulate the model. During simulation, the data request from the model is communicated to the hardware. You can continue to modify and simulate the model until the expected behavior is achieved.

Note

  • The communication in Simulink IO is an on-demand process. The hardware sends data only when receiving a data request from the Simulink model.

  • You do not have to build, deploy, and run the model on the hardware to monitor the effects of your changes in your model design.

Simulink IO in Model-Based Design

When you simulate a model in Normal mode without Simulink IO, Simulink does not communicate with the hardware. Simulink communicates with the hardware only when the code is generated and the model is deployed on the hardware in External mode. Normal mode simulation with Simulink IO is an intermediate step in the model-based design workflow that bridges the gap between simulation and code generation by enabling Simulink to communicate with the hardware before deploying the model on the hardware.

This Model-Based Design Workflow diagram displays a model-based workflow:

  1. Create a Simulink model.

  2. Simulate the model in:

    1. Normal mode simulation without Simulink IO: There is no hardware interaction and no code generation.

    2. Normal mode simulation with Simulink IO: The model communicates with the hardware. There is no code generation.

    3. External mode: The model is deployed on the hardware and generates code.

  3. Deploy the model to the hardware.

Model-Based Design Workflow

How Simulink IO Differs from External Mode

Simulink IO and External mode both enable you to communicate with the hardware during simulation. However, you use Simulink IO and External mode for different purposes. The table shows the actions that you can perform with each mode.

ActionExternal ModeSimulink IO
Obtain real-time dataYou can obtain real-time data with External mode.Enable the Simulink Pacing Option (Simulink) to get near real-time data.
Timing analysis of real-time dataTiming analysis of real-time data is possible because the Simulink model is running on the hardware in real-time.Timing analysis of real-time data is not possible because the Simulink model is running in your computer and not on the hardware.
Code generationCode is generated on the hardware.No code is generated.

How to Enable Simulink IO

To simulate a model in Simulink IO during Normal mode simulation, you must enable the Simulink IO option:

  1. Open a Simulink model.

  2. In the Simulink toolbar, set the Simulation mode to Normal.

  3. In the Simulink model, select Simulation > Model Configuration Parameters.

  4. In the Configuration Parameters dialog box, select Hardware Implementation.

  5. Set the Hardware board parameter to any Arduino board listed in the Supported Arduino Boards and Blocks with Simulink IO section. For example, Arduino Mega 2560. This selection automatically populates the parameters in the Hardware board settings with the default values for the Arduino hardware.

  6. From the Groups list under Target hardware resources, select Simulink IO.

  7. Select the Enable Simulink IO option.

  8. Click Apply. Click OK to close the dialog box.

  9. Optionally, you can change the rate of simulation by enabling the Simulink Pacing Option as described in Simulation Pacing (Simulink).

See Also

Related Topics