Why does my serial communication with Arduino is not working ?

31 visualizaciones (últimos 30 días)
Hugo el 31 de Mzo. de 2023
Respondida: Vinayak Choyyan el 11 de Abr. de 2023
I'm trying to implement a communication from MATLAB to an Arduino Uno using Serial port.
I tried the simplest case I could imagine to test this communication but it still doesn't work.
My arduino code is the following :
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
Basically, when Serial recieves anything, it moves the servo to a random position. I tried it with directly sending something in the serial monitor of Arduino and it works fine.
However, when I try to send anything with MATLAB using the simple following code :
clear s;
s=serial('COM16', 'BAUD', 9600);
The program runs, terminates, but nothing happens with the servo, indicating that nothing was recieved. As this is the simplest case I can imagine to test the communication between the two softwares, I really don't see where the problem comes from.
Thank you in advance for your help with this issue.

Respuestas (1)

Vinayak Choyyan
Vinayak Choyyan el 11 de Abr. de 2023
Hi Hugo,
As per my understanding, you are facing issues when trying to communicate with your Arduino Uno over serial comm. I understand that you have used the Arduino app to confirm that your board is indeed working.
Please ensure the Arduino Uno support packages have been installed. Please refer to this documentation for details steps on how to configure and setup Arduino Uno with MATLAB https://www.mathworks.com/help/supportpkg/arduinoio/index.html.
Alternatively, use the Arduino Explorer App to do the above interactively. A details documentation of the same can be for here https://www.mathworks.com/help/supportpkg/arduinoio/ug/using-arduino-explorer.html.
I hope this resolves the issue you are facing.


Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by