Make Simulink model work with hardware using Waijung 2


This application will allow you to understand how the simple model is uploaded in to the hardware of user's preference. As the introductory sample the blink LED example is explained here,

  • Understand the fundamental steps in creating a model & Uploading.
  • Understanding the fundamentals of Simulink
  • How to blink an LED using ESP32 Devkit

Required hardware

  1. ESP-WROOM-32
  2. LED
  3. Resistor: 220 ohm

Required software

  1. Matlab
  2. Simulink

Connect the hardware

Note : No need to setup the following hardware configuration, if the ESP32 module has onboard LED which is connected to the GPIO2.

Connect the hardware in the following order. Connect an LED to digital pin 2 of your ESP32 through 1k ohm.

How to create a new model

Step 01
Open Matlab . Change the current folder to the directory where you want to create the model. Click Simulink.

Step 02
Click Blank Model. Save the new model in any name you want without space to avoid any errors as '******.slx'

Step 03
Open Library Browser .
  • After Waijung 2 installation the Waijung 2 blockset will be available in the Library Browser. You can use the library browser to import Waijung 2 blocks to your workspace.
  • Step 01
    Click open library button to view the library.
  • Step 02
    Double Click ESP32 Target.
  • Step 03
    Double Click Device Configuration.
  • Step 04
    Select Waijung 2 Target Setup block and press Ctrl + i to add it to the model.

Step 04

Re-arrange the blocks according to the picture by connecting the two blocks . For more details about Building, Simulating and connecting a Simple Simulink Model

Step 05

Change the block configuration parameters as shown in picture by double clicking on each block. Make sure the COM port hardware is connected to the same COM port. Change the ESP32 Flash Size according to the hardware connected, in this example select 4MB. Pin 2 is assigned as the digital output pin for this example in Digital Out blockset. The parameter values are adjusted to get frequency of 1 Hz.

Step 06

Now upload the code. Go to APPS tab and click Embedded Coder. After C CODE tab opens press the drop down menu to UPLOAD the code.


The LED connected to pin5 through 1k ohm resistor will start blinking at 0.5 Hz frequency. The target setup blockset allow you to connect the model with the hardware. The frequency is generated with used of the pulse generator, the digital out blockset allow the signal to be transmited to the LED. In this example the output pin is assigned to GPIO2 in the digital out blockset.

Related Waijung 2 blocks

The following blocks have been used in this model.

  1. Target Setup Block
  2. Digital Output Block

Simulink model

Click to download the HelloWorld.slx model file.

Additional information

In case the user wants to monitor run time serial data, the following options would serve.

Previous: Simulate LED toggle
Next: How to use demo file?

Also available in: PDF HTML TXT