How to read multiple sensors through the serial.
Show older comments
Hi guys
I hope you can help me.
I have connected 3 sensors to an Arduino, and I´m sending the data to the serial port simultaniously – no problems so far.
Now I would like Matlab to read the serial and plot 3 graphs, 1 from each sensor.
My problem is, that I dont know how to seperate the serial so each of the 3 dataset is placed in its own variable so I afterwards can make the plots.
This is my code:
obj = serial('COM17'); %creating the object
set(obj,'BaudRate',9600) %setting baudrate
fopen(obj); %open port
set(obj,'terminator','cr') %providing the terminator
pressure1=0; % a variable for y axis
time1=now; % time is in x axis
while 2>1
time2=now;
x=[time1 time2];
pressure2 = fscanf(obj) ;
pressure=[pressure1 pressure2];
datetick('x','HH:MM') %change the axis
pause(0.5);
pressure1=pressure2;
time1=time2;
end
5 Comments
Geoff Hayes
on 11 Apr 2015
raki - does the data from all three sensors go through the same serial port? If so, can you tag the data that each is sending out to that you know which sensor is sending which piece of data?
raki
on 11 Apr 2015
Geoff Hayes
on 11 Apr 2015
Can you tag the data from this sensor? I have no experience with Arduino so can only offer suggestions. Are there alternatives to Serial.println?
raki
on 11 Apr 2015
Geoff Hayes
on 12 Apr 2015
Raki - the error messages seems very clear. regexp is expecting a one-dimensional array of characters and yet it is probably getting something different. Put a breakpoint at this line, run your code, and when the debugger pauses at this line check to see what the IncomingString looks like.
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!