Orangutan X2 as Stepper Motor Controller

I have an Orangutan X2 with LCD and VHN2 that I am trying to use to drive a stepper motor. The stepper motor has a built in driver with the following pins:11

1 - Direction, 2 - Clock, 3 - On/Off, 4 - MS2, 5 - MS1, 6 - vcc, 7 - gnd. The Microstep resolution Truth Table Indicates Active Stepping if both MS1 and MS2 are Active. I have connected Pin6 to a power source that can supply enough amps and pin 7 to a ground pin in the 3 x 16 I/I header (outside pin row).

The following code activates the motor but never moves it. I am blinking the lights and sending outputs to the display to show that the program is moving. Also, changing the clock delay results in the encoder light flashing at a different frequency, but does not move the motor. Any help on what I am missing would be most appreciated:

void delay_100us( int d )
   for( int i=0; i < d; i++ )
      for ( int j = 0; j <10; j++ )
	  } } }

void motorDriverInit()

    //Initialize PD1 = MS1, PD2 = MS2, PD3 = Direction, PD4 = Clock to outputs

    PORTD |= 1 << PD5;  //Turn the Motor to Active   
    PORTD |= 1 << PD1;  // Turn on the MS1 for Full Stepping
    PORTD |= 1 << PD2;  // Turn on the MS2 for Full Stepping
    PORTD |= 1 << PD3;  // Turn the direction to clockwise      
    PORTD |= 1 << PD4;  // Turn The clock to Active to go one step
    motorStatus = 1;     //the motor is now running

void cycleMotor( )
   if ( motorStatus == 0 )

      PORTD |= 1 << PD4;    //generate a clock signal
      motorStatus = 1;     //the motor is now running


      PORTD &= ~(1 << PD4); //generate a clock signal 

      motorStatus = 0;     //the motor is now running


int main()

     // the X2's user LEDs are located on PORTC, pins C0, C2, C3, C5, and C7
    //  so make these pins outputs to get blinking lights
   DDRC |= (1 << PC0) | (1 << PC2) | (1 << PC3) | (1 << PC5) | (1 << PC7);

    //Initialize PD1 = MS1, PD2 = MS2, PD3 = Direction, PD4 = Clock, PD5 = On/Off  to outputs
    DDRD |= (1 << PD1) | (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5); 

    LCDInit();  // initialize the LCD

    SPIInit();  // initialize communications between the two CPU's

    motorDriverInit( );

	while (1)



            LCDMoveCursor( LCD_ROW_0 );

	LCDAddString( "Counter: " );

	LCDUInt( abs(counter) );  // print the loop number to the display

            LCDMoveCursor( LCD_ROW_1 );
	LCDAddString( "M1 Ch A : " );
            motor1ChannelA_Revs = motor1ChannelA_Revs + encoders_get_counts_m1( ); //abs(encoders_get_counts_m1());
           LCDUInt( abs(motor1ChannelA_Revs) );

           LCDMoveCursor( LCD_ROW_2 );
          LCDAddString( "M2, ChA : " );
         motor2ChannelA_Revs = motor2ChannelA_Revs + abs(encoders_get_counts_m2());
         LCDUInt( abs(motor2ChannelA_Revs) );

         LCDMoveCursor( LCD_ROW_3 );   // get ready to print on the bottom row

         LCDAddString( "GA " );

         LCDUInt (global_last_M1A_val );

        LCDAddString( "GB " );

        LCDUInt (global_last_M1B_val );

        PORTC = 0x01;		// drive PC0 high, all other PORTC outputs low for blinking lights
       //delay_ms(50);		// delay here for 200 ms
      counter = counter + 1; 

     int w = 6;

      cycleMotor( );

     delay_100us( w );

I don’t see anything obviously wrong with your code, and it looks like you already tried running at a much lower frequency. Does your stepper motor hold its position when you run this program, or is it as easy to turn as when it is powered off? Do you have a datasheet for the motor+driver?

If you’re running your X2 off of a separate power source from the motor, do you have both grounds connected to the motor ground pin?


I am powering the X2 and the stepper motor from the same source. Originally they shared the same ground, which resulted in the motor starting up very slowly the first time everything was connected. I then changed the motor’s ground to the X2 pin. This allowed me to toggle the motor on using the controller.

I will see if the motor spins freely when the program is running. I emailed Paul the data sheet. What address can I use to get the sheet to you?



Hello Ken,
Just to make sure, can you describe what the ground of your power source is connected to? If there is not current path back to the power source, it’s not going to turn. Also, you said that the motor originally started up very slowly - does that mean it was working better before?

I’ve attached your datasheet below.

StepperMotorDriver.pdf (728 KB)

Hey Paul,

I originally had both the X2 and the motor grounded to a negative battery terminal. If I disconnected the common lead to the negative terminal and then reconnected it, the motor turned slowly. Also, in this configuration the motor was always on, but aside from the initial connection - it would never turn again until I disconnected and then reconnected the common ground to the battery.

The current configuration is as follows: Both the X2 and the motor are connected to the positive side of the battery. The X2 is grounded to the negative terminal of the battery, and the motor is grounded via an X2 grounding pin (i.e. left most side of 3 x 16 I/O pins). Interestingly enough, the motor energizes when we turn on its on/off pin, and I see a flashing light that corresponds to the clock activation/deactiviation - but the motor does not move at all. I’m sure something is wrong with my wiring setup, but am unsure how to solve it given that I believe the motor needs more amps than the H-bridge will supply. We do have a VNH2 on the board as well but I do not believe that would be useful for supplying power to the stepper motor. Thoughts?

If motor needs a lot of current (how high?), you should really ground it separately to the battery, since the X2’s pins might not be able to handle the amount of current you are trying to put through them. Still, if you are giving the motor power and ground, and you are supplying the correct signals, it should be turning. Can you verify the voltages at each of the signal wires separately with a multimeter or oscilloscope?

Also, which version of the driver do you have? This datasheet describes two versions, one that has the inputs internally pulled low which are activated by driving them high, and one that has the inputs internally pulled high which are activated by driving them low. If you’re not sure you might try driving all of the control pins low in your motorDriverInit() function just to test.


P.S. Yeah, I second the call for grounding the motor directly to your battery pack.

Thanks Adam,

I’ll reconnect the ground to the battery pack and try setting the pins low and let you know how it works.




I’ll get out my meters and scope and see what is going on. Since the motor was getting power from the battery I figured all I had to do was send it the signals. There may be something to setting the pins low vice high. That could explain some of what I am seeing.