Saleem Sattar
Saleem Sattar

Reputation: 1

Unable to send data (1) from MATLAB to Arduino

I am sending 1 from MATLAB to Arduino. My Arduino code works perfectly when I send 1 from teraterm terminal software. But when I send 1 from MATLAB by using this code arduino TX lite blinks but cannot get the 1 output.

s = serial('COM7','BaudRate',9600);
fopen(s)
fprintf(s,'1');
fclose(s)

Upvotes: 0

Views: 151

Answers (1)

Akshay Sarode
Akshay Sarode

Reputation: 11

Problem with this code is that you are not giving Delay to process the code.

According to my calculation : fopen(string) command needs 0.8754 Seconds of Processing time.

So add 1 second delay, it will work. .. Your Modified Code :

clear all
clc
s=serial('COM7','BaudRate',9600);
fopen(s);
pause(1);
fprintf(s,1);
fclose(s);

Upvotes: 1

Related Questions