Documentos de Académico
Documentos de Profesional
Documentos de Cultura
I. OBJETIVOS.
a. Identificar características y especificaciones del módulo de entrenador PIC-Arduino
b. Realizar la instalación del soporte de Arduino desde Matlab.
c. Conocer las instrucciones de programación para salida digital y entrada analógica.
d. Elaborar aplicaciones básicas para el manejo de entrada y salida de datos usando
GUIDE Matlab.
II. HERRAMIENTAS
1. Computador con acceso a internet.
2. Apuntes de laboratorio.
III. BIBLIOGRAFIA
[1] Fernández F. Arduino Libro de Proyectos, Arduino 2013.
[2] Corona L., Abarca G. y Mares J. Sensores y actuadores. Aplicaciones con Arduino. Patria 2014.
IV. Actividades
2. Manejo de salidas digitales. Elabore el GUIDE para encender un led según diseño
presentado en clase.
a. Elabore Guide.
% Hints: contents =
cellstr(get(hObject,'String')) returns
pMenuPdig contents as cell array
% contents{get(hObject,'Value')}
Togle Button
returns selected item from pMenuPdig
lista=get(hObject,'String');
pin=get(hObject,'Value');
handles.opcion=lista{pin};
guidata(hObject,handles);
% --- Executes on button press in
tButtonOnOff.
function tButtonOnOff_Callback(hObject,
eventdata, handles)
% hObject handle to tButtonOnOff (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with handles and user
data (see GUIDATA)
writeDigitalPin(handles.a,handles.opcion,1);
set(handles.tButtonOnOff,'String','Apagar
Led');
else
writeDigitalPin(handles.a,handles.opcion,0);
set(handles.tButtonOnOff,'String','Encender
Led');
end
% --- Executes when user attempts to close
Close Function figure1.
function figure1_CloseRequestFcn(hObject,
eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with handles and user
data (see GUIDATA)
clear handles.a
% Hint: delete(hObject) closes the figure
delete(hObject);
componente
function
Opening Function DelgadoV_RojasJ_Analogico_G05_OpeningFcn(hObject,
eventdata, handles, varargin)
% This function has no output args, see
OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
% varargin command line arguments to
DelgadoV_RojasJ_Analogico_G05 (see VARARGIN)
global k IO
k=0;
IO=arduino('COM3')
% Choose default command line output for
DelgadoV_RojasJ_Analogico_G05
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DelgadoV_RojasJ_Analogico_G05 wait
for user response (see UIRESUME)
% uiwait(handles.figure1);
function edit1_Callback (hObject, eventdata,
handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
handles.dato1=get(hObject,'string')
Vmax handles.Ymax=str2double(handles.dato1)
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents
of edit1 as text
% str2double(get(hObject,'String'))
returns contents of edit1 as a double
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents
of edit3 as text
% str2double(get(hObject,'String'))
returns contents of edit3 as a double
function edit2_Callback(hObject, eventdata,
handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
Núm. muestras handles.dato2=get(hObject,'string')
handles.Xmax=str2double(handles.dato2)
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents
of edit2 as text
% str2double(get(hObject,'String'))
returns contents of edit2 as a double
% --- Executes on button press in pButtonLim.
function pButtonLim_Callback(hObject, eventdata,
handles)
% hObject handle to pButtonLim (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
Limpiar Campos % handles structure with handles and user data
(see GUIDATA)
lim = '';
set(handles.edit1,'String',lim);
set(handles.edit2,'String',lim);
set(handles.edit3,'String',lim);
% --- Executes on button press in pb1.
function pb1_Callback(hObject, eventdata,
handles)
% hObject handle to pb1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
global k IO
axes(handles.axes1)
Iniciar/Detener %y1=[];
for k=1:1:handles.Xmax
handles.ejex(k,1)=k;
y1(k,1)=readVoltage(IO,'A0');
%y1(k,1)=(5/1023)*IO.analogRead(0)
plot(handles.ejex,y1,'LineWidth',2);grid on;
axis([0 handles.Xmax handles.Ymin
handles.Ymax]);
pause(0.01);
end
% --- Executes on button press in pButtonSal.
function pButtonSal_Callback(hObject, eventdata,
handles)
% hObject handle to pButtonSal (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
Salir opc = questdlg('¿Desea Salir del
Programa?','Salir','Si','No','No');
if (strcmp(opc,'No'))
return;
end
clear IO
clc; close all;
% --- Executes when user attempts to close
figure1.
function figure1_CloseRequestFcn(hObject,
eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
Close Function
% Hint: delete(hObject) closes the figure
opc = questdlg('¿Desea salir del
programa?','Salir','Si','No','No');
if (strcmp('No',opc))
return;
else
clear IO
delete(hObject);
end
V. Cuestionario Final
V.1 Manejo de salidas digitales. Elabore un GUIDE para encender simular un
semáforo.
a. Elabore diseño GUIDE.
b. Coloque le programa de los componentes programados, separelos
por componente.
% --- Executes just before
DelgadoVicente_RojasJohn_Semaforo_G05 is made visible.
function
DelgadoVicente_RojasJohn_Semaforo_G05_OpeningFcn(hObject,
eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% varargin command line arguments to
DelgadoVicente_RojasJohn_Semaforo_G05 (see VARARGIN)
Opening handles.a=arduino;
set (handles.eTextPue,'String',handles.a.Port);
Function %Capturando puesrto COMX
set (handles.eTextTar,'String',handles.a.Board);
set (handles.pMenuPdig1,'String',strseq('D',2:13));
set (handles.pMenuPdig2,'String',strseq('D',3:13));
set (handles.pMenuPdig3,'String',strseq('D',4:13));
handles.opcion1='D2';
handles.opcion2='D3';
handles.opcion3='D4';
% Choose default command line output for
DelgadoVicente_RojasJohn_Semaforo_G05
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Executes on selection change in pMenuPdig1.
function pMenuPdig1_Callback(hObject, eventdata, handles)
% hObject handle to pMenuPdig1 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% Hints: contents =
cellstr(get(hObject,'String')) returns
pMenuPdig2 contents as cell array
% contents{get(hObject,'Value')} returns
selected item from pMenuPdig2
lista2=get(hObject,'String');
pin2=get(hObject,'Value');
handles.opcion2=lista2{pin2};
guidata(hObject,handles);
% --- Executes on button press in tButtonOnOff.
function tButtonOnOff_Callback(hObject,
eventdata, handles)
% hObject handle to tButtonOnOff (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with handles and user
data (see GUIDATA)
estado=get(hObject,'Value');
pin = 'D8'
configurePin(handles.a,pin,'DigitalInput');
while(1)
Iniciar estado = readDigitalPin(handles.a,'D8');
disp(estado);
if(estado==0)
writeDigitalPin(handles.a,handles.opcion2,1);
set(handles.tButtonOnOff,'String','Detener');
else
writeDigitalPin(handles.a,handles.opcion2,0);
set(handles.tButtonOnOff,'String','Iniciar');
end
end
% --- Executes when user attempts to close
figure1.
function figure1_CloseRequestFcn(hObject,
eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a
Close Function future version of MATLAB
% handles structure with handles and user
data (see GUIDATA)
clear handles.a
% Hint: delete(hObject) closes the figure
delete(hObject);