Serial communication between matlab and arduino problem
Show older comments
i was trying to connect the arduino uno to matlab using this setupSerial.m file
if true
%%~~~~~~~~~ SERIALPUSH SETUP ~~~~~~~~~ %
function [s,flag] = setupSerial(comPort)
% Initialize the serialpush port communication between Arduino and MATLAB
% The input value is the COMPORT should be changed as per requirement
% We ensure that the arduino is also communicatiing with MATLAB at this
% time. A predefined code on the arduino acknowledges this.
% if setup is complete then the value of setup is returned as 1 else 0
%instrfind
flag = 1;
s = serial(comPort);
set(s,'DataBits', 8 );
set(s,'StopBits', 1 );
set(s,'BaudRate', 9600);
set(s,'Parity', 'none');
fopen(s);
{
a='b';
while (a ~='a')
a=fread(s,1,'uchar');
end
if (a=='a')
disp('serial read');
end
fprintf(s,'%c','a');
mbox = msgbox('Serial Communication setup.'); uiwait(mbox);
}
disp(fscanf(s,'%s'));
end
so when i do this
>> comPort='com4'; [s,flag] = setupSerial(comPort);
I get this error
Error: File: setupSerial.m Line: 17 Column: 2 The expression to the left of the equals sign is not a valid target for an assignment.
the setup arduino code is
if true
void setup()
{
// Initialize the Serial Bus for printing data.
Serial.begin(9600);
Serial.println('a');
char a = 'b' ;
while(a != 'a')
{
a=Serial.read();
}
// Initialize the 'Wire' class for the I2C-bus.
Wire.begin();
// Clear the 'sleep' bit to start the sensor.
MPU9150_writeSensor(MPU9150_PWR_MGMT_1, 0);
MPU9150_setupCompass();
}
end
Can anyone tell me what is the problem plz?
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!