フィルターのクリア

How can I display live data in MATLAB from external sensors connected through arduino?

3 ビュー (過去 30 日間)
Emma  Atkinson
Emma Atkinson 2019 年 4 月 23 日
編集済み: Emma Atkinson 2019 年 4 月 23 日
I am currently working on a project that is using a displacement sensor and a load cell to take measurement from a surgical tools that puts electrodes in the brain. A huge part of the project is that I have live/real-time data being shown as the sensors are being used. The code I am using was written in MATLAB and is using an arduino support package. I want to be able to not only show the graph of real-time data, but also show the numerical value as well. Both sensors give a voltage output, which needs to be converted to the displacement, force and speed. I want to extract the data from the sensors as they are in motion, feed it through the arduino into a MATLAB code that will produce a graph that will work in real-time. So far, in terms of the progress, the code that I have outputs a graph that shows the change in voltage as time goes on (which is a good first step). My questions are as follows:
  1. how can I convert the voltage data into the displacment, force, and speed data that I want, and show that on the graph in real-time? (i have special equations that can convert to these numbers, I just dont know how to implement them into the code).
  2. how can I display a numerical value in real time in addition to the graph? (i.e. I want to show the graph changing, but also have something that says "force= , displacement= , speed= and shows the real-time data and changes as the sensors change)
Here is the code that I have :
clear
clc
%User Defined Properties
a = arduino('Com4'); % define the Arduino Communication port
plotTitle = 'Real-Time Data Log';
xLabel = 'Elapsed Time (s)';
yLabel = 'Voltage (V)';
legend1 = 'Displacement Sensor';
legend2 = 'Load Cell';
yMax = 10; %y Maximum Value
yMin = 0; %y minimum Value
plotGrid = 'on'; % 'off' to turn off grid
min = 0; % set y-min
max = 3; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
plotGraph = plot(time,data,'-r' );
hold on %hold on makes sure all of the channels are plotted
plotGraph1 = plot(time,data1,'-b');
hold on
% plotGraph2 = plot(time, data2,'-g' );
title(plotTitle,'FontSize',15);
xlabel(xLabel,'FontSize',15);
ylabel(yLabel,'FontSize',15);
legend(legend1)% legend(legend1,legend2,legend3)
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph) %Loop when Plot is Active will run until plot is closed
dat = readVoltage(a,'A0'); %* 0.48875855327; %Data from the arduino
dat1 = readVoltage(a, 'A1'); %* 0.48875855327;
% dat2 = a.analogRead(4)* 0.48875855327;
count = count + 1;
time(count) = toc;
data(count) = dat(1);
data1(count) = dat1(1);
% data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
set(plotGraph,'XData',time,'YData',data);
set(plotGraph1,'XData',time,'YData',data1);
% set(plotGraph2,'XData',time,'YData',data2);
axis([0 time(count) min max]);
%Update the graph
pause(delay);
end
delete(a);
disp('Plot Closed and arduino object has been deleted')

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by