Using L293D Motor Driver Shield without any library

Dear Arduino Forum members,

I have newly started learning Arduino for making some personal projects.
I have some computer programming background.
First, I decided to learn controlling motors using Arduino
as I have two bipolar motors from HP Scanjet 3800s.
After searching about these motors I have figured out that
they are Epoch T3508 and their data sheet exists here.
In the internet, I have heard about L293D Motor Driver Shield and purchased one
thinking that I can drive my Epoch T3508 motors with them.

I have coupled this with my Arduino Uno,
and connected a 6V battery to my L293D Shield (and removed the power jumper).
I also made proper connections for my Epoch1 motor to M1+M2 slots of the L293D Shield.
I can run these motors with Stepper Test example supplied by Adafruit Motor shield library.
However, I would like to learn how to give a single step to my motor without using the library.
Which pins should I use to give output for M1+M2 (also if possible M3+M4)?
How can I make a full turn for my Epoch bipolar motor?

I believe this will be a good lesson for me to start with.

Best regards.
bkarpuz

If you go to the Adafruit downloads page for the motor shield, you can get another link to access the schematic for the shield from github.
You should be able to find all the information there (altho' I confess I haven't looked).

johndg, thank you ver much for giving me a direction. I am not an electronics guy but as far as I figured out from the schematics of the shield Driver #1 has to inputs from Arduino called as PWM2A and PWM2B, which are the outputs D11 and D3, respectively.
For Driver #2, I see that they are PWM0A and PWM0B, i.e., D6 and D5, respectively.
Do you think activating these pins will work for me? Do I need to activate other pins such as DIR_EN?
Please teach me which code files in the library I should read to figure this out.

Thank you.
bkarpuz

This is quite a complex project, if you are determined to do your own thing, without a library. The IC is quite straightforward, but working out how the shield works is another thing!
You should learn all you can about the L293D, from the datasheet (which you'll find here) and resources like Adafruit themselves, and this application note. I don't like the schematic - I find it very hard to follow.
You can also look at the Adafruit library. The way to find it is
(top of page) DOCUMENTATION->REFERENCE->(left of page) LIBRARIES->Device Control->Adafruit Motor Shield Library->Read the documentation. This will take you to github. The library code is in AFMotor.cpp. It's quite complicated!
Good luck.

johndg, thank you once again. I extracted one of my L293D from the L293D motor driver shield, and could run my 4 wire stepper forward and backward after placing the L293D on my breadboard, which I believe is a good step for this study. I had lots of cables on the breadboard to have it run. I believe the shield itself has those connections on its circuit. I just need to figure out how the 74HCT595N operates here… So that I can score my goal.

Circuit scheme:
As I have used (4 wire) bipolar stepper motor in my project,
I have connected two joint wires of the bipolar motor to slots of Motor A,
and the other two joint ones to slots of Motor B.

Code for running BP Motor forward:

const int motorPin1  = 5;  // Pin 14 of L293D
const int motorPin2  = 6;  // Pin 10 of L293D
const int motorPin3  = 10; // Pin  7 of L293D
const int motorPin4  = 9;  // Pin  2 of L293D

void setup(){

    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);

}

void loop(){

    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(5);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    delay(5);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(5);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
    delay(5);

}

Code for running BP Motor backward:

const int motorPin1  = 5;  // Pin 14 of L293D
const int motorPin2  = 6;  // Pin 10 of L293D
const int motorPin3  = 10; // Pin  7 of L293D
const int motorPin4  = 9;  // Pin  2 of L293D

void setup(){

    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);

}

void loop(){

    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
    delay(5);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(5);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
    delay(5);
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
    delay(5);

}

bkarpuz:
I just need to figure out how the 74HCT595N operates here... so that I can score my goal.

Well done, that's great progress! They use the shift register to reduce the number of outputs needed from the Arduino.
Here's a library which may help work out how to drive it.

I was so sure that the following code would work. But it did not!

I have placed L293D Motor Driver Shield over my Arduino Uno,
and connected my bipolar motor to M1&M2 slots properly.

I would be very glad if one can show me a direction.

 // Bit positions in the Arduino UNO micro controller output

//#define PWM2B 3
#define DIR_CLK 4 //SHCP
//#define PWM0B 5
//#define PWM0A 6
//#define DIR_EN 7 //OE
#define DIR_SER 8 //DS
//#define PWM1A 9
//#define PWM1B 10
//#define PWM2A 11
#define DIR_LATCH 12 //STCP

