Pololu BD65496MUV DC Driver


I'm relatively new to using DC motors with encoders on Arduino, but I bought the following products to use on a Due:

Pololu 4756 DC Motor

BD65496MUV DC Driver

Can anyone help me with the general setup with the encoder? I understand the truth table provided on the BD65496MUV Datasheet but I'm sure how the pinout will work with both components.

Attached is the code we have so far. Most of it is commented out because we just found a few examples, but don't understand them. If someone could help with the encoder code to create a more accurate rotation, that would be amazing!!


// Motor pin connections 
//#define encodPinA1   // encoder A pin yellow wire (both encoder numbers are according to arduinio wiring 
//#define encodePinB1   // encoder B pin white wire 
//#define InA1 12// INA motor pin red motor wire conncets to one motor terminal 
//#define InB1 13 //InB motor pin black wire conncets to motor terminal 2 

//#define LOOPTIME        100                     // PID loop time
//#define FORWARD         1                       // direction of rotation
//#define BACKWARD        2                       // direction of rotation

//int encodPinA1 =12 //whavever pin number
//int encodPinA2 = 13
//volatile long encoderValue = 0; // Raw encoder value
//int PPR = 1600;  // Encoder Pulse per revolution.
//int angle = 360; // Maximum degree of motion.
//int REV = 0;          // Set point REQUIRED ENCODER VALUE
//int lastMSB = 0;
//int lastLSB = 0;
//double kp = 5 , ki = 1 , kd = 0.01;             // modify for optimal performance
//double input = 0, output = 0, setpoint = 0;
//PID myPID(&input, &output, &setpoint, kp, ki, kd, DIRECT);
//unsigned long lastMilli = 0;                    // loop timing
//unsigned long lastMilliPrint = 0;               // loop timing
//long count = 0;                                 // rotation counter
//long countInit;
//long tickNumber = 0;
//boolean run = false;                                     // motor moves

// Function for motor spinning direction 

// Turining on motor 

// Set Motor Speed 

// Accelerate motor from zero to max speed

//void setup() {

  // motor control pin to outputs declarartion of position control 
//pinMode(InA1, OUTPUT);
//pinMode(InB1, OUTPUT);
//pinMode(encodPinA1, INPUT_PULLUP);
//pinMode(encodPinB1, INPUT_PULLUP);
//pinMode(2, INPUT); //input_pullup?
//pinMode(3, INPUT);
//last_read = digitalRead(3) << 1 | digitalRead(2);
// interrupt 0 is for pin 2
//attachInterrupt(0, InA1, CHANGE);
// interrupt 1 is for pin 3
//attachInterrupt(1, InB1, CHANGE);
// turning off motor - initial state 
//digitalWrite(encodPinA1, LOW);
//digitalWrite(encodePinB1, LOW);
// turning on motor/ pull up resistor

// Is this really needed? 
//void encoder_read()
  // uint8_t encoderRead = 0;
  //encoderRead = digitalRead(3) << 1 | digitalRead(2);
  //if(encoderRead == last_read)
  //if(bitRead(encoderRead, 0) == bitRead(last_read, 1))
   // quad -= 1;
 // else
    //quad += 1;
  //last_read = encoderRead; 

//void loop() {
// moveMotor(FORWARD, 50, 1200*2);                        // direction, PWM, ticks number
// delay(5000);
 //moveMotor(BACKWARD, 100, 2400*2);                           // 464=360°

//void moveMotor(int direction, int PWM_val, long tick)  {
 //countInit = count;    // abs(count)
 //tickNumber = tick;
 //if(direction==FORWARD)          motorForward(PWM_val);
 //else if(direction==BACKWARD)    motorBackward(PWM_val);

//void rencoder()  {                                    // pulse and direction, direct port reading to save cycles
 //if (encodPinB1 & 0b00000001)    count++;                  // if(digitalRead(encodPinB1)==HIGH)   count_r ++;
 //else                      count--;                  // if (digitalRead(encodPinB1)==LOW)   count_r --;
// if(run)  
 //  if((abs(abs(count)-abs(countInit))) >= tickNumber)      motorBrake();

//void motorForward(int PWM_val)  {
 //analogWrite(PWM1, PWM_val);
// digitalWrite(InA1, LOW);
// digitalWrite(InB1, HIGH);
// run = true;

//void motorBackward(int PWM_val)  {
// analogWrite(PWM1, PWM_val);
 //digitalWrite(InA1, HIGH);
 //digitalWrite(InB1, LOW);
 //run = true;

//void motorBrake()  {
 //analogWrite(PWM1, 0);
 //digitalWrite(InA1, HIGH);
 //digitalWrite(InB1, HIGH);
 //run = false;

int pin12=12;           //Direction control pins
int pin13=13;           //Direction control pins

void setup(){

pinMode(pin12,OUTPUT); //Arduino Pin#7 as Output 
pinMode(pin13,OUTPUT); //Arduino Pin#8 as Output 

void loop(){

digitalWrite(pin12,HIGH);   //Pin#7 as High
digitalWrite(pin13,LOW);    //Pin#8 as Low
delay(2000);               //Delay 4 seconds Motor rotates in clock wise direction
digitalWrite(pin12,LOW);    //Pin#7 as Low
digitalWrite(pin13,LOW);    //Pin#8 as Low 
delay(2000);               //Delay 3 seconds Motor halts
digitalWrite(pin12,LOW);   //Pin#8 as High
digitalWrite(pin13,HIGH);    //Pin#7 as Low
delay(2000);               //Delay for 4 seconds Motor rotates in anti clock wise direction
digitalWrite(pin12,LOW);    //Pin#7 as Low
digitalWrite(pin13,LOW);    //Pin#8 as Low
delay(2000);               //Delay for 2 seconds Motor halts

wireharnessdc.ino (5.26 KB)

More members will see your code if you post your code as described in the forum guidelines.

Got it! Any chance you could help with the code? :slight_smile:

Have you written test code that to just read the encoder if you turn the motor by hand?

Does the code to just test the motor work?

Can you post a schematic of the wiring and photos of the wiring? A schematic shows how it should be connected, the photo shows how it is connected.

This Pololu page has some information on using the encoder.

The Encoder library may be helpful.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.