Running two motors daisy-chained simple motor controller


I am trying to run two motors using an arduino mega and pololu simple motor controller. I am stuck and need assistance. I was able to use one motor but now i want to control individual motors. I am not an expert on this and could use some help. I tried using the example code and tweaking it but i cant get it to work :’( please help ASAP

#include <SoftwareSerial.h>
#define rxPin 0  // pin 0 connects to smcSerial TX  (not used in this example)
#define txPin 1  // pin 1 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed, unsigned char deviceId) 
  Serial.write(0xAA); // first byte of Pololu protocol
  Serial.write(deviceId); // determine which controller gets the command

  if (speed < 0) 
    Serial.write(0x06); // Pololu protocol version of motor reverse command 
    speed = -speed; // make speed positive 
    Serial.write(0x05); // Pololu protocol version of motor forward command 
  Serial.write((unsigned char)(speed & 0x1F)); 
  Serial.write((unsigned char)(speed >> 5));
void setup()
  // initialize software serial object with baud rate of 19.2 kbps
  // the Simple Motor Controller must be running for at least 1 ms
  // before we try to send serial data, so we delay here for 5 ms
  // if the Simple Motor Controller has automatic baud detection
  // enabled, we first need to send it the byte 0xAA (170 in decimal)
  // so that it can learn the baud rate
  smcSerial.write(0xAA);  // send baud-indicator byte
  // next we need to send the Exit Safe Start command, which
  // clears the safe-start violation and lets the motor run
  exitSafeStart();  // clear the safe-start violation and let the motor run
void loop()
  setMotorSpeed(3200, 0xb);  // full-speed forward for controller 0xb
  setMotorSpeed(3200, 0xd);  // full-speed forward for controller 0xd

  delay(20000);  // wait for 2 seconds

  setMotorSpeed(-3200, 0xb);  // full-speed reverse for controller 0xb
  setMotorSpeed(-3200, 0xd);  // full-speed reverse for controller 0xd

  delay(20000);  // wait for 2 seconds


What do you mean when you say it is not working? Could you tell me what you expect to happen and what is actually happening? Could you please post pictures of your setup showing all your connections? Have you configured each motor controller with the IDs used in your code? Also, could you please post working code for controlling only one motor, so I can suggest modifications for controlling two motors?