// Bit positions in the 74HCT595 shift register output

#define MOTOR3_A 15 //Q0
#define MOTOR2_A 1 //Q1
#define MOTOR1_A 2 //Q2
#define MOTOR1_B 3 //Q3
#define MOTOR2_B 4 //Q4
#define MOTOR4_A 5 //Q5
#define MOTOR3_B 6 //Q6
#define MOTOR4_B 7 //Q7

//Step BPMotor1 connected to M1&M2 by setting the following entries to HIGH, respectively: Q2, Q1, Q3, Q4
//Step BPMotor2 connected to M3&M4 by setting the following entries to HIGH, respectively: Q0, Q5, Q6, Q7

boolean QSeq[8] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int counter = 0;

void PostSeq() {
  digitalWrite(DIR_LATCH, LOW);

  for (int i=7; i>=0; i--)
  {
    digitalWrite(DIR_CLK, LOW);
    digitalWrite(DIR_SER, QSeq[i]);
    digitalWrite(DIR_CLK, HIGH);
  }
  //digitalWrite(DIR_CLK, LOW);
  digitalWrite(DIR_LATCH, HIGH);
}

void setup() {

  pinMode(DIR_SER, OUTPUT);
  pinMode(DIR_LATCH, OUTPUT);
  pinMode(DIR_CLK, OUTPUT);
  //pinMode(PWM2A, OUTPUT);
  //pinMode(PWM2B, OUTPUT);
  //pinMode(DIR_EN, OUTPUT);

}

void loop() {

  Serial.begin(9600);
  Serial.print(counter);
  switch (counter) {
    case 0:
      {
        QSeq[0]=LOW; //HIGH
        QSeq[1]=LOW;
        QSeq[2]=HIGH;
        QSeq[3]=LOW;
        QSeq[4]=LOW;
        QSeq[5]=LOW;
        QSeq[6]=LOW;
        QSeq[7]=LOW;
      }
      break;
    case 1:
      {
        QSeq[0]=LOW;
        QSeq[1]=HIGH;
        QSeq[2]=LOW;
        QSeq[3]=LOW;
        QSeq[4]=LOW;
        QSeq[5]=LOW; //HIGH
        QSeq[6]=LOW;
        QSeq[7]=LOW;
      }
      break;
    case 2:
      {
        QSeq[0]=LOW;
        QSeq[1]=LOW;
        QSeq[2]=LOW;
        QSeq[3]=HIGH;
        QSeq[4]=LOW;
        QSeq[5]=LOW;
        QSeq[6]=LOW; //HIGH
        QSeq[7]=LOW;
      }
      break;
    case 3:
      {
        QSeq[0]=LOW;
        QSeq[1]=LOW;
        QSeq[2]=LOW;
        QSeq[3]=LOW;
        QSeq[4]=HIGH;
        QSeq[5]=LOW;
        QSeq[6]=LOW;
        QSeq[7]=LOW; //HIGH
      }
      break;
  }
  PostSeq();
  delay(300);
  counter = (counter + 1) % 4;

}

bkarpuz:
As I have used bipolar stepper motor in my project,
I have connected two joint wires of the bipolar motor to slots of Motor A,
and the other two joint ones to slots of Motor B.

Think you need a re-think! Don't know why I didn't spot it before but the motors you are using a just DC motors, not stepper motors. You don't get 2-wire stepper motors, unipolar or bipolar (except maybe the tiny ones used in clocks, which are very low torque and designed to run at a single speed). Your 2-wire motors are just DC motors.
One L293D can either drive 4 DC motors unidirectionally, two DC motors bidirectionally, or 1 stepper motor. See the application note I linked in #3.

johndg, I don't know how to draw this scheme on my Linux computer and I got it from somewhere in the internet. And I noted that I did a correct connection with my 4 wire Stepper Motor (wich I call as Bipolar Motor) to the slots of the DC Motors (Motor A and Motor B). There is no problem with my code and circuit setting as they work perfectly. I am working on the stepper motor (Epoch T3508) I have mentioned in my post #1. My problem appears in my last post, where the L293D Motor Diver Shield comes in the play.

When I will learn how to draw this scheme, I will update it in my post #3.

Thank you.
bkarpuz

Ah! I thought the circuit drawing was what you actually had used to wire the motor(s). I'll try to have a proper look at your code later. Did anything happen when you ran it?

johndg,

I have updated the scheme in my post #4.

johndg:
... Did anything happen when you ran it?

About your question, nothing happened.

Thank you.
bkarpuz

