Adafruit Motor Shield 2 Motors MATLAB

Hi all,

This is my first post. :cold_sweat:

I am currently building an xy gantry as a part of a project. I am using an Arduino Uno, an Adafruit Motor Shield, and 2 stepper motors. I have interfaced the Arduino with a MATLAB GUI and the connection is working great but what I am finding is that as I run the program I created I cannot run the 2 motors simultaneously. One axis moves the required steps and then once its finished the second moves.
Its simple code but surely it should work?

function BeginButton_Callback(hObject, eventdata, handles)
% hObject handle to BeginButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;

a.stepperSpeed(1, 1);
a.stepperSpeed(2, 1);
a.stepperStep(1, 'backward', 'double',255);
a.stepperStep(2, 'forward', 'double', 255);

I've seen the cnc build where they speak of using a motor shield and sparkfun easy driver to drive the 3 motors but cannot get it to work myself. :astonished:

http://blog.arduino.cc/category/languages/mathlab/

Can anyone help me out on this one? :~

Thanks,

Colm

What stepper motor library are you using on the Arduino ?

I have downloaded the ArduinoIO package from the Mathworks website and installed the motor_v2.pde onto the arduino to coincide with using the v2 motor shield. The commands are working, just they are working individually and not together.

I have downloaded the ArduinoIO package from the Mathworks website

And, now you expect us to do the same, but without you providing the URL. Hmmm, no.

The commands are working, just they are working individually and not together.

There are at least two different approaches to solving the problem (not counting using two PCs and two Arduinos). Which one is most appropriate depends on your mystery code.

Sorry for getting your knickers in a twist. You might want to take that stick out a few inches…

Did I say for you to download it? Hmmm, no.

This is a forum where people look for help. I, myself, am looking for help. There are bound to be people who encountered Adafruit motor shields and can understand a little about them and the MATLAB side of things. If you don’t want to try help then don’t, but there is no need for being an absolute douche for someone wanting help. By the way, my mystery code is a common piece of code within a MATLAB GUI which I stated I was using. It is to run a series of events when a button is pressed, in this case to begin the motors.

Thanks, I hope you have a horrible dinner :slight_smile:

CClinton48:
Sorry for getting your knickers in a twist. You might want to take that stick out a few inches....

Did I say for you to download it? Hmmm, no.

This is a forum where people look for help. I, myself, am looking for help. There are bound to be people who encountered Adafruit motor shields and can understand a little about them and the MATLAB side of things. If you don't want to try help then don't, but there is no need for being an absolute douche for someone wanting help. By the way, my mystery code is a common piece of code within a MATLAB GUI which I stated I was using. It is to run a series of events when a button is pressed, in this case to begin the motors.

Thanks, I hope you have a horrible dinner :slight_smile:

I am with Paul on this. You have provided no details of the program running on MATLAB nor the program running on the Arduino apart from the cryptic snippets in your first post. If you had given details of the Arduino library I was going to check whether the stepperStep() method was blocking and maybe suggest ways round it but you have made that impossible.

Sorry, but I feel that I can be of no more help with your problem but I am intrigued as to whether MATLAB is controlling the motors directly or via the Arduino.

You are going about it a nice way though explaining yourself. He was very short and like I said its my first post. I am new and learning to understand this sort of stuff. I am mechanical by trade and this electronic programming is proving difficult to understand.

I have downloaded the relevant adafruit stepper librarys that are recommended to operate within the Arduino environment.

To interlink the MATLAB and Arduino it is recommened to download the ArduinoIO software support package.

This package contains a .pde to upload to the arduino for the matlab to be able to cross function with the arduino and the motor shield I have installed. That is the adafruit motor shield v2. I have uploaded this to the arduino. It is working like I said, a connection is made and functioning. Its just not allowing myself to run the two motors simultaneously.

I have created a GUI that has several buttons completing a few image processing tasks but when it comes down to moving the motors it is dependent on the pressing of one button. The coding for this is that stated previously, but I have added in where the arduino is referenced first in the program.

% --- Executes just before KnismesisGUI is made visible.
function KnismesisGUI_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 KnismesisGUI (see VARARGIN)

% Choose default command line output for KnismesisGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set(handles.SpeedControl,'SelectedObject',handles.SlowButton);
set(handles.TransOptions,'SelectedObject',handles.OriginalButton);

clear all;

global a;

a = arduino('COM15');

function BeginButton_Callback(hObject, eventdata, handles)
% hObject handle to BeginButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;

a.stepperSpeed(1, 1);
a.stepperSpeed(2, 1);
a.stepperStep(1, 'backward', 'double',255);
a.stepperStep(2, 'forward', 'double', 255);

I have 'a' set as a global coordinate as it is the name given to the arduino in the input stage and needs to be capable of being referenced elsewhere in the program.

Sorry about the previous lack of information. Thanks for a bit more of an explanation about what is needed unlike the other fella.

Hi all,

This is my first post. smiley-roll-sweat

No, it's your second - you cross-posted the exact same question in another section.

Don't.

I tried taking that down but it wouldn't let me. I realised my problem was a programming problem. It is my first day on a forum. Sorry

A suggestion for you. Forget about using MATLAB to control the motors for now and write a program to do it on the Arduino, perhaps as a series of actions to be taken each time through loop()

CClinton48:
% — Executes just before KnismesisGUI is made visible.
function KnismesisGUI_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 KnismesisGUI (see VARARGIN)

% Choose default command line output for KnismesisGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set(handles.SpeedControl,‘SelectedObject’,handles.SlowButton);
set(handles.TransOptions,‘SelectedObject’,handles.OriginalButton);

Just in case someone comes across this in the future as I did. This will work if you save a to the handles structure instead of as a global variable. Change the beginning of the GUI m file to:

% — Executes just before KnismesisGUI is made visible.
function KnismesisGUI_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 KnismesisGUI (see VARARGIN)

% Choose default command line output for KnismesisGUI
handles.output = hObject;

handles.a = arduino(‘COM15’);

% Update handles structure
guidata(hObject, handles);

Then your commands to the Arduino will become:

handles.a.stepperSpeed(1, 1);
handles.a.stepperSpeed(2, 1);
handles.a.stepperStep(1, ‘backward’, ‘double’,255);
handles.a.stepperStep(2, ‘forward’, ‘double’, 255);

If they are within a function just pass the handles structure to it.