Plotting data in realtime using SensorDAQ (NI DAQ)
Show older comments
Hi everyone,
I am trying to plot data in real-time, as acquired from a NI card (a little different to usual, as it is a SensorDAQ, but should work the same - http://www.vernier.com/products/interfaces/sdaq/). I have followed the instructions as per the MATLAB documentation (https://uk.mathworks.com/help/daq/examples/acquire-continuous-and-background-data-using-ni-devices.html), but it won't plot in real-time. It just waits until the end of the script and then plots the figure.
addpath('SensorDAQ')
s = sdaq.createSession;
sdaq.addSensor(s,1,sdaq.Sensors.HandDynamometer);
s.Rate = 100;
s.DurationInSeconds = 5;
s.NotifyWhenDataAvailableExceeds = 100;
lh = addlistener(s,'DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
startBackground(s);
s.wait();
delete(lh)
I have also tried alternatives, for example using a nested function with drawnow. But it still doesn't plot anything until the script has finished running. See below:
function test_script()
addpath('SensorDAQ')
s = sdaq.createSession;
sdaq.addSensor(s,1,sdaq.Sensors.HandDynamometer);
s.Rate = 100;
s.DurationInSeconds = 5;
s.NotifyWhenDataAvailableExceeds = 100;
lh = addlistener(s,'DataAvailable', @plotData);
s.startBackground()
wait(s)
delete(lh)
function plotData(src,event)
plot(event.TimeStamps,event.Data)
drawnow
pause(0.1)
end
end
Any ideas? I've tried running this on Matlab 2014a and 2016b.
Accepted Answer
More Answers (4)
Eddy H
on 8 Jun 2017
0 votes
Eddy H
on 9 Jun 2017
Grace Steward
on 3 Aug 2021
0 votes
As of August 3 2021, this problem with the SensorDAQ still exisits. I just got a email from Matlab support saying that they are looking at fixing this issue in future version of Matlab; however, with the SensorDAQ being discontinued earlier this year, support seems unlikely.
Vernier support was much more helpful. They suggested creating short duration continuous sampling session and running repeatedly through a loop to achieve a high sampling rate with close to real time feedback. However, there will be some gaps in the collection using this method.
I'm hoping to post my code shortly as an example.
Grace Steward
on 26 Aug 2021
0 votes
After being in contact with Matlab for a few weeks, I found that increasing the sampling rate from 1kHz to 24 kHz solves this issue.
Categories
Find more on National Instruments Frame Grabbers 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!