MATLAB Answers

Kazi
0

Can't connect MATLAB 2016 to Arduino using arduino() function ??

Asked by Kazi
on 28 May 2016
Latest activity Edited by Walter Roberson
on 31 May 2016

Hi,

I am working on a servo motor that's gonna receive an angle value from matlab. Previously we were using arduino ide but there were problems in creating an arduino serial communication. Then we began using serial communication with arduino built-in function in matlab 2016.

But problem did not go away. Even a few minutes ago, the servo was doing the job. Then when we ran the program again, this popped up, again,

" Failed to open serial port COM5 to communicate with board Mega2560. Make sure there is no other MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware Troubleshooting."

This has been really frasustrating ! Please guyz, anyone have any idea what went wrong here or how to solve it ??

Thanks in advance.

a=arduino();
s=servo(a,'D9');
angle=30/180;
writePosition(s,angle);

  0 Comments

Log in to comment.

1 Answer

Answer by Walter Roberson
on 28 May 2016
 Accepted Answer

You have an existing arduino object. The single easiest way to make certain it is gone is to restart MATLAB.

  1 Comment

Thanks Walter, that worked. All I had to do was write these two in the beginning of the code

clear a
clear s

That's it !

Log in to comment.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!