Matlab 2 Arduino serial communication
2 ビュー (過去 30 日間)
古いコメントを表示
I'm attempting to communicate serially with an Arduino Due while a sketch is already uploaded and running. For debugging purposes, I would like to print results to the terminal screen. I am successful when using the programming port for uploading and terminal communication and the native USB port for communication from Matlab to the Due. However, a conflict occurs when only using the programming port for both tasks. I am pretty certain that the latter is possible as all of the examples on Matlab Answers appear to use only one port (though the use of Arduino is not specified). Therefore, I attempted the same task using a Mega 2560, but got the same conflict. Any insight would be greatly appreciated!
The following is the Matlab script:
s1 = serial('COM24', 'BaudRate', 9600);
fopen(s1);
fwrite(s1, 4);
fclose(s1);
And the following is the Arduino sketch:
byte matlab_var; // for incoming serial data
void setup() {
Serial.begin(9600);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
matlab_var = Serial.read(); // read incoming data
Serial.print("Matlab = ");
Serial.println(matlab_var);
}
}
Lastly, here is the error:
Error using serial/fopen (line 72)
Open failed: Cannot connect to the COM24 port. Possible reasons are another
application is connected to the port or the port does not exist.
2 件のコメント
Walter Roberson
2016 年 7 月 7 日
You do not mention the nature of the "conflict"
I notice that on the MATLAB side you are not reading the output of the Serial.print done by the Arudino
回答 (3 件)
Tugba Kapan
2019 年 3 月 11 日
I am trying to combine 2 arduino in Simulink. But i couldn't do that. How can i do ?
0 件のコメント
Raúl Silvero
2019 年 12 月 7 日
When you running the code in Matlab, do you have the serial monitor of the arduino IDE open? Beacuse I think this is the problem.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Support Package for Arduino Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!