Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

L293 H-Bridge Problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

L293 H-Bridge Problem

by submicro on Tue Sep 14, 2010 6:42 pm

I'm using an L293 h-bridge with two Mabuchi toy motors. When I send both motors the forward command it works but when In try and reverse, one reverses the other stops!

I have checked, double, triple, checked my wiring, and code. I have two L293's both behave the same. I just got two L298's I'm gonna try as soon as I figure out how to plug them in the breadboard!

I also just ordered a Baby Orangutan to try since it has built in h-bridge.

The motors are the ones that come with Tamiya's twin motor gear box kit.
The controller is an Arduino.

Here is the code used to test the H-Bridge
Code: Select all | TOGGLE FULL SIZE
 ///////////////////
  // h bridge test //
  ///////////////////
 
  const int switchPin = 7;    // switch input
  const int enablePin1 = 10;    // Enable for Motor 1
  const int enablePin2 = 11;    // Enable for Motor 2
  const int motor1Pin = 2;    // H-bridge leg 1 (pin 2, 1A)
  const int motor2Pin = 3;    // H-bridge leg 2 (pin 7, 2A)
  const int motor3Pin = 4;    // H-bridge leg 3 (pin 10, 3A)
  const int motor4Pin = 5;    // H-bridge leg 4 (pin 15, 4A)
  const int ledPin = 13;      // LED
 
 
  void setup() {
    // set the switch as an input:
    pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:
    pinMode(enablePin1, OUTPUT);
    pinMode(enablePin2, OUTPUT);
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(motor3Pin, OUTPUT);
    pinMode(motor4Pin, OUTPUT);
    pinMode(ledPin, OUTPUT);

    // set enablePin high so that motor can turn on:
    // digitalWrite(enablePin1, HIGH); //Uncomment if enable pins are not tied to Vcc
    // digitalWrite(enablePin2, HIGH); //Uncomment if enable pins are not tied to Vcc
    digitalWrite(switchPin, HIGH); // Enable internal pull up restor
    // blink the LED 3 times. This should happen only once.
    // if you see the LED blink three times, it means that the module
    // reset itself,. probably because the motor caused a brownout
    // or a short.
    blink(ledPin, 3, 100);
  }

  void loop() {
     
     
   
    // if the switch is high, motor will turn on one direction:
   
    if (digitalRead(switchPin) == HIGH) {
      digitalWrite(motor1Pin, LOW);   // set leg 1A of the H-bridge low
      digitalWrite(motor2Pin, HIGH);  // set leg 2A of the H-bridge high
      digitalWrite(motor3Pin, LOW);   // set leg 1B of the H-bridge low
      digitalWrite(motor4Pin, HIGH);  // set leg 2B of the H-bridge high
    }
    // if the switch is low, motor will turn in the other direction:
    else {
      digitalWrite(motor1Pin, HIGH);  // set leg 1A of the H-bridge high
      digitalWrite(motor2Pin, LOW);   // set leg 2A of the H-bridge low
      digitalWrite(motor3Pin, HIGH);   // set leg 1B of the H-bridge low
      digitalWrite(motor4Pin, LOW);  // set leg 2B of the H-bridge high
    }
  }

  /*
    blinks an LED
   */
  void blink(int whatPin, int howManyTimes, int milliSecs) {
    int i = 0;
    for ( i = 0; i < howManyTimes; i++) {
      digitalWrite(whatPin, HIGH);
      delay(milliSecs/2);
      digitalWrite(whatPin, LOW);
      delay(milliSecs/2);
    }
  }


Ok as soon as I figure out how to post pics I'll post a pic of how it's wired

TIA

SubMicro

submicro
 
Posts: 3
Joined: Tue Sep 14, 2010 6:39 pm

Re: L293 H-Bridge Problem

by franklin97355 on Tue Sep 14, 2010 9:25 pm

Swap the motors and see if the problem follows the motor or the H-bridge connections.

franklin97355
 
Posts: 21498
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: L293 H-Bridge Problem

by pstemari on Wed Sep 15, 2010 2:47 am

It's probably overheating the L293--I had exactly the same problem on that gearbox, which I solved by only putting one motor on each H-bridge (this is with the Adafruit motor shield). Put your finger on the chip--is it getting warm?

Gradual acceleration and deceleration also helps a lot. You don't get a ton of stall-level current if you ramp up from a 25% duty cycle (i.e. analogWrite(64)) up to 100% over a second or two, e.g.

Code: Select all | TOGGLE FULL SIZE
   speed++;  // or speed--
   left_motor.setSpeed(speed);
   right_motor.setSpeed(speed);
   delay(10);


somewhere in the main loop.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 310
Joined: Sun Mar 21, 2010 6:10 pm
Location: Seattle, WA

Re: L293 H-Bridge Problem

by submicro on Wed Sep 15, 2010 10:35 am

Thanx for the tips

Swapping motors didn't help.

The motors aren't running long enough to get the chip hot, but I'll try using two L293's

What library goes with that code snippet?

submicro
 
Posts: 3
Joined: Tue Sep 14, 2010 6:39 pm

Re: L293 H-Bridge Problem

by submicro on Wed Sep 15, 2010 12:16 pm

Ok somethings off, it has to be a simple error on my part. I added a second L293 and got the same problem when I try and reverse, one reverses the other stops........hmmmmmmm

submicro
 
Posts: 3
Joined: Tue Sep 14, 2010 6:39 pm

Re: L293 H-Bridge Problem

by zener on Wed Sep 15, 2010 8:20 pm

Double check all your wiring. Easy to swap a couple of pins here or there. Ask me how I know...

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Please be positive and constructive with your questions and comments.