Afraid I've been tied up on other things. You may glean something from the video below, at least it's something to look at for a while:

74HC595 & 74HC165 Shift Registers with Arduino - YouTube.

Finally, I could make it work, even for two stepper motors. After reading the AFMotor.h file, I saw that I had to activate the pin DIR_EN for the 74HC595, and the pins PWM0A, PWM0B (these 2 for BPM2=M3&M4), PWM2A and PWM2B (these 2 for BPM1=M1&M2). I am sharing my code for those who may need it.

johndg, thank you very much for your time and and your guidance for directing me to the correct files,
which eventually lead me to the solution.

Here is a picture of the circuit:


Here is the link for a video:

//Bit positions in the Arduino UNO micro controller output

#define PWM2B 3 //For slots M1&M2 on the L293D Motor Shield
#define DIR_CLK 4 //SHCP of the Shift Register 74HC595
#define PWM0B 5 //For slots M3&M4 on the L293D Motor Shield
#define PWM0A 6 //For slots M3&M4 on the L293D Motor Shield
#define DIR_EN 7 //OE of the Shift Register 74HC595
#define DIR_SER 8 //DS of the Shift Register 74HC595
#define PWM1A 9 //For slots SERVO1&SERVO3 on the L293D Motor Shield
#define PWM1B 10 //For slots SERVO1&SERVO3 on the L293D Motor Shield
#define PWM2A 11 //For slots M1&M2 on the L293D Motor Shield
#define DIR_LATCH 12 //STCP of the Shift Register 74HC595

//Bit positions in the 74HCT595 shift register output

#define MOTOR3_A 15 //Q0
#define MOTOR2_A 1 //Q1
#define MOTOR1_A 2 //Q2
#define MOTOR1_B 3 //Q3
#define MOTOR2_B 4 //Q4
#define MOTOR4_A 5 //Q5
#define MOTOR3_B 6 //Q6
#define MOTOR4_B 7 //Q7

//Step BPMotor1 connected to M1&M2 by setting the following entries to HIGH, respectively: Q2=4, Q1=2, Q3=8, Q4=16
//Step BPMotor2 connected to M3&M4 by setting the following entries to HIGH, respectively: Q0=1, Q5=32, Q6=64, Q7=128

int BPMotor1Seq[4]={4,2,8,16}; //Sequence for BPM1 for forward 4 steps
int BPMotor2Seq[4]={1,32,64,128}; //Sequence for BPM2 for forward 4 steps
int stepperval;
int stepper1val;
int stepper2val;
int qcounter = 0;
int hcounter = 0;
int hmax=1500;

void setup() {

  pinMode(DIR_EN, OUTPUT);
  pinMode(DIR_SER, OUTPUT);
  pinMode(DIR_LATCH, OUTPUT);
  pinMode(DIR_CLK, OUTPUT);
  pinMode(PWM0A, OUTPUT);
  pinMode(PWM0B, OUTPUT);
  digitalWrite(PWM0A, HIGH);
  digitalWrite(PWM0B, HIGH);
  pinMode(PWM2A, OUTPUT);
  pinMode(PWM2B, OUTPUT);
  digitalWrite(PWM2A, HIGH);
  digitalWrite(PWM2B, HIGH);

}

void loop() {

  if (hcounter<(hmax/4)) {
    SetBPMotor1CW();
    SetBPMotor2CW();
  } else if (hcounter<(hmax/2)) {
    SetBPMotor1CCW();
    SetBPMotor2CW();
  } else if (hcounter<(3*hmax/4)) {
    SetBPMotor1CCW();
    SetBPMotor2CCW();
  } else {
    SetBPMotor1CW();
    SetBPMotor2CCW();
  }

  stepperval=stepper1val+stepper2val;
  digitalWrite(DIR_LATCH, LOW);
  shiftOut(DIR_SER, DIR_CLK, MSBFIRST, stepperval);
  digitalWrite(DIR_LATCH, HIGH);
  delay(20);
  qcounter = (qcounter + 1) % 4;
  hcounter = (hcounter + 1) % hmax;

}

void SetBPMotor1CW() {

  stepper1val=BPMotor1Seq[qcounter];

}

void SetBPMotor1CCW() {

  stepper1val=BPMotor1Seq[3-qcounter];

}

void SetBPMotor2CW() {


  stepper2val=BPMotor2Seq[qcounter];

}

void SetBPMotor2CCW() {

  stepper2val=BPMotor2Seq[3-qcounter];

}