Hi guys,
I have the same issues controlling 28BYJ-48 stepper with ULN2003 using MATLAB. I have used code very similar to that given above and made the trick to speed up x7 the process...
I want to control a usb cam and the stepper motor through matlab so as to rotate 2 degrees each time the stepper motor take a picture of an object attached on the stepper motor and continue this process until a full 360 degree rotation is reached i.e. take 180 pictures of the object from respective angles.
In total the stepper motor makes 4096 steps for a 360 degree rotation thus for rotating 2 degrees:
4096 steps equal 360 degrees
x steps equal 2 degrees
x= 22.7555556 steps
in code x is k and has to be an integer (right?) so the problem is that with my code below if I use k=23 (23 steps is approximately 2 degrees) the actual rotation is approximately 380 degrees instead of 360...
and if I use k=22 steps the actual rotation is approximately 300 degrees instead of 360.
I do not mind to have a small error 2-5 degrees ... but 20 degrees or 60 degrees error is huge... any ideas? any suggestions to overcome this problem?
If I buy adafruit motor shield and use the adafruit library to control this motor would it give me a solution? Does adafruit shield support 28BYJ-48 5Volt stepper motor?
% Use cam as the name of the object,
% type 'webcamlist' to find out which are the available cameras in your
% system, choose the appropriate cam, note 1 is the first available webcam.
cam = webcam(1);
% set camera resolution
cam.Resolution = '640x480';
%preview cam
preview(cam)
%initializing a counter for numbering the acquire images
counter = 000; %initialize filename increment
%initializing connection with arduino
a=arduino('com3','Mega2560');
%setting up arduino pins and steps for stepper motor
pins={'D8', 'D9', 'D10', 'D11'};
steps={ '0001','0011', '0010','0110','0100', '1100', '1000', '1001'};
steps_size=size(steps,2); %number of steps = 8
configurePin(a,'D8','DigitalOutput');
configurePin(a,'D9','DigitalOutput');
configurePin(a,'D10','DigitalOutput');
configurePin(a,'D11','DigitalOutput');
%pause waiting for preview
pause(6);
closePreview(cam);
for i = 1:1:180
%take snapshot
img = snapshot(cam);
savename = strcat('C:\Users\orf\Desktop\New Image Sets\' ,num2str(counter, '%03i'), '.jpg'); %this is where and what your image will be saved
imwrite(img, savename);
%pause
pause(4);
%moving stepper motor 2 degrees(23 steps approximately)
for k = 1:23
step = steps{mod(k,steps_size)+1}; % step=1,2,3,4,5,6,7,8
for j=1:4
writeDigitalPin(a, pins{j}, str2double(step(j)));
end
end
counter = counter +1; %counter for images should increment each time you push the button
end
%pause so as to switch off the LED light and grab a background image
clear('cam');