You are on page 1of 20

Integration of Simulink with

Hardware (An Effective


Solution)
Divyesh Harwani

Birla Vishvakarma Mahavidyalaya


Department of Electrical Engineering
Contents
1. Making MathWorks Account ............................................................................................. 1
2. Downloading Hardware Support Packages ........................................................................ 3
3. Installing Hardware Support Package ................................................................................ 5
4. Deploying a Simulink Model in Arduino ......................................................................... 11
5. External Mode .................................................................................................................. 16

i
1. Making MathWorks Account

Step 1: Create MathWorks Account


Go to https://in.MathWorks.com/mwaccount/register
You will see the screen as shown below.

Fill the necessary details and follow the instruction step by step to complete the sign up. And
note down your User id an and Password.

Step 2: Logging In with MathWorks account in MATLAB


Open Matlab. On Top Right of your main window of MATLAB Click on Log In.

1
Once you will click on Log In a pop up will open asking your user Id and Password as shown
below.

Use the User ID and Password that you noted down in step one and hit the Sign in button.
Once you Login Successfully on Top Right Corner your First Name will be displayed instead
of Log In button.

2
2. Downloading Hardware Support Packages

Step 1: Downloading Hardware Support Packages


Open one of the Links given below
1) https://in.MathWorks.com/matlabcentral/fileexchange/40312-simulink-support-
package-for-arduino-hardware
2) https://drive.google.com/open?id=1aXHhyQiOii9JRZDL6jRpRnLDb6wkk579
• If you are using Link 1 you will be asked to Log In to your MathWorks account before
downloading. So make sure you remember your user id and Password of your
MathWorks Account before proceeding.
If you are using Link 1 you will be redirected to the page given below. Hit the download
button to download the support packages.

One file will be downloaded as soon as you hit the download button.

3
If you are using Link 2 you will be redirected to the page shown below.

One file will be downloaded as soon as you hit the download button.
You can either follow the Link 1 or Link 2. Extra Link is provided if you face any
difficulty with the one of the links or if one of the servers may have down time when
you need urgently.
In both the links file named “arduino .mlpkginstall” will be downloaded

4
3. Installing Hardware Support Package
Step 1: Locating downloaded package in MATLAB
Open main window of MATLAB and select Open under the Home Tab

As soon as you will hit the Open button Pop-Up shown below will open

Here pre selected file format is ALL MATLAB Files instead of that select ALL Files from
the drop down menu.

5
Once you select the ALL Files option locate the hardware support package file named
“arduino .mlpkginstall” and press the Open button as shown below.

Step 2: Installing Hardware Support Packages


Once you will click Open you will be redirected to the screen given below. And then click on
I Accept button if you are okay with the Terms & Conditions.

6
Once you click, I Accept button you will be redirected to the screen given below. Hit the Next
button as shown below.

Once you hit Next button Download and Installation process will be started as shown below.
(Downloading and installation process depends on your connection speed it may take up to 30
min)

7
Once download & installation will be completed you will see the screen given below. Then
click Setup Now button as shown below.

Once you click Setup Now button you will see the screen sown below. Connect your Arduino
to your PC with the help of compatible Arduino cable. Then and then only press Next Button

8
Once you will click Next button MATLAB will automatically start detecting your board as
shown below.

And then it will automatically show the board that you have connected as shown below. I have
connected my Arduino mega, so MATLAB has detected it. Once your board is detected press
Next.

9
After pressing Next, you will see the screen shown below. Press Next to test Arduino
connection. Make sure your Arduino board is connected to your PC pressing Next.

Once you press next you will be redirected to the screen shown below. Then press Test
Connection button

Than follow the on screen information to finish the setup.

10
4. Deploying a Simulink Model in Arduino

Before proceeding understand the Arduino pins which are given below.

Here we will only focus on Analog and Digital Pins.


Analog Input: Pins A0 to A5 here is analog input pins. Analog input pins are used to sense
the analog signals like voltage, current etc with the help of a sensor or the appropiate circuit.
Digital Pins : Pins 4 to 13 are Digital Pins. Digital pins can either be used as an input or the
output. As the digital pins only will understand 1 or 0 we can only apply the input which is in
the form of 1 or 0. And from digital pin we will be able to obtain the output that will be in the
form of 1 or 0 for e.g. Pulses.

11
Once you finish setting up your Arduino with MATLAB. Open a new Simulink model and
follow the steps as shown below. Here we will deploy a Simulink model to Arduino to generate
the required pulses.

Step 1:Take a pulse generator.


Step 2:Tap on the blank screen and search Digital output as shown below

Step 3: Than connect pulse generator with digital pin.

12
Step 4:Now go to the Simulation Tab and select Model Configuration
Parameters

Step 5: In Model Configuration Parameters select the Solver Tab and in it


go to the Solver Selection and select Fixed step and hit Apply button.

13
Step 6: Than go to Hardware Implementation Tab and Select the Hardware
Board. And hit OK button.

14
Step: 7 Than go to main window of MATLAB. You will see the main
directory will be C:\Program Files\MATLAB\R2018a\bin
Change that default directory to Any Drive:\Folder (for e.g. E:\Pulse)

Step:8 Now go back to Simulink model and go to Deploy to Hardware option


and select Deploy to Hardware

Once you will hit the deploy to hardware button your model will be deployed in your
board.

15
5. External Mode
For external mode settings are same as we saw in deployment mode. Only difference is that in
external mode whatever the controller pin will read we will be able to see on the scope of the
Simulink.
Steps:

Step 1: Connect the output of your sensor to A4 pin of your controller


Step 2: Follow the steps 4 to 7 of deploy mode.
Step 3: Search for Analog input in the Simulink model. Double click on it
and set the sample time 0. (If you take constant block in your model keep its
sample time 0.001)

16
Step 4: At the output of Analog pin connect a data type converter. Connect
the output of converter to the Scope. Select External Mode in place of Normal
Mode. Now click on Run button and it will run your model in the controller
and whatever the controller will read you will be able to see on your scope.

17
Step 5: Take constants and Gain blocks to calibrate your voltage or current.
And re-run the simulation.

18

You might also like