How to get data from esp32 into matlab application and display in graphs in real time

23 visualizaciones (últimos 30 días)
I am looking for the code to get matlab to collect data from three different sensors connected to the esp32, but whatever I try isn't working to communicate with the esp32 and recieve the data needed. After I get this portion to function properly I need to display it in real time on graphs after hitting the start button of the app.Below is the code that has been created for the app and I need to add in the code under the start button function.
classdef MatlabHeartMonitorApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
StartButton matlab.ui.control.Button
FilteredSCG matlab.ui.control.UIAxes
FilteredPCG matlab.ui.control.UIAxes
FilteredECG matlab.ui.control.UIAxes
RawSCG matlab.ui.control.UIAxes
RawPCG matlab.ui.control.UIAxes
RawECG matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
%s = serial('com3');
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0 1 0];
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create RawECG
app.RawECG = uiaxes(app.UIFigure);
title(app.RawECG, 'Raw ECG')
xlabel(app.RawECG, 'Time (s)')
ylabel(app.RawECG, 'Frequency (Hz)')
app.RawECG.PlotBoxAspectRatio = [1.94957983193277 1 1];
app.RawECG.XTickLabelRotation = 0;
app.RawECG.YTickLabelRotation = 0;
app.RawECG.ZTickLabelRotation = 0;
app.RawECG.Position = [1 325 199 135];
% Create RawPCG
app.RawPCG = uiaxes(app.UIFigure);
title(app.RawPCG, 'Raw PCG')
xlabel(app.RawPCG, 'Time (s)')
ylabel(app.RawPCG, 'Frequency (Hz)')
app.RawPCG.PlotBoxAspectRatio = [2.20168067226891 1 1];
app.RawPCG.XTickLabelRotation = 0;
app.RawPCG.YTickLabelRotation = 0;
app.RawPCG.ZTickLabelRotation = 0;
app.RawPCG.Position = [199 325 219 135];
% Create RawSCG
app.RawSCG = uiaxes(app.UIFigure);
title(app.RawSCG, 'Raw SCG')
xlabel(app.RawSCG, 'Time (s)')
ylabel(app.RawSCG, 'Frequency (Hz)')
app.RawSCG.PlotBoxAspectRatio = [2.11764705882353 1 1];
app.RawSCG.XTickLabelRotation = 0;
app.RawSCG.YTickLabelRotation = 0;
app.RawSCG.ZTickLabelRotation = 0;
app.RawSCG.Position = [417 325 212 135];
% Create FilteredECG
app.FilteredECG = uiaxes(app.UIFigure);
title(app.FilteredECG, 'Filtered ECG')
xlabel(app.FilteredECG, 'Time (s)')
ylabel(app.FilteredECG, 'Frequency (Hz)')
app.FilteredECG.XTickLabelRotation = 0;
app.FilteredECG.YTickLabelRotation = 0;
app.FilteredECG.ZTickLabelRotation = 0;
app.FilteredECG.Position = [1 164 199 135];
% Create FilteredPCG
app.FilteredPCG = uiaxes(app.UIFigure);
title(app.FilteredPCG, 'Filtered PCG')
xlabel(app.FilteredPCG, 'Time (s)')
ylabel(app.FilteredPCG, 'Frequency (Hz)')
app.FilteredPCG.XTickLabelRotation = 0;
app.FilteredPCG.YTickLabelRotation = 0;
app.FilteredPCG.ZTickLabelRotation = 0;
app.FilteredPCG.Position = [209 164 199 135];
% Create FilteredSCG
app.FilteredSCG = uiaxes(app.UIFigure);
title(app.FilteredSCG, 'Filtered SCG')
xlabel(app.FilteredSCG, 'Time (s)')
ylabel(app.FilteredSCG, 'Frequency (Hz)')
app.FilteredSCG.XTickLabelRotation = 0;
app.FilteredSCG.YTickLabelRotation = 0;
app.FilteredSCG.ZTickLabelRotation = 0;
app.FilteredSCG.Position = [423 164 199 135];
% Create StartButton
app.StartButton = uibutton(app.UIFigure, 'push');
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.StartButton.IconAlignment = 'center';
app.StartButton.BackgroundColor = [0 0 1];
app.StartButton.FontColor = [1 1 1];
app.StartButton.Position = [280 121 100 22];
app.StartButton.Text = 'Start';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = MatlabHeartMonitorApp
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Respuestas (1)

Ninad
Ninad el 22 de En. de 2024
Hi Alexander,
I understand that you are trying to collect data from three different sensors connected to ESP32 and display it your app after hitting the "Start" button.
The "tcpclient" object in MATLAB will help you. It represents a connection to a remote host and remote port from MATLAB to read and write data. The remote host can be a server or hardware that supports TCP/IP communication, and must already exist.
Following line of code create a TCP/IP client connection called "t" using the IP address shown and port 80. The "read" function can be used to read data from the "tcpclient" object.
t = tcpclient("144.212.130.17",80) % Replace with the IP address of ESP32
read(t)
Go through the following MATLAB Documentation to understand how to use the "tcpclient" object:
This MATLAB Documentation will help you with creating a graph in MATLAB App Designer:
Hope this helps.
Regards
Ninad

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by