Saturday, June 25, 2016

Serial Communication Using MATLAB

As everyone knows that MATLAB is a very powerful tool for data analysis and processing, it also supports various data acquisition techniques one of which is Serial Port Communication, one can acquire data and send data over this port using MATLAB. Electronics and Electrical Engineers are much more familiar with Serial Port and its importance in their day to day task.

In this tutorial i will show a simple demonstration in which we send and receive data using MATLAB and Serial Port Terminal.

I am using Virtual serial port software (Elitma Virtual Serial Port) for connecting two communication with each other, by doing this we can open two ports on PC itself and test our application.
In this video, one port is opened in MATLAB and another connected port is opened in Labcenter Electronics Proteus Software.

This video illustrate the whole thing, have a look at this.



Steps to follow for using Serial Port Communication:-
  • Create a Serial Port Objects = serial('COM1','BaudRate',9600);
  • Open the serial port for Communication
    fopen(s)
  • Send some Characters over Serial Portfprintf(s,'Embedded Laboratory');
  • Receive some character from Serial Port
    fgets(s)
  • Close the serial port
    flcose(s)
  • Delete the serial port
    delete(s)
A Simple Program to send a string on Serial Port COM2 at a baud rate of 2400:

 %Create Serial Port Object  
 s = serial('COM2','BaudRate',2400,'Terminator','CR');  
 fopen(s)  
 fprintf(s,'Embedded Laboratory Serial Communication Tutorial');  
 msg = fgets(s);  %get data from serial port  
 fclose(s)  
 delete(s)  



Update:
New Video Updated on Serial Communication Using MATLAB, is as follow, this video explores few other API's MATLAB has for Serial Communication.



For other MATLAB based posts and projects click here.

2 comments:

  1. Nice tutorial, I want to connect my Arduino with an ehealth shield to Matlab to process data from health sensors is the process the same

    ReplyDelete
    Replies
    1. Yes the process is same and you can use the same approach to get data of your sensor in MATLAB.
      Also watch this video

      https://youtu.be/2RNB_BRDprg

      This will help you further.

      Delete