Skip to main content
HSing.8
Associate
May 13, 2023
Question

Is there an Algorithm or a library or a Flowchart to controll STEPPER MOTORS with stm32??

  • May 13, 2023
  • 2 replies
  • 912 views

..

This topic has been closed for replies.

2 replies

MNapi
Senior II
May 13, 2023

What kind of stepper motors ? if you are talking about the small 5-12V you buy on Aliexpress.

You can use for example L293DNEE4 to interface motor and you program four IO pins on your STM32 chip.

Here is example for the stepper motor, it does not mean it will work with another you need to figure out the sequence how to energize the coils

void forward_single_stepping_stepper_1(uint16_t speed, uint16_t steps)

{

   for (uint16_t i = 0; i <steps; i++)

   {

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);   

   HAL_Delay(speed);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);

   HAL_Delay(speed);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);

   HAL_Delay(speed);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);

   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);

   HAL_Delay(speed);

   }

}

so giving you mine library it does not mean it will work in your case.

HSing.8
HSing.8Author
Associate
May 13, 2023

hi, im talking of a motor like Nema 17, i have to controll a simple robotic arm, i searchin some algorithms or a flowchart of the controll so i can convert it in a code... im new to this stuff