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.
#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);
}
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?
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
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.
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.