# Stepper Motor not moving to target position

**URL:** https://community.simplefoc.com/t/stepper-motor-not-moving-to-target-position/7093
**Category:** developement
**Tags:** raspberry\_pi\_pico, l298n, stepper
**Created:** [April 22, 2025, 1:28pm UTC](https://community.simplefoc.com/t/stepper-motor-not-moving-to-target-position/7093 "2025-04-22T13:28:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Brent\_Porter](https://community.simplefoc.com/user_avatar/community.simplefoc.com/brent_porter/32/8603_2.png) [@Brent\_Porter](https://community.simplefoc.com/u/Brent_Porter)
#### Post date: [April 22, 2025, 1:28pm UTC](https://community.simplefoc.com/t/stepper-motor-not-moving-to-target-position/7093/1 "2025-04-22T13:28:44Z")

</div>

**SETUP:** I am using a Raspberry Pi Pico configured for the Arduino IDE using the Arduino-Pico library. I am using NEMA08-AMT112S series stepper motor that comes with an encoder. The driver is a standard L298N stepper driver board.

**ISSUE:** I am having issues moving to the motor target position. I have the motor target hard coded to a value of 3. However, when I run the following code, the motor moves for the initialization then holds itself at the zero position. The motor gets hot. I have it printing the motor angle and it says it is at 0. Without the motor driver being powered, the motor angle updates as I turn the motor shaft with my hands. What could be the cause of the issues?

```auto
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"

#define P1_PLUS 18
#define P1_MINUS 19
#define P2_PLUS 20
#define P2_MINUS 21
#define EN1 26
#define EN2 27
#define A 14
#define B 15

// Stepper driver instance
StepperMotor motor = StepperMotor(50 , 5.4);
StepperDriver4PWM driver = StepperDriver4PWM(P1_PLUS, P1_MINUS, P2_PLUS, P2_MINUS, EN1, EN2);

// encoder instance
Encoder encoder = Encoder(A, B, 2048);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}

// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {
  
  
  gpio_init(P1_PLUS); // Initialize GPIO
  gpio_set_dir(P1_PLUS, GPIO_OUT); // Set as output
  gpio_init(P1_MINUS); // Initialize GPIO
  gpio_set_dir(P1_MINUS, GPIO_OUT); // Set as output
  gpio_init(P2_PLUS); // Initialize GPIO
  gpio_set_dir(P2_PLUS, GPIO_OUT); // Set as output
  gpio_init(P2_MINUS); // Initialize GPIO
  gpio_set_dir(P2_MINUS, GPIO_OUT); // Set as output

  gpio_init(EN1); // Initialize GPIO
  gpio_set_dir(EN1, GPIO_OUT); // Set as output
  gpio_init(EN2); // Initialize GPIO
  gpio_set_dir(EN2, GPIO_OUT); // Set as output

  gpio_init(A); // Initialize GPIO
  gpio_set_dir(A, GPIO_IN); // Set as output
  gpio_init(B); // Initialize GPIO
  gpio_set_dir(B, GPIO_IN); // Set as output

  // initialize encoder sensor hardware
  encoder.init();
  encoder.enableInterrupts(doA, doB);
  // link the motor to the sensor
  motor.linkSensor(&encoder);

  // choose FOC modulation
  motor.foc_modulation = FOCModulationType::SinePWM;

  // power supply voltage [V]
  driver.voltage_power_supply = 24;
  driver.init();
  driver.enable();
  // link the motor to the driver
  motor.linkDriver(&driver);
  // Max DC voltage allowed - default voltage_power_supply
  driver.voltage_limit = 24;

  // set control loop type to be used
  //motor.controller = MotionControlType::velocity_openloop;
  motor.controller = MotionControlType::angle;
  
  // controller configuration based on the control type
  motor.PID_velocity.P = 0.1;
  motor.PID_velocity.I = 10;
  motor.PID_velocity.D = 0.00;
  motor.PID_velocity.output_ramp = 5;

  // velocity low pass filtering time constant
  motor.LPF_velocity.Tf = 0.1;
  motor.current_limit = 1.6; // Amps - default 2 Amps
  // angle loop controller
  motor.P_angle.P = 2;
  motor.P_angle.I = 0.5;
  motor.P_angle.D = 0;
  // angle loop velocity limit
  motor.velocity_limit = 5;
  
  
  
  Serial.begin(9600);
  
  //driver.enable();

  motor.useMonitoring(Serial);

  // initialise motor
  motor.init();
  // align encoder and start FOC
  motor.initFOC();

  // define the motor id
  command.add('M', onMotor, "motor");
  motor.target = 0;
 
  delay(1000);

}

void loop() {
  motor.target = 3;

  // iterative setting FOC phase voltage
  motor.loopFOC();
  motor.move();

}

```

---

<div class="post-metadata">

### Author: ![Brent\_Porter](https://community.simplefoc.com/user_avatar/community.simplefoc.com/brent_porter/32/8603_2.png) [@Brent\_Porter](https://community.simplefoc.com/u/Brent_Porter)
#### Post date: [April 25, 2025, 2:13pm UTC](https://community.simplefoc.com/t/stepper-motor-not-moving-to-target-position/7093/2 "2025-04-25T14:13:37Z")

</div>

@Andreas_Hofmann I should have clarified, the connections are all good. I know this because I am able to run the stepper motor and control the speed in open-loop mode. During the init stage, the motor turns back and forth and it looks like the only error is a PP check failure.

---

<div class="post-metadata">

### Author: ![dekutree64](https://community.simplefoc.com/user_avatar/community.simplefoc.com/dekutree64/32/3398_2.png) [@dekutree64](https://community.simplefoc.com/u/dekutree64)
#### Post date: [April 26, 2025, 8:16am UTC](https://community.simplefoc.com/t/stepper-motor-not-moving-to-target-position/7093/3 "2025-04-26T08:16:32Z")

</div>

Have you tried running in closed loop torque or velocity mode? Angle mode depends on velocity, and velocity depends on torque, so it’s generally easiest to test them in order.
