Hi!
I am trying to use a pololu TB67H420FTG to drive a 12v motor with encoder however nothing is happening when I run the arduino sketch. I am following a tutorial and I am not sure if my problem is in the software or the hardware, so code and pictures are attached. Any help would be amazing.
Code:
#define ENCA 2 // Yellow
#define ENCB 3 // White
#define PWM 5
#define IN2 6
#define IN1 7
int pos = 0;
void setup() {
Serial.begin(9600);
pinMode(ENCA, INPUT);
pinMode(ENCB, INPUT);
attachInterrupt(digitalPinToInterrupt(ENCA),readEncoder,RISING);
}
void loop() {
setMotor(1,25,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
setMotor(-1,25,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
setMotor(0,25,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
}
void setMotor(int dir, int pwmVal, int pwm, int in1, int in2){
analogWrite(pwm,pwmVal);
if(dir == 1){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
}
else if(dir == -1){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
else {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
}
void readEncoder(){
int b = digitalRead(ENCB);
if(b>0){
pos++;
}
else{
pos--;
}
}
Hardware + Wiring: