Reading analog signal with Arduino Due and Simulink Part 2 tutorial

In this second part of the tutorial series Reading analog signal with Arduino Due and Simulink, you will learn how to configure Simulink and view the real time analog signal.

This is the second part of the tutorial Reading analog signal with Arduino Due and Simulink. Here we will now configure the Simulink to co-work with Arduino Due. This is required to compile and upload the S-Function generated code into Arduino Due. Then we will setup the simulation run time and simulation mode so that we can view the analog voltage signal on the Time Scope in real time.

To read the first part of tutorial see Reading analog signal with Arduino Due and Simulink Part 1 tutorial.

Step 4: Configure Simulink

The configuration of Simulink requires that you setup simulink to use the Arduino Due as your Target Hardware and also set the com port to be used. To do this go to Simulation then Click on Model Configuration Parameters. See below.

Then choose Hardware Implementation. There choose Arduino Due as your Hardware board. The Device vendor should be automatically set by the Simulink after you click on Apply. Otherwise choose ATMEL as your Device vendor. Next clock on the Hardware board settings and click on the Host-board connection. There set Set host COM port to Manually and write your com port in the COM port number field. Here we are using com port 4. This might be different for your computer. Normally we can choose Set host COM port to automatic but if simulink does not recognize the com port then you set it manually as was done in this tutorial.

Click on Apply and exit this configuration by clicking on OK button.

Now we have to set the run time and simulation mode. On the toolbar you can see the run time field. Set it to inf as shown below. Also set the simulation mode to External also shown below.

Now we are ready to run the simulation.

Step 5: Physical Hardware connection

At this point you should have connected your analog sensor to the A0 pin on the Arduino Due board. In this reading analog signal with Arduino Due and Simulink tutorial we have used 10Kohm potentiometer as our analog sensor. Normally you would connect a analog sensor like LDR or temperature sensor or something like those kind of sensors but potentiometer can be equally be used. By varying the potentiometer we can generate different voltage signal on the A0 analog pin and we can read that into Simulink via S-Function builder.

See the following hardware setup used in this tutorial.

Once you have build your hardware, connect the USB to your computer.

Step 6: Simulation

Now we are ready for simulation. Click on the Simulation Run button on the toolbar. This will initiate a process that build build the simulink model, compile the codes and burn it into Arduino Due ARM Cortex microprocessor.

Once it is done open the Time Scope and change the values in the potentiometer. You should get a graph similar to the one shown below.

As you rotate the potentiometer knob, you will see the voltage sensed by Arduino Due and plotted on the Time Scope. This is all in real time. The graph is showing signal read with 10 bit ADC resolution. And in the next tutorial we will show how to setup the 12-bit ADC resolution to obtain similar analog signal amplitude vs time graph in real time.

 

One Comment

Leave a Reply
  1. I follow the tutorial to get analogRead from arduino uno, however there is no any output show in the scope and in my code generation report shown an error : cannot open source file “Arduino.h” for file: C:\MATLAB\SupportPackages\R2016a\toolbox\target\supportpackages\arduinotarget\scheduler\include\arduinoAVRScheduler.h
    how can I add the source file “Arduino.h” in my model?

Leave a Reply

Your email address will not be published. Required fields are marked *