Stepper motor programming on arduino using drv8825 on MATLAB

7 views (last 30 days)
I am facing a problem while programming a stepper motor on arduino using drv8825 on MATLAB. The results are not same while programming on these 2 platforms.
On Arduino IDE its working as expected using the following code:
# define dirpin 2
# define stepPin 3
# define stepsPerRevolution 200
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(600);
digitalWrite(stepPin, LOW);
delayMicroseconds(600);
}
delay(600);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
//Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(600);
digitalWrite(stepPin, LOW);
delayMicroseconds(600);
}
delay(600);
}
On MATLAB I have tried to program the same but results are not same as shown on Arduino, using the following code:
clear a
% Arduino Declaration
a = arduino('COM4', 'Uno');
StepPerRevolution = 200;
% Pin Configuration
configurePin(a,'D2','DigitalOutput'); %D2 = Direction pin
configurePin(a,'D3','DigitalOutput'); %D3 = Step pin
while true
writeDigitalPin(a,'D2',1);
for i = 0:StepPerRevolution
writeDigitalPin(a,'D3',1);
pause(0.0006);
writeDigitalPin(a,'D3',0);
pause(0.0006);
end
writeDigitalPin(a,'D2',0);
for i = 0:StepPerRevolution
writeDigitalPin(a,'D3',1);
pause(0.0006);
writeDigitalPin(a,'D3',0);
pause(0.0006);
end
end
Please help

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!