Controlling Raspberry pi using GUI
7 views (last 30 days)
Show older comments
Dear Fellow MATLABers
Greetings! i hope you are well
My problem is that I am trying to control my raspberry pi that is connected to an L298n motor shield that has 4 inputs to control 2 DC motors,
IN1 and IN2 to control the first one, and IN3 and IN4 to control the second one.
now in order to run for example the first motor forward
i need to set IN1 to high and IN2 to low using the function configurePins(rpi,IN1_pin, 0 or 1)
where :
rpi is the method we connect the raspberry pi to MATLAB so rpi = raspi;
IN1 pin in my case is GPIO 14 so IN1_pin = 14;
here is my code to control 2 dc motors forward for example,
my problem is :
when i try to set the function Forward to a button in my gui, it says that rpi is unknown, i tried to make it global but it didnt work for rpi, it works for the pins because they r doubles, but not the rpi.
second problem is :
i want to use my keyboard arrows to control the motors, ps : uparrow to push forward,, etc
function varargout = keyyyyboard(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @keyyyyboard_OpeningFcn, ...
'gui_OutputFcn', @keyyyyboard_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before keyyyyboard is made visible.
function keyyyyboard_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = keyyyyboard_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in FORWARD.
function FORWARD_Callback(hObject, eventdata, handles)
% hObject handle to FORWARD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get.handles(FORWARD.'on')
set(handles.FORWARD,'visible','on')
% set(handles.uitable1,'visible','on')
rpi = raspi;
a = 14; b = 15; d = 27; c = 22;
Forward(rpi,a,b,c,d)
% The keypressfcn for the figure.
% --- Executes on button press in BACKWARDS.
function BACKWARDS_Callback(hObject, eventdata, handles)
% hObject handle to BACKWARDS (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.BACKWARDS,'visible','on')
% set(handles.uitable1,'visible','on')
rpi = raspi;
a = 14; b = 15; d = 27; c = 22;
Back(rpi,a,b,c,d)
% --- Executes on button press in RIGHT_TURN.
function RIGHT_TURN_Callback(hObject, eventdata, handles)
% hObject handle to RIGHT_TURN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.RIGHT_TURN,'visible','on')
% set(handles.uitable1,'visible','on')
rpi = raspi;
a = 14; b = 15; d = 27; c = 22;
Right(rpi,a,b,c,d)
% --- Executes on button press in LEFT_TURN.
function LEFT_TURN_Callback(hObject, eventdata, handles)
% hObject handle to LEFT_TURN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.LEFT_TURN,'visible','on')
% set(handles.uitable1,'visible','on')
rpi = raspi;
a = 14; b = 15; d = 27; c = 22;
Left(rpi,a,b,c,d)
% --- Executes on button press in STOP.
function STOP_Callback(hObject, eventdata, handles)
% hObject handle to STOP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.STOP,'visible','on')
% set(handles.uitable1,'visible','on')
rpi = raspi;
a = 14; b = 15; d = 27; c = 22;
Stop(rpi,a,b,c,d)
please help me as i am very new to GUIs
0 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!