Issue with DC Motors, ESP32, and TB6612 Motor Driver

Hello,

When I execute “motor2.drive(255,10000);” in the sketch, motor2 works fine.

When I execute “forward(motor1, motor2);” in the sketch, both motors work fine.

When I execute “back(motor1, motor2);” in the sketch, only motor1 moves.

It seems when I attempt to distribute power to both motors outside of the forward command, only motor1 will operate.

Any assistance is welcomed. I have attached both a wiring diagram and the sketch for reference. Thanks in advance.

#include <SparkFun_TB6612.h>

// Pins for all inputs, keep in mind the PWM defines must be on PWM pins
// the default pins listed are the ones used on the Redbot (ROB-12097) with
// the exception of STBY which the Redbot controls with a physical switch
#define AIN1 14
#define BIN1 26
#define AIN2 12
#define BIN2 25
#define PWMA 13
#define PWMB 33
#define STBY 9

// these constants are used to allow you to make your motor configuration 
// line up with function names like forward.  Value can be 1 or -1
const int offsetA = 1;
const int offsetB = 1;

// Initializing motors.  The library will allow you to initialize as many
// motors as you have memory for.  If you are using functions like forward  
// that take 2 motors as arguements you can either write new functions or
// call the function more than once.

Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);

void setup()
{
motor_sequence();

}


void loop()
{
   
} 

void motor_sequence(){
  
    
       //motor2.drive(255,10000);
    back(motor1, motor2);
    // right(motor1, motor2, 100); 
   
   
}

You need to attache the code using code tags, the symbol up to the left in this window. That makes the code appear in a little scrollable window together with text and other info.
By some reason my Pc refuces to download the code.
The electrical diagram looks okey soo faar.

code tags do this

#include <SparkFun_TB6612.h>

// Pins for all inputs, keep in mind the PWM defines must be on PWM pins
// the default pins listed are the ones used on the Redbot (ROB-12097) with
// the exception of STBY which the Redbot controls with a physical switch
#define AIN1 14
#define BIN1 26
#define AIN2 12
#define BIN2 25
#define PWMA 13
#define PWMB 33
#define STBY 9

// these constants are used to allow you to make your motor configuration 
// line up with function names like forward.  Value can be 1 or -1
const int offsetA = 1;
const int offsetB = 1;

// Initializing motors.  The library will allow you to initialize as many
// motors as you have memory for.  If you are using functions like forward  
// that take 2 motors as arguements you can either write new functions or
// call the function more than once.

Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);

void setup()
{
motor_sequence();

}


void loop()
{
   
} 

void motor_sequence(){
  
    
       //motor2.drive(255,10000);
    back(motor1, motor2);
    // right(motor1, motor2, 100); 
   
   
}

Hey, hey, hey….. Setup is only ran once, at startup! Then loop() takes over the action! Your loop() does nothing!
You get the idea?

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Ops diag.

It would be best to post diagrams as jpg files.

Thanks... Tom.... :slight_smile:

Thanks for the posting tips everyone. My goal is to program the robot to move based on a series of commands then stop. I have no desire for it to loop. My concern is that there might not be enough power to support what the code is requiring. Could the ESP32 controller and both motors be consuming to much power? Here is a link to the motors. https://www.amazon.com/Adafruit-DC-Gearbox-Motor-TT/dp/B07JXZ6TX8

Hi,
What value are the capacitors at the 3V3 regulator?

Tom... :slight_smile:

Thanks Tom.

Here are the links to the voltage regulator and capacitors.

Capacitors (2)

Voltage Regulator

I'd supply 5V to the ESP32 and let the internal regulators do all the work.

I found that the MCPWM, a built in motor controller to the ESP32, works quite well to control motors, without the need for an external module.

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/mcpwm.html

And powering from a 9V battery causes more issues then it solves.

Hi,
Do you have a DMM?

Tom... :slight_smile:

Yes Tom. What should I check?

Idahowalker:
I'd supply 5V to the ESP32 and let the internal regulators do all the work.

I found that the MCPWM, a built in motor controller to the ESP32, works quite well to control motors, with out the need for an external module.

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/mcpwm.html

And powering from a 9V battery causes more issues then it solves.

It still needs an external motor driver.
The built in motor controller cannot drive a motor.
mcpwm-brushed-dc-control.png
Tom... :slight_smile:

mcpwm-brushed-dc-control.png

Maybe I'm not on alert but I don't find any info about Your pwr supply. It's hardly a nuclear powerplant, but what type is it?

The power is being supplied by a 9v battery.

A 6f..... ?

The 9v battery powers the TB6612 Motor Driver which powers the ESP32 board.

Yes, but my question was what kind of 9 volt battory? Is the one having to 2 circular connectors beside each other at the short end? Send a picture of it.
If so..... That is a battory that supplies voltage but absolutely not current enough.

Ah yes!!! Two circular!!! Any suggestions on how to supply enough current for both motors? Thank you in advance.

Okey, that's the reason for the problems. That battory can be used in low pwr applicatiions like fire alarms, remote controls but defenatly not for motors.

I looked through all answers and I advice You to read answers #6, #8 and #11 again.

Get a power supply good enough for both motors running at maximum load. Check motor specs. Maybe You can use a step down converter, fed from the motor supply, to produce +5v, or +3.3v for the controller etc. Else, get a separate pwr supply for the controller and its near circuitry.

Thank you for your advice. You and everyone else who answered have been of tremendous assistance.