feki ahmedamine
feki ahmedamine

Reputation: 1

serial communication beteen arduino and MATLAB

I'm currently working on my final year study project , i'm using arduino due and the ultrasonic sensors which are placed on a wheelchair to make an autonomous one.

so my problem is that i'm reading the distances from the sensors and i need to send them tomatlab simulink to use them in the fuzzy logic controller block but i can't because what i'm sending in the serial monitor from ardiuno is something like " #distance1#distance2#...#distance10# " which is a string type,so how can i get the data (distances) using serial port to use them in matlab simulink.

Do i have to change the arduino code or should i use some block in simulink? any response might be helpfull

Upvotes: -1

Views: 529

Answers (1)

Jordan Stewart
Jordan Stewart

Reputation: 3395

You need to parse the input, based on the delimiter, and decide you often you should sample the sensor.

You want your input to be split at the hash. You should use something like:

str = input;    % from arduino buffer
delimiter = "#";
C = strsplit(str,delimiter)
C = int(C)    % type case to an int

You probably should read every 5th signal based on the frequency of the sensor. If the sensor takes 100 measures per second you probably only need 20 to be processed. This looks like:

 C = C[1:5:end]

Maybe...

Processing the signal you might want to use error std from the data sheet of the sensor somewhere. Parse the input probably either before it gets passed into simulink, or as one of the first blocks. It is kind of up to you (I don't know if there is a best practise).

I hope that helped!

The docs for str split is here: http://au.mathworks.com/help/matlab/ref/strsplit.html

Upvotes: 1

Related Questions