GUI interface with arduino

now, i try to control arduino board through Matlab GUI(using IO packages). First,i try to light on the LED by click on the push button i create, below is the callback function i put:
a=arduino('com3')
a.pinMode(10,'output');
a.digitalWrite(10,1);
after i try it, the LED only blink for a second, but now i wish to light on the LED continuously, what code should i type? I wish to light on and light off the LED using push button i create...anyone can help me, thanks..

1 comentario

Mohamed Asif
Mohamed Asif el 6 de Jul. de 2017
https://in.mathworks.com/videos/arduino-and-matlab-reading-inputs-and-writing-outputs-106502.html
use this above link you can get idea about it

Iniciar sesión para comentar.

 Respuesta aceptada

Jarrod Rivituso
Jarrod Rivituso el 24 de Mzo. de 2011

0 votos

Disclaimer - I've used Arduinos in the past, but never used the MATLAB Arduino package.
With that said, I'm not sure if this is your issue, but one thing to consider is whether you want your callback to reinitialize the Arduino pinmode every time.
It seems to me like you'd really want to set up the Arduino pin modes and COM ports in the GUI initialization, and then have your callback only perform the digitalWrite.
If using GUIDE, then you will find a GUI initialization function that you can use to do the initialization. Then, you can use the guidata function to add the Arduino object to the guidata. Something like...
a = arduino('com3');
a.pinMode(10,'output');
handles.a = a;
guidata(hObject, handles);
Then, you could use the handles structure again in your callback
handles.a.digitalWrite(10,ledValue)
Again, this is all assuming you are using GUIDE. If you aren't, then you probably know your GUI's initialization better than I do.

3 comentarios

Tee
Tee el 24 de Mzo. de 2011
I'm newbie in Matlab GUI, when i put the code in initialization, it show error too,
Attempting connection ......
Basic I/O Script detected !
Arduino successfully connected !
??? Undefined function or variable 'hObject'.
Error in ==> untitled at 47
guidata(hObject, handles)
Jarrod Rivituso
Jarrod Rivituso el 25 de Mzo. de 2011
Hi Tee,
Are you placing that code in the OpeningFcn?
You may want to have a read through this documentation page, as it discusses data management within a GUI.
http://www.mathworks.com/help/techdoc/creating_guis/f5-998352.html
Other than that, I can't comment more without seeing your code.
Hope this helps!
-Jarrod
medo
medo el 28 de Jul. de 2014
hi all .... please i need the correct arduinoIO because iam downloading it but it not woke >>> thanx to all

Iniciar sesión para comentar.

Más respuestas (2)

Kaustubha Govind
Kaustubha Govind el 24 de Mzo. de 2011

0 votos

You could try using a persistent variable to store that last state, and toggle that each time the callback is fired:
persistent ledValue
if isempty(ledValue)
ledValue = 0;
end
ledValue = ~ledValue; %toggle ledValue
a=arduino('com3');
a.pinMode(10,'output');
a.digitalWrite(10,ledValue);

3 comentarios

Tee
Tee el 24 de Mzo. de 2011
I'm still a newbie in Matlab GUI, when i run the code in callback function, it show error below :
Attempting connection ......
Basic I/O Script detected !
Arduino successfully connected !
??? Error using ==> arduino>arduino.digitalWrite at 399
The value must be numeric
Error in ==> untitled>lighton_Callback at 95
a.digitalWrite(10,ledValue);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> untitled at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)untitled('lighton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Kaustubha Govind
Kaustubha Govind el 24 de Mzo. de 2011
Apparently digitalWrite doesn't like boolean values - you can make that:
a.digitalWrite(10,double(ledValue));
heisenberg
heisenberg el 18 de Mzo. de 2015
how to access serial pins in above program to send data?

Iniciar sesión para comentar.

hardik sanghvi
hardik sanghvi el 25 de Nov. de 2015

0 votos

How to make pause and counter button code

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Tee
el 24 de Mzo. de 2011

Comentada:

el 6 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by