Go Down

Topic: Problem in sending data from arduino to matlab (Read 109 times) previous topic - next topic

reihane.at

Hi,

I want to run simple example in arduino  and send data from arduino to matlab for drawing plot,

my arduino code is following:
Code: [Select]
#include <SoftwareSerial.h>

int i=0;
void setup()
{
  Serial.begin(9600);
}
 
void loop()
{
   Serial.println(i);
   i++;
}


and my matlab code is following:
Code: [Select]
arduino=serial('COM4','BaudRate',9600);
fopen(arduino)
x=linspace(1,100);
for i=1:length(x)
    y(i)=instrfind(arduino);
y(i)=fscanf(arduino,'%d');
end
fclose(arduino);
disp('making plot..')
plot(x,y);


But I've faced with error! The following is matlab error:
Code: [Select]
Error using serial/fopen (line 72)
Open failed: Port: COM4 is not available. No ports
are available.
Use INSTRFIND to determine if other instrument
objects are connected to the requested device.

Error in kh (line 2)
fopen(Arduino)


and here is arduino error:
Code: [Select]
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.


My arduino uno (COM4) driver in device manager are installed.
I use matlab 2013a and ŮŽArduino 1.8.1 Genuino


How can I fix this error?

PaulS

Quote
How can I fix this error?
Close whatever app has COM4 tied up.
The art of getting good answers lies in asking good questions.

Go Up