Encounter this error when i tried to connect my arduino board with my matlab: Unable to create a communication link with the serial port. Please check the input argument PORT and verify that a device is connected.
Can anyone solve this?

댓글 수: 13

Juan Israel García Celedón
Juan Israel García Celedón 2021년 11월 28일
편집: Walter Roberson 2021년 11월 28일
My code:
a = arduino;
in_cero = 0;
in_hombro = 130;
in_brazo = 180;
in_mano1 = 90;
s_cuerpo = servo(a,'D2');
writePosition(s_cuerpo,(in_cero/180));
s_hombro = servo(a,'D3');
writePosition(s_hombro, in_hombro/180);
s_brazo = servo(a,'D4');
writePosition(s_brazo,in_brazo/180);
s_alabeo = servo(a,'D5');
writePosition(s_alabeo,in_mano1/180);
s_elevacion = servo(a,'D6');
writePosition(s_elevacion,in_cero/180);
s_cabeceo = servo(a,'D7');
writePosition(s_cabeceo, in_cero/180);
s_pinza = servo(a,'D8');
writePosition(s_pinza, in_cero/180);
Have you used
arduinosetup
Yes, I have
Walter Roberson
Walter Roberson 2021년 11월 28일
Which port did arduinosetup identify for use with your installed device? Have you tried hardcoding that port name in the arduino() call ?
Also, are you using Windows, or are you using Mac or Linux ?
Which port did arduinosetup identify for use with your installed device?
It is the COM4 port.
Have you tried hardcoding that port name in the arduino() call ?
Yes, I have, and Matlab showed me the same message. Just to be sure, it is like this: a = arduino('COM4','Mega2560');
Also, are you using Windows, or are you using Mac or Linux ?
I'm usign Windows
If arduinosetup was able to communicate with the port, but MATLAB is not able to communicate, then I do not know what is going on -- other than the possibility that the port is already in use ?
freeports = serialportlist("available")
freeports = "/dev/ttyS0"
It seems like it is available.
Walter Roberson
Walter Roberson 2021년 11월 30일
Sorry, the only other possibility is that coming to mind is the possibility of mismatch on baud rate, if the arduino has somehow been configured to an unusual rate... but then I would expect problems with the configuration process.
I configured the arduino with a different rate one month ago. I changed because when I wanted to use "arduinosetup" Matlab was giving me an error. Do you want me to show you the rate I changed it for?
Walter Roberson
Walter Roberson 2021년 11월 30일
Try using 'BaudRate' when you arduino()
How do I do that?
a = arduino('COM4', 'Mega2560', 'BaudRate', 38400);
or whatever baud rate you had set the arduino to. Try 9600, 38400, 19200
Well, that didn't work :/

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by