MATLAB:SEND DATA SERIALLY THROUGH MATLAB

Note:Before proceeding with the code,please note the COM port in your system.The following code will send the data serially through the port.

s=serial('com5');
fopen(s);
fwrite(s,'A');
fclose(s);

To send the data in a particular format,(for example as a string):

total=20;
doi=total;
arduino=serial('COM6','BaudRate',9600); % create serial communication object
fopen(arduino); % initiate arduino communication
pause(2);
fprintf(arduino, '%s', doi); % send answer variable content to arduino
fclose(arduino); %or use BytesAvailableFcn property of serial

Leave a Reply

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