MATLAB Answers

0

How do I pass Sensor Data to a GUI?

Asked by Martin Velasquez on 18 Mar 2019
Latest activity Edited by Akshay Khadse on 27 Mar 2019
Hello,
I'm trying to create a GUI that simply plots , or shows in a gauge, what the speed of a Dc motor is. My only problem is that I don't exactly know how to pass it to a GUI function.
So I've created these objects for arduino, the shield library and the dcmotor.
I can set/read the speed, as well as plot it by using a while loop that goes on from 1 -1000, setting axis auto and the drawnow feature.
Now my problem is just doing this in the appdesigner. Now of course a "ValueChangingFcn" should be used, my only problem is passing these parameters to the app designer.
Should I set a property? make a function with the code shown below? start from scratch (i.e uicontrol, uislider..etc..)?
a=arduino('COM4','Uno','Libraries',{'Adafruit/MotorShieldV2','I2C','RotaryEncoder'});
mot=addon(a,'Adafruit/MotorShieldV2');
dcm=dcmotor(mot,1);
%taken from another post, but works well for me
interv=1000;
passo=1;
t=1;
x=0;
while (t<interv)
b=dcm.Speed;
x=[x,b];
plot(x);
axis auto
grid on
t=t+passo;
drawnow limitrate
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Akshay Khadse on 27 Mar 2019
Edited by Akshay Khadse on 27 Mar 2019

You could directly set the Value property of the Gauge in a MATLAB App. In my opinion, this is the simplest way to pass the data to a GUI designed using MATLAB App Designer.
Assuming that you have a variable named motorSpeed, you can create a simple GUI using MATLAB App Designer named myApp.mlapp as shown below:
This app only has a Guage inside it. The Value property for this Guage is a public property. You just need to have the handle for the app when it is started. Following steps should get you started:
1) Open the app from script or command line using the following command
>> handleApp = myApp
2) Change the Guage Value
>> handleApp.Guage.Value = motorSpeed;
You could do this update whenever you have a new motorSpeed Value.
Please refer the following link to more about sharing data within apps:

  0 Comments

Sign in to comment.