I am very confused on this.
I’m using this motor: DC 12v Motor
This is the motor driver: TB67H420FTG
I know the motor works. I’m using an Arduino Nano 33 IoT, and I know it works. I can read encoder values from the motor and when I physically power the motor, it powers up and the encoder value is updated like you’d expect. The problem arises when I try to have the driver send power to the motor.
The code compiles file, no errors. Here’s my code:
#include "thingProperties.h"
#define ENCA 2
#define ENCB 3
#define PWM 5
#define IN1 7
#define IN2 6
int pos = 0;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1000);
pinMode(ENCA, INPUT);
pinMode(ENCB, INPUT);
attachInterrupt(digitalPinToInterrupt(ENCA), readEncoder, RISING);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
setMotor(1,40,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
Serial.println("TEST1");
setMotor(-1,40,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
Serial.println("TEST2");
setMotor(0,40,PWM,IN1,IN2);
delay(200);
Serial.println(pos);
Serial.println("TEST3");
}
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--;
}
}
Here is a schematic of my set up:
So far, I’ve tried a range of values for the PWM. I’ve tried different delay times, ranging from 200 to 5000. I tried setting INPUT to INPUT_PULLUP. I know the power adapter I’m using is outputting about 14V. The Pololu board is brand new and this is my first time using a motor driver. There’s gotta be something simple I’m missing here, any help is appreciated. Thanks in advance.