Communicate with Hardware Using Connected IO
You can use Connected IO to communicate with the IO peripherals on the hardware.
Normal mode simulation with Connected 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 hardware. Connected IO enables you to modify your model design and monitor the effect of the modified design using 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 interaction between Simulink (software) and Android™ device (hardware) is possible in Normal mode simulation only when you enable Connected IO.
These sections explain:
Android Blocks Supporting Connected IO
Use Connected IO with the following sensor blocks from the Simulink Support Package for Android Devices. Without Connected IO, these sensor blocks output zero during Normal mode simulation. With Connected IO, these blocks read data from the connected sensors during Normal mode simulation.
How Connected IO Works
Connected 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 the peripheral functions. The transport layer formats and transmits the data using the communication interface.
This diagram shows the connection that the Connected IO creates between your computer and the hardware.
Communication in Connected IO
When you simulate a Simulink model with Connected IO:
The device driver block (for example, Accelerometer block) in the model request sensor data from the IO Server.
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.
For data acquisition applications, IO Server can be pre-configured to send data at a specific rate. For more information, see Data Acquisition using Connected IO (Simulink Support Package for Arduino Hardware).
If necessary, you can modify the design by adding, removing, or replacing any block in the Simulink model.
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.
The communication in polling Connected IO is an on-demand process. The device driver blocks (for example, Digital Input (Simulink Support Package for Arduino Hardware) and Digital Output (Simulink Support Package for Arduino Hardware) blocks) in the model request peripheral data from the IO Server. The IO Server accepts the request and responds with the requested data. The hardware sends data only when it receives a data request from the Simulink model. In this mode, you can use any number of blocks as required in the model.
Consider the case where data needs to be read from a device connected to the target hardware via I2C, the below diagram shows the interaction between the target and Computer in the Polling mode.
Streaming mode is used to get higher data acquisition rates for sensor/source blocks. In this mode, the Simulink pre-configures the IO Server on target to process a particular command at the sample rate specified on the block. After the configuration, data is transmitted from the target hardware proactively at the specified rate without additional commands to the target.
Response time for getting data from hardware with streaming is less compared to polling, which allows data acquisitions at high rates.
Streaming requires configuration for each block on the target. Every configuration books memory on the hardware. So, you can use this mode only with a limited number of blocks.
Only the source blocks (For example Analog Input (Simulink Support Package for Arduino Hardware), Digital Input (Simulink Support Package for Arduino Hardware), I2C Read (Simulink Support Package for Arduino Hardware)) can stream data. The sink blocks (for example, Digital Output (Simulink Support Package for Arduino Hardware), I2C Write (Simulink Support Package for Arduino Hardware)) works in Polling mode.
Consider the case where data needs to be read from a device connected to the target hardware via I2C at Sample time 10ms, the below diagram shows the interaction between the target and Computer in the Streaming mode.
Connected IO in Model-Based Design
When you simulate a model without Connected 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. Connected 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:
Create a Simulink model.
Simulate the model in:
Simulation without Connected IO: There is no hardware interaction and no code generation.
Simulation with Connected IO: The model communicates with the hardware. There is no code generation.
External mode (Monitor & Tune): The model is deployed on the hardware and generates code.
Deploy the model to the hardware.
Model-Based Design Workflow
How Connected IO Differs from External Mode
Connected IO and External mode both enable you to communicate with the hardware during simulation. However, you use Connected IO and External mode for different purposes. The table shows the actions that you can perform with each mode.
|Action||External Mode||Connected IO|
|Obtain real-time data||You can obtain real-time data with External mode.||Enable the Simulink Pacing Option to get near real-time data.|
|Timing analysis of real-time data||Timing 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.|
|Time required to start simulation||1-2 minutes||Few seconds|
|Code generation||Code is generated on the hardware.||No code is generated.|
Run Android Simulink Model in Connected IO
Follow these steps to run a Simulink model in connected IO mode:
Open a Simulink model.
On the Modeling tab of the model, select Model Settings.
In the Configuration Parameters dialog box, select Hardware Implementation from the left pane and select the target hardware in the Hardware board parameter.
On the Hardware tab of the model, in the Mode section, select
Connected IOand then click Run with IO.
Additionally, you can change the rate of simulation by enabling
Simulink Pacingas described in Simulation Pacing.
On the Simulation tab of the model, enter the Stop Time and click Run. The SimulinkIOServer Android application is now installed on the Android device.
The SimulinkIOServer application shows the following details:
Name: Displays the name of the network to which the Android device is connected.
IP Address: Displays the IP address of the Android device.
To establish a connection between the Android device and the host computer, ensure that they are connected on the same Wi-Fi® network.
Serial: Displays the serial number of the Android device.
This section displays data only from sensors supported by the connected Android device. For example, if the Android device does not support a humidity sensor, the section displays the message No relative Humidity Support. Data from the supported sensors is displayed in this section during simulation.
While using the Location Sensor into the Simulink model, you will be prompted to set the location permission for obtaining the location information of the Android device. Once you grant the permission, the location data of the device is displayed in Simulink when Connected IO runs. Otherwise, 0 is displayed. The input data obtained from other connected sensors is not affected.
The SimulinkIOServer application closes automatically after the connected IO simulation is complete.