2

I'm trying to connect Maltab and Arduino by this code:

arduino=serial('COM7','BaudRate',9600);
fopen(arduino);

But I get this message:

Open failed: Port: COM7 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.

What might be a proper reason?

I have another question which is; How can I save a text file (.txt) from Matlab to Arduino SD card .. ? Wether opening a .txt file in arduino or saving it from Matlab directly to Arduino SD card.

  • 1
    when you open it and after forget to close it (lets say your script crashes) and retry to reopen it will cause these errors. Try force a fclose on serial object. – brtiberio Feb 18 '16 at 19:03
  • I've done this and it still gives the same message. Isn't there any other possible option maybe to add a text file to Arduino SD card or anything else? – Jack Sparrow Feb 18 '16 at 19:37
  • If you use arduino IDE, does it open the port normally? – brtiberio Feb 18 '16 at 20:36
  • Hmmm I currently have no time to order one since I have to finish my project in only 3 days .. You see, I got the results of my algorithm from Matlab in a .txt file, and what's left is to add this .txt file in Arduino SD card in a way or another... my first option was to add it directly from Matlab but the connection seems not quite supportive.. so is there any way to put this text file from my pc to Arduino SD card? Thanks in advance! You'd save my life :) – Jack Sparrow Feb 18 '16 at 20:45
  • Sorry but now you got me confused. You don't actually have an arduino (hardware)? When before I asked if the port opens correctly I was talking about arduino IDE (the software). I suppose a basic SD card reader connected to computer is out of question right? – brtiberio Feb 18 '16 at 21:13
  • Ahh apologies, Yes I have the Arduino hardware and the port works normally from what I see in IDE, however, in Matlab there seems to be a problem, I don't think it is the port neither the Arduino plug-ins in Matlab, this was actually the second option, my first option was to take the text file from my pc and save it in Arduino SD card but I don't think it is possible! – Jack Sparrow Feb 18 '16 at 21:29
  • There is no 'Arduino SD card'. There are only SD cards and Arduino libraries that help you talk with the cards. Now, the text file you wish to write to an SD card, where exactly is it? Is it already on your PC? If so, then transferring it to the SD card using a standard card reader or adapter, like has been suggested already, is all you need to do. Unless there's some other reason why you need the Arduino... – SoreDakeNoKoto Feb 18 '16 at 23:16
  • @JackSparrow aparrently the problem is related to the fact the uno usesatmega16u2 as serial emulator. I managed to make it work in linux by following this link: (http://www.mathworks.com/matlabcentral/newsreader/view_thread/194071). However I do not have any windows pc to test similar approach as refered like here: http://www.mathworks.com/matlabcentral/answers/93708-is-it-possible-to-support-1024-serial-ports-in-win32-systems-in-matlab . Try to test it with your port – brtiberio Feb 18 '16 at 23:26
  • The first step in debugging this is to use the Device Manager (available in Computer Management) to see what ports the PC thinks are there. It will confirm whether or not there is a COM7 at all. Your error message seems to indicate the port does not exist. – SDsolar Nov 11 '16 at 17:34

0 Answers0