Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
: Michael Klug)
GUI - Graphical User Interface
OBS:
a propriedade "TAG" de cada elemento deve ser memorizada para a posterior
programao (para facilitar devem ser utilizadas nomenclaturas que lembrem
a funo de cada objeto: ex: botao_on, lista_dados, ...);
Para alterar as propriedades de um elemento basta dar dois cliques sobre o
mesmo.
PROGRAMAO:
PASSO 1: Baixe o pacote para manipulao do arduino via Matlab:
Opo 1:
URL:http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-
and-simulink-support-for-arduino
OBS: aps efetuar o download e descompactar, efetuar a instalao a partir do
arquivo "install_arduino.m" diretamente do workspace do matlab.
URL: http://www.mathworks.com/hardware-support/arduino-matlab.html
PASSO 2: Conecte o arduino e identifique a porta utilizada (ver primeira figura abaixo).
Carregue o arduino com o firmware "adioes.pde" (localizado na pasta pde/adioes)
usando a sua IDE (ver segunda figura abaixo).
Pronto, o arduino est apto a ser controlado atravs do ambiente Matlab!!!
Comandos tpicos:
% read digital input from pin 4 % change reference voltage for analog pins
dv=digitalRead(a,4); to external
analogReference(a,'external');
% output the digital value (0 or 1) to pin 13
digitalWrite(a,13,dv); % change it back to default
% read analog input from analog pin 5 analogReference(a,'default');
(physically != from digital pin 5)
av=analogRead(a,5);
% gets the name of the serial port to which encoderAttach(a,0,3,2)
the arduino is connected to
serial(a) % read the encoder position
encoderRead(a,0)
% flushes the PC's serial input buffer (just
in case) % attach encoder #2 on pins 18 (pin A) and
flush(a); 21 (pin B)
encoderAttach(a,2,18,21)
% sends number 42 to the arduino and
back (to see if it's still there) % sets debouncing delay to 17 (~1.7ms) for
roundTrip(a,42) encoder #2
encoderDebounce(a,2,17)
% attach servo on pin #9
servoAttach(a,9); % read position or encoder #2
encoderRead(a,2)
% return the status of all servos
servoStatus(a); % reset position of encoder #2
encoderReset(a,2)
% rotates servo on pin #9 to 100 degrees
servoWrite(a,9,100); % get status of all three encoders
encoderStatus(a);
% reads angle from servo on pin #9
val=servoRead(a,9) % detach encoder #0
encoderDetach(a,0);
% detach servo from pin #9
servoDetach(a,9); % close session
delete(a)
% attach encoder #0 on pins 3 (pin A) and 2
(pin B)
global a
valor_angulo=round(get(handles.angulo_servo,'Value')); % Le
valor do Slider
set(handles.string_angulo,'String',num2str(valor_angulo));
% Atualiza Label do Angulo
a.servoWrite(4,valor_angulo);
clear a
delete(instrfind({'Port'},{'COM6'}));
warning off; clc;
global a
a=arduino('COM6');
a.servoAttach(4);
a.servoWrite(4,90);