Stepper motor control with matlab and arduino - Page 1
Forum section: electronics / general

author: Jagomezh93
author_rank: Newbie
timestamp: April 19, 2023, 02:30:43 am
content: Hello all I am José and this is my first post.I want to move a stepper motor using Matlab but I do not know what is wrong. The motor does not move.Materials:Arduino UnoTB6600 Motor DriverMotor: 28HB30-401AArduino Suport Package for MatlabThe next code works ok, it is for the Arduino IDE.int BOTON_1 = 7; //SELECCIONARint BOTON_2 = 8; //MOVERint LED_1 = 5; //ENCENDER AVANCEint LED_2 = 6; //ENCENDER REVERSAint ENA = 3; //ENABLE A PIN 3int DIR = 2; //DIRECCION PIN 2int PUL = 4; //PULSO PIN 4void setup() {pinMode(BOTON_1, INPUT_PULLUP); //SE DECLARA PIN 7 COMO ENTRADApinMode(BOTON_2, INPUT_PULLUP); //SE DECLARA PIN 8 COMO ENTRADApinMode(LED_1, OUTPUT); //SE DECLARA PIN 5 COMO SALIDApinMode(LED_2, OUTPUT); //SE DECLARA PIN 6 COMO SALIDApinMode (PUL, OUTPUT); //SE DECLARA PIN 4 COMO SALIDApinMode (DIR, OUTPUT); //SE DECLARA PIN 2 COMO SALIDApinMode (ENA, OUTPUT); //SE DECLARA PIN 3 COMO SALIDA}void loop() {if (digitalRead(BOTON_1) == HIGH){ //SELECCION 0-> RETROCEDER; 1-> AVANZAR;if (digitalRead(BOTON_2) == HIGH){ //BOTON_2digitalWrite(LED_1, LOW);digitalWrite(PUL,HIGH); //PARA MOTOR}else {digitalWrite(LED_1, HIGH); //AVANZAdigitalWrite(DIR,LOW);digitalWrite(ENA,HIGH);digitalWrite(PUL,HIGH);digitalWrite(PUL,LOW);}}else{if (digitalRead(BOTON_2) == HIGH){digitalWrite(LED_2, LOW);digitalWrite(PUL,HIGH);}else{digitalWrite(LED_2, HIGH); //RETROCEDEdigitalWrite(DIR,HIGH);digitalWrite(ENA,HIGH);digitalWrite(PUL,HIGH);digitalWrite(PUL,LOW);}}}The next code is the same but for Matlab and the motor does not movea = arduino('COM8','Uno');configurePin(a,'D2','DigitalOutput'); % DIRECCION - PIN 2configurePin(a,'D3','DigitalOutput'); % ENABLE - PIN 3configurePin(a,'D4','DigitalOutput'); % PULSO - PIN 4configurePin(a,'D5','DigitalOutput'); % LED 1 ENCENDER AVANCEconfigurePin(a,'D6','DigitalOutput'); % LED 2 ENCENDER REVERSAconfigurePin(a,'D7','Pullup'); % BOTON 1 SELECTORconfigurePin(a,'D8','Pullup'); % BOTON 2 MOVERwhile 1if readDigitalPin(a,'D7') == 1 % 1 --> AVANZAR / 0 --> RETROCEDERif readDigitalPin(a,'D8') == 1 % HACER NADAwriteDigitalPin(a,'D5',0); % D5 LED 1 APAGADOwriteDigitalPin(a,'D4',1); % D4 PULSO ALTO --> PARAR MOTORelsewriteDigitalPin(a,'D5',1); % D4 LED 1 ENCIENDEwriteDigitalPin(a,'D2',0); % DIRECCION --> BAJO PARA AVANZARwriteDigitalPin(a,'D3',1); % ENABLE --> ALTOwriteDigitalPin(a,'D4',1); % PULSO --> ALTOwriteDigitalPin(a,'D4',0); % PULSO --> BAJOendelseif readDigitalPin(a,'D8') == 1 % HACER NADAwriteDigitalPin(a,'D6',0); % D6 LED 2 APAGADOwriteDigitalPin(a,'D4',1); % D4 PULSO ALTO --> PARAR MOTORelsewriteDigitalPin(a,'D6',1); % D8 LED 1 ENCIENDEwriteDigitalPin(a,'D2',1); % DIRECCION --> ALTO PARA RETROCEDERwriteDigitalPin(a,'D3',1); % ENABLE --> ALTOwriteDigitalPin(a,'D4',1); % PULSO --> ALTOwriteDigitalPin(a,'D4',0); % PULSO --> BAJOendendendPlease help me.

author: rstofer
author_rank: Super Contributor
timestamp: April 23, 2023, 03:25:01 am
content: I would probably Google for "stepper motor control with matlab and arduino" and just copy/pasteMaybe this one (but there are others)https://youtu.be/ZsyLtv77BtQ