Error while operating stepper motor

조회 수: 4 (최근 30일)
safaa al-hafar
safaa al-hafar 2021년 11월 3일
답변: Shreshth 2024년 7월 16일
Hello,
I want to control stepper motor using matlab, arduino hardware and l293d driver.
I write simple code to supply the driver with appropriate pulses, the motor move but not in the correct way and the speed is fixed dispite of value of delay time between steps. this is the code below. I test the code in arduino ide it work fine and the stepper fully controlled, but i don't know why in matlab it doesn't work. any one help
clear;
clc;
delay_time = 0.001; % delay time between steps
%% Initialize arduino pins
a = arduino("COM6","Mega2560");
configurePin(a,"D8","DigitalOutput");
configurePin(a,"D9","DigitalOutput");
configurePin(a,"D10","DigitalOutput");
configurePin(a,"D11","DigitalOutput");
%% move stepper motor step by step with delat time 1ms
while 1
% first step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% second step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% third step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
% 4th step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
end

답변 (1개)

Shreshth
Shreshth 2024년 7월 16일
Hey Safaa,
It appears that u are looking to control stepper motor using MATLAB and L293D driver.
MATLAB handles the timing and digital pin writing compared to the Arduino IDE. MATLAB might not be able to achieve the precise timing required for controlling the stepper motor, resulting in the motor not moving correctly or at a fixed speed regardless of the delay time.
I would recommend you to install the support package for ardunio hardware and then try to control the motor.
You can use L293D motor block controls to control the motor.
Kindly refer to the below mentioned resources from MathWorks to understand about the support package and controlling motor using Arduino board.
Hope it helps.

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by