How can I run matlab connected to arduino more than once?

6 ビュー (過去 30 日間)
hamzah alamoodi
hamzah alamoodi 2015 年 12 月 20 日
I have a problem with connecting my arduino uno to matlab.. It actually runs perfectly for the first time but when I run it again it says this (Failed to open serial port COM4 to communicate with Arduino board Uno. Make sure there is no other MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware Troubleshooting.
.. I'm using this command to connect: a = arduino('com4','uno') ..
If anyone can help here I would appreciate it ...
  2 件のコメント
Sumit Banerjee
Sumit Banerjee 2016 年 5 月 10 日
You have to delete the object which you have created. For example, if you have this object arduino_board = arduino(port, board, 'Libraries', 'Servo'); then you have to delete this object in the end of the code, i.e. clear arduino_board; all the objects which you have created like this should be cleared.
Test Tester
Test Tester 2016 年 7 月 16 日
And how can you clear e.g. arduino_board ???

サインインしてコメントする。

採用された回答

Esther
Esther 2015 年 12 月 21 日
Are you running the connect command
a = arduino('com4','uno')
a second time while object 'a' still exists in the workspace? You only need to connect once.
  4 件のコメント
hamzah alamoodi
hamzah alamoodi 2015 年 12 月 23 日
Yea global a was the mistake .. thanks

サインインしてコメントする。

その他の回答 (2 件)

Sadi Mohammad Rifat
Sadi Mohammad Rifat 2017 年 6 月 18 日
All you have to write a command "clear all" on the first line of your code . That's it.
  1 件のコメント
Hakki Eren Uzunyayla
Hakki Eren Uzunyayla 2019 年 6 月 17 日
it worked on me. Thank you ver much

サインインしてコメントする。


Sumit Banerjee
Sumit Banerjee 2016 年 5 月 10 日
You have to delete the object which you have created. For example, if you have this object arduino_board = arduino(port, board, 'Libraries', 'Servo'); then you have to delete this object in the end of the code, i.e. clear arduino_board; all the objects which you have created like this should be cleared.

カテゴリ

Help Center および File ExchangeRun on Target Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by