Hi everyone I'm having lots of trouble sending a value from Matlab to the Arduino Uno through the serial port. I know Matlab is sending the value over and Arduino is receiving it but I don't understand how to get Arduino to read the value. I have tried so many different things and nothing has worked for me I've searched all over the internet but I'm still having trouble.
So my Matlab code below just sends the number 4 to the serial port.
priorPorts = instrfind; % finds any existing Serial Ports in MATLAB
delete(priorPorts); % and deletes them
set(a, 'Timeout', 10);
So I'm confused as to how to get Arduino to read the value. Does Arduino read an integer in its ascii format? Either way no matter what I do Arduino doesn't read the value, if I run the code I have below all I get is "-1" which I think means there's nothing there. I have also tried using Serial.parseInt() also to read an integer but that didn't work. The arduino code below simply reads the serial port and prints what it read but so far I can't get it to read anything.
if (Serial.available()>0) // if there is data to read
matlabData=Serial.read(); //read data
If anyone can help me with this in anyway I would greatly appreciate it. In the end I need Arduino to read the value and be put into a function such as running a motor a certain amount of steps. Thanks for any help in advance