How do I pass Sensor Data to a GUI?

6 vues (au cours des 30 derniers jours)
Martin Velasquez
Martin Velasquez le 18 Mar 2019
Modifié(e) : Akshay Khadse le 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

Réponses (1)

Akshay Khadse
Akshay Khadse le 27 Mar 2019
Modifié(e) : Akshay Khadse le 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:

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by