Wiring help

i need help with the wiring of a DRV8833 to encoder motor using arduino. For the motor, where do I plug in the encoder A and B?

On whatever pins your program expects them to be on.

That link is to nosy for me.
Google brings this: https://www.ti.com/lit/df/tidrmq3a/tidrmq3a.pdf?ts=1615759938716&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FDRV8833

where do I plug in the encoder A and B?

codewriter123, the DRV8833 seems to be an open loop speed controller(no encoder inputs).
the encoder A and B wires would go to Arduino's interrupt pins with that speed controller.

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0

To help with reading your post, please attach your images, rather than using an off forum site.
OPs image.


Thanks.. Tom.. :slight_smile:

Ah, image, that's helpful.

Encoder wires connect to the Arduino, not to the motor driver.

TomGeorge:
To help with reading your post, please attach your images, rather than using an off forum site.

Off forum sites are perfectly fine - as long as they are reliable and not obfuscating (which does exclude quite a few).

OP's image, hosted on "imgur" and directly linked:

Expand

As Tom found ... and then downloaded ... and attached ... and the forum inlined ... :roll_eyes:

Hi,
The problem with directly linking is if the OP removes the image from the link source, the image on the forum is also removed, possibly making the thread useless.

Tom.... :slight_smile:

I'm trying to wire it to the motor encoders, but nothing is happening once the code is ran
I have a 9V going t the GND and VIN

Help! What am I doing wrong?

int E1 = 4; //MOTOR_1
int M1 = 5; //MOTOR_1
int E2 = 7; //MOTOR_2
int M2 = 8; //MOTOR_2

const byte encoder0pinA = 2; //A pin ->interrupt pin 0
const byte encoder0pinB = 3; //B pin ->digital pin 8
byte encoder0PinALast;
int duration;//the number of the pulses
boolean Direction; //the roration direction

void setup() {
  Serial.begin(57600); //Initialize the serial port
  EncoderInit(); //Initialize the module

  pinMode(M1,OUTPUT);
  pinMode(M2,OUTPUT);

  digitalWrite(M1,LOW);
  analogWrite(E1,100);

  digitalWrite(M2,HIGH);
  analogWrite(E2,250);
}
void loop()
{
  Serial.print("Pulse");
  Serial.println(duration);
  duration=0;
  delay(100);
}

void EncoderInit()
{
  Direction = true; //Default ->Forward
  pinMode(encoder0pinB,INPUT);
  attachInterrupt(0, wheelSpeed, CHANGE);
}

void wheelSpeed()
{
  int Lstate = digitalRead(encoder0pinA);
  if((encoder0PinALast == LOW) && Lstate == HIGH)
  {
    int val = digitalRead(encoder0pinB);
    if(val == LOW && Direction)
    {
      Direction = false; //Reverse
    }
    else if(val ==HIGH && !Direction)
    {
      Direction = true; //Forward
    }
  }
  encoder0PinALast = Lstate;

  if(!Direction)  duration++;
  else duration--;
}

9 volt at Vin... Where does that 9 volt come from, what kind of source?

my bad, I didn't attach he picture

Capture1.JPG

Capture1.JPG

That' may be the reason for the trouble. There is not a nuclear power station in that little battery. There are no amps to get, only some 20-30 mA at the most.
What powers the motor and its Vcc?

A 9V battery like that won't be able to run your motors. The lack of input and output capacitors with that 7805 means it's probably not working well, either.

To make matters worse, based on the image you posted in #8 your motors do not even have a power source to run of...

Power source to run from? Is that needed when there's faith and belief? I'm joking.

I was trying to follow this video on youtube. The title is: Control DC MOTOR + Encoder with DC Motor Shield for Arduino - DFRobot

He uses a different module, but he was mentioning where to plug the encoder.
How can I fix my diagram?
For the power source, I connected it to the 5V on the arduino

Post a real wiring diagram so we can see what changes might be needed.

Posted below. I drew everything by hand. Let me know if this make sense. I was following that video title I posted earlier.
This is the motor I'm using: Pololu - 20.4:1 Metal Gearmotor 25Dx65L mm LP 6V with 48 CPR Encoder

int E1 = 4; //MOTOR_1
int M1 = 5; //MOTOR_1
int E2 = 7; //MOTOR_2
int M2 = 8; //MOTOR_2

const byte encoder0pinA = 2; //A pin ->interrupt pin 0
const byte encoder0pinB = 3; //B pin ->digital pin 3
byte encoder0PinALast;
int duration;//the number of the pulses
boolean Direction; //the roration direction

void setup() {
  Serial.begin(57600); //Initialize the serial port
  EncoderInit(); //Initialize the module

  pinMode(M1,OUTPUT);
  pinMode(M2,OUTPUT);

  digitalWrite(M1,LOW);
  analogWrite(E1,100);

  digitalWrite(M2,HIGH);
  analogWrite(E2,250);
}
void loop()
{
  Serial.print("Pulse");
  Serial.println(duration);
  duration=0;
  delay(100);
}

void EncoderInit()
{
  Direction = true; //Default ->Forward
  pinMode(encoder0pinB,INPUT);
  attachInterrupt(0, wheelSpeed, CHANGE);
}

void wheelSpeed()
{
  int Lstate = digitalRead(encoder0pinA);
  if((encoder0PinALast == LOW) && Lstate == HIGH)
  {
    int val = digitalRead(encoder0pinB);
    if(val == LOW && Direction)
    {
      Direction = false; //Reverse
    }
    else if(val ==HIGH && !Direction)
    {
      Direction = true; //Forward
    }
  }
  encoder0PinALast = Lstate;

  if(!Direction)  duration++;
  else duration--;
}

Very readable! Technically the controller and motors have no power supplied. But the drawing is excellent.

for now I was powering the arduino with my laptop, and from there the 5v and so on. I have a portable battery too that should work as well. I;m using LiPo too, but just my laptop for now. Would that be why?

The motor is attached to the 5V from the arduino

one of the motors is working. The serialprint prints a constant Pulse0, no any other numbers (sometimes Pulse-1)
only one is moving, the other is not.

so basically, I couldn't get the encoders working