I'm using the arduino nano with the TB6612FNG motor driver.
Here is the code i am running:
#include <SparkFun_TB6612.h>
Motor motor1{3, 4, 5, 1, 9};
Motor motor2{7, 8, 6, 1, 9};
uint8_t pwmSpeed;
void setup() {
Serial.begin(9600);
}
char recv{};
void loop() {
if(Serial.available() > 0){
recv = Serial.read();
pwmSpeed = analogRead(A4) / 4;
switch(recv){
case 's':
Stop();
break;
case 'f':
forward();
break;
case 'b':
back();
break;
case 'r':
right();
break;
case 'l':
left();
break;
}
Serial.println("Received input");
}
}
void forward() {
forward(motor1, motor2, pwmSpeed);
}
void back() {
forward(motor1, motor2, -pwmSpeed);
}
void left() {
motor1.drive(-pwmSpeed);
motor2.drive(pwmSpeed);
}
void right() {
motor1.drive(pwmSpeed);
motor2.drive(-pwmSpeed);
}
void Stop() {
brake(motor1, motor2);
}
Everything works well except the back() and right(), where motor2.drive() has a negative value (running backwards)
I have two of these drivers and i tried with both, and the problem is still there.
And when i switch the two motors, the one connected to A1 and A2 is still the motor which does not work
Can someone help me please