# Two 36v4 Drivers with Arduino mega

**URL:** https://forum.pololu.com/t/two-36v4-drivers-with-arduino-mega/21906
**Category:** Motor controllers/drivers and motors
**Created:** [August 11, 2021, 1:36pm UTC](https://forum.pololu.com/t/two-36v4-drivers-with-arduino-mega/21906 "2021-08-11T13:36:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Madmax](https://forum.pololu.com/letter_avatar_proxy/v4/letter/m/8baadc/32.png) [@Madmax](https://forum.pololu.com/u/Madmax)
#### Post date: [August 11, 2021, 1:36pm UTC](https://forum.pololu.com/t/two-36v4-drivers-with-arduino-mega/21906/1 "2021-08-11T13:36:25Z")

</div>

Dear Pololu team,  
I would like to control 2 stepper motor (Two "36v4 "pololu drivers)with 1 arduino mega.  
my question is how to initialise the two drivers and the pin assignment .  
this code work fine for only one driver :

```auto
#include <SPI.h>
#include <HighPowerStepperDriver.h>

const uint8_t CSPin = 49;

// This period is the length of the delay between steps, which controls the
// stepper motor's speed. You can increase the delay to make the stepper motor
// go slower. If you decrease the delay, the stepper motor will go faster, but
// there is a limit to how fast it can go before it starts missing steps.
const uint16_t StepPeriodUs = 2000;

HighPowerStepperDriver sd;

void setup()
{
  SPI.begin();
  sd.setChipSelectPin(CSPin);

  // Give the driver some time to power up.
  delay(1);

  // Reset the driver to its default settings and clear latched status
  // conditions.
  sd.resetSettings();
  sd.clearStatus();

  // Select auto mixed decay. TI's DRV8711 documentation recommends this mode
  // for most applications, and we find that it usually works well.
  sd.setDecayMode(HPSDDecayMode::AutoMixed);

  // Set the current limit. You should change the number here to an appropriate
  // value for your particular system.
  sd.setCurrentMilliamps36v4(1000);

  // Set the number of microsteps that correspond to one full step.
  sd.setStepMode(HPSDStepMode::MicroStep32);

  // Enable the motor outputs.
  sd.enableDriver();
}

void loop()
{
  // Step in the default direction 1000 times.
  sd.setDirection(0);
  for(unsigned int x = 0; x < 1000; x++)
  {
    sd.step();
    delayMicroseconds(StepPeriodUs);
  }

  // Wait for 300 ms.
  delay(300);

  // Step in the other direction 1000 times.
  sd.setDirection(1);
  for(unsigned int x = 0; x < 1000; x++)
  {
    sd.step();
    delayMicroseconds(StepPeriodUs);
  }

  // Wait for 300 ms.
  delay(300);
}

```

how can i customise this code for 2 drivers  
what happens for the (MISO MOSI SCK)pins ?  
how does Arduino uni recognise the parameter pins for the two drivers?  
thanks for the support  
\<3

---

<div class="post-metadata">

### Author: ![PatrickM](https://forum.pololu.com/user_avatar/forum.pololu.com/patrickm/32/7800_2.png) [@PatrickM](https://forum.pololu.com/u/PatrickM)
#### Post date: [August 11, 2021, 7:15pm UTC](https://forum.pololu.com/t/two-36v4-drivers-with-arduino-mega/21906/2 "2021-08-11T19:15:40Z")

</div>

Hello.

I suggest checking out this [“Two 36v4 drivers and two stepper motors”](https://forum.pololu.com/t/two-36v4-drivers-and-two-stepper-motors/18691) thread which includes an example program I wrote for controlling two of our [High-Power Stepper Motor Drivers](https://www.pololu.com/product/3730) with our Arduino library.

The SPI interface pins are shared between the two drivers except for SCS, the SPI chip select input.

I am not sure what you mean by the “parameter pins”, but if looking at the other thread does not answer that question, please elaborate what specific pins you mean and I should be able to explain.

- Patrick
