Here is the code I used to make sure the setup worked as exected.
///////////////////
// h bridge test //
///////////////////
int enablePin1 = 10; // Enable for Motor 1
int enablePin2 = 11; // Enable for Motor 2
int motor1Pin = 2; // Motor1A
int motor2Pin = 3; // Motor1B
int motor3Pin = 4; // Motor2A
int motor4Pin = 5; // Motor2B
void setup() {
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
digitalWrite(enablePin1, HIGH); //comment line if enable pins are tied to Vcc
digitalWrite(enablePin2, HIGH); //comment line if enable pins are tied to Vcc
}
void loop() {
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
delay(2500);
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
delay(2500);
}
Here is PWM test code
const int motorAPin1 = 8; // AIN1
const int motorAPin2 = 9; // AIN2
const int motorBPin1 = 10; // BIN1
const int motorBPin2 = 11; // BIN2
const int enablePin = 2; // H-bridge enable pin
const int ledPin = 13; // LED
const int PWMA = 3; // Pulse Width Modulation Motor A
const int PWMB = 5; // Pulse Width Modulation Motor B
void setup() {
// set outputs:
pinMode(motorAPin1, OUTPUT);
pinMode(motorAPin2, OUTPUT);
pinMode(motorBPin1, OUTPUT);
pinMode(motorBPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
}
void loop() {
analogWrite(motorAPin1, LOW);
analogWrite(motorAPin2, HIGH);
analogWrite(motorBPin1, LOW);
analogWrite(motorBPin2, HIGH);
analogWrite(PWMA, 60);
}
My main problem is understanding how to use the motor library to drive an h-bridge with 2 motors.
I'm new to mbed and so far I love it, but i'm used to the simpler Arduino. Any pointers would be helpful.
P.S. Using L293 h-bridge and two small 6v motors for testing.