Read arduino data from matlab with fscanf. I can read data but something's wrong
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having a problem reading Arduino data in Matlab. I have 2 Arduino 1 connected to the computer on SerialCom 4 and 5.
The one on COM4 is connected to the Adafruit PT100/P1000 RTD Sensor w/MAX31865. The one on COM5 is connected to the MLX90614 Temp Sensor.
In Matlab I want to read the data from both sensors, so I wrote this:
arduino1=serial('COM4','BaudRate',115200); % COM4 is the one with the Wire Temp
fopen(arduino1); % initiate arduino communication
arduino2=serial('COM5','BaudRate',9600); % COM5 is the one with Infrared Temp
fopen(arduino2);
t0 = clock;
j=0;
while etime(clock,t0)<=expDuration
j=j+1;
time{j,1} = etime(clock,t0);
tempWire{j,1} = fscanf(arduino1, '%f');
tempInfrared{j,1} = fscanf(arduino2, '%f')
end
The problem is that if I use them individually, then everything works. That is, If I only run:
while etime(clock,t0)<=expDuration
j=j+1;
time{j,1} = etime(clock,t0);
tempInfrared{j,1} = fscanf(arduino2, '%f')
end
then I can see that the value update immediately. If I point the sensor toward the skin, values go up to around 30 degrees. If I point it on Ice, it immediately goes to 0.
But, If I try to collect data from both the sensors, then it looks like the Infrared sensor does not update immediately. The data look quite random.
Does anybody have an idea of what could the problem be? Thank you for your time.
0 Kommentare
Antworten (1)
Tony Mohan Varghese
am 22 Mär. 2018
Try setting the baud rate of both boards the same. And check if you are facing the same issue.
Also look into the readasync command.
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!