Interfacing Proteus and MATLAB-SIMULINK for Co-Simulation

 Here it is shown how you can create interface Proteus and Matlab/Simulink software for prototyping and co-simulation with Arduino based system as an example. In this simple example, we will write simulink program to control a LED connected to Arduino in Proteus. 

Matlab/Simulink has its own feature and capabilities ranging from DSP, antenna design, neural network, communication and many many more while Proteus is basically an electronics circuit simulator with PCB design capabilities. They are both widely used by engineers and others for design  and development of either software and hardware. Combining the features of both of these useful programs one can increase productivity and innovation. So it is quite useful if Proteus and Matlab/Simulink can be interfaced for product development.

MATLAB and Simulink are popular tools for interfacing with Arduino boards. MATLAB provides a suite of functions and toolboxes for communicating with and controlling various types of hardware, including Arduino boards. Simulink, in turn, provides a graphical environment for modeling and simulating dynamic systems, including systems that interact with hardware.

The combination of MATLAB and Simulink with Arduino provides a powerful and flexible platform for a wide range of applications, including control systems, data acquisition and analysis, and rapid prototyping of hardware systems.

There are also toolboxes available for MATLAB and Simulink specifically designed for interfacing with Arduino boards, such as the Arduino Support Package for Simulink. These toolboxes provide a convenient and user-friendly interface for communicating with and controlling Arduino boards, making it easy to incorporate Arduino into your MATLAB and Simulink workflows.

The popularity of MATLAB and Simulink with Arduino is growing, particularly in the areas of educational technology, prototyping, and hobbyist projects. The combination of MATLAB and Simulink's extensive capabilities for modeling, simulation, and data analysis with Arduino's versatility and accessibility as an open-source hardware platform makes this combination a popular choice for a wide range of projects.

Brief Overview

Here we start by creating a simple circuit in Proteus with Arduino and a LED attached to digital pin 9 via a 220Ohm current limiting resistor. Also we connect a RS232 com port component which will be configured as COM2 to the Rx pin 1 of Arduino. Next we write Arduino program to monitor the serial port and receive the data and upload the program into the Arduino. Depending upon the data received we either turn off or turn on the LED. Then we setup a model in Simulink where we send either 1 or 0 using constant block via a manual switch block to serial send block. The serial send block is configured as COM2 port. Finally we use the Virtual Serial Port Emulator(VSPE) program to pair COM1 and COM2 port and start the proteus simulation then run the simulink model. By switching the manual switch in simulink, when 0 is sent the LED will be turned off in proteus and when 1 is sent the LED is turned on. In this way we can interface and co-simulate Arduino and other circuit with simulink. 

See the tutorial Arduino simulation in Proteus with Virtual COM port for setting up Arduino control using serial port with COMPIM RS232 com port part and Virtual Serial Port Emulator(VPSE).

Proteus

Create the following Arduino with LED circuit in Proteus.

Arduino LED circuit in proteus

Configure the COMPIM RS232 com port part as shown in below.

RS232 COM port proteus

 Next use the following Arduino program and compile and upload to the Arduino.

const int LED_PIN = 9;

void setup() {
  pinMode(LED_PIN, OUTPUT); // Set pin 9 as an output for the LED
  Serial.begin(9600); // Start the serial communication
}

void loop() {
  if (Serial.available() > 0) { // Check if there is data available on the serial port
    int data = Serial.read(); // Read the data
		if (data == '1') { // If the data is '1'
		  digitalWrite(LED_PIN, HIGH); // Turn on the LED
		} 
		else if (data == '0') { // If the data is '0'
		  digitalWrite(LED_PIN, LOW); // Turn off the LED
		}
  }
}

The above Arduino code controls an LED (Light Emitting Diode) based on the input received from the serial port of the Arduino board. Here's a step-by-step explanation of the code:

  1. const int LED_PIN = 9; - Define a constant variable LED_PIN with value 9, which is the pin number to which the LED is connected.

  2. void setup() - A standard Arduino function that runs once when the board starts up or is reset. In this function, the following actions are performed: a. pinMode(LED_PIN, OUTPUT); - Set pin 9 (the LED pin) as an output pin using pinMode function. b. Serial.begin(9600); - Start the serial communication with a baud rate of 9600 using Serial.begin function.

  3. void loop() - A standard Arduino function that runs continuously after the setup() function. In this function, the following actions are performed: a. if (Serial.available() > 0) - Check if there is any data available on the serial port using the Serial.available() function. If there is data available, the code inside the if statement is executed. b. int data = Serial.read(); - Read the incoming data from the serial port and store it in the data variable. c. if (data == '1') - If the incoming data is '1', which indicates that the LED should be turned on, execute the following statement: digitalWrite(LED_PIN, HIGH); - Set the LED pin to HIGH, which turns on the LED. d. else if (data == '0') - If the incoming data is '0', which indicates that the LED should be turned off, execute the following statement: digitalWrite(LED_PIN, LOW); - Set the LED pin to LOW, which turns off the LED.

Therefore, the code reads data from the serial port and if it's '1', the LED connected to pin 9 turns on, and if it's '0', the LED turns off. This code can be used to control the LED using a computer or another microcontroller that sends data over the serial port.

Simulink model

Next construct the following simulink model.

simulink model

The two constant blocks are configure as shown below.

constant block

The serial send block is configured as shown below.

serial send block

The serial configuration block is configured as shown below.

serial configuration block

VSPE(Virtual Serial Port Emulator)

The VSPE program is configured as shown below.

VSPE

For learning how to configure virtual serial port emulator program with proteus see the tutorial Serial communication from PC to Proteus.

Co-Simulation

The next step is to start the simulation. First the proteus simulation should start and then the simulink model should be run. Then by changing the switch state to send 1 in simulink model the LED connected to Arduino in Proteus is turned on. Similarly when the switch state is 0 then the LED is turned off.

Video demonstration

The following video shows interfacing of Proteus with Matlab/Simulink and co-simulation of Arduino control of LED.

Summary and Conclusion

In summary, this tutorial explained the interfacing and co-simulation of Proteus and Simulink using Arduino as an example. It highlights the popularity of MATLAB and Simulink with Arduino in control systems, data acquisition, and rapid prototyping of hardware systems. The article provides a step-by-step guide to interface Proteus and Simulink for prototyping and co-simulation with Arduino using a simple example of controlling an LED through a serial port. The process involves creating a simple circuit in Proteus with Arduino, writing an Arduino program to monitor the serial port and upload it into the Arduino, setting up a model in Simulink, and pairing the COM1 and COM2 port using Virtual Serial Port Emulator. The combination of Proteus and Simulink allows engineers to improve productivity and innovation in product development.

In conclusion, below are good tutorial references who are interested in co-simulation of circuits using Proteus and Matlab/Simulink software. The reference[1] shows an alternative method of sending data from Simulink model to Proteus using the Serial Send block. The reference[2] shows how to send data from Proteus to Simulink using the Serial Receive block. The reference[3] highlights the advantages and application of Proteus Matlab/ Simulink cosimulation. In reference[4] shows how to setup the virtual serial port pair for serial communication in Proteus. Those who wish to perform simulation of Arduino alone in Simulink the references [5] and [6] provides the guide to simulation of Arduino in Simulink.

References:

[1] Send data from Simulink to Proteus for Arduino Co-Simulation

[2] Send Arduino data from Proteus to Simulink 

[3] Arduino in Proteus co-simulation with Simulink: Advantages & Applications

[4]  Serial communication from PC to Proteus

[5] Programming Arduino using Matlab/Simulink

[6] How to plot real time data from Arduino in Matlab

Post a Comment

Previous Post Next Post