I attempted to test a motor using an Arduino nano and a TB6612FNG Dual H-Bridge motor driver.
I connected the VCC and GND pins on the driver to the respective power pins on the Arduino (VCC to 3.3V power, and GND to GND).
I connected PWMA to pin 4, AIN2 to pin 3, AIN1 to pin 2, and STBY to pin 5.
VMOT (Motor Power) and its GND pin were connected to the Postive and negative ends of a 12V power supply.
I am using an Adafruit 12V 48-Step motor.
I connected the red wire to ground, the orange and pink wires to AO1, and the blue and yellow wires to A02.
Now here is the code:
#include <AccelStepper.h>
AccelStepper Motor1(AccelStepper::DRIVER, 2, 3);
AccelStepper Motor2(AccelStepper::DRIVER, 4, 5);
char val;
void setup()
{
digitalWrite(5,HIGH);
}
void loop()
{
Motor1.setSpeed(24);
Motor2.setSpeed(-24);
Motor1.runSpeed();
Motor2.runSpeed();
}
What did i do wrong?
It seems like you're missing a bunch of code.
There is no initialization for variable val
What is the purpose of that variable? There's no association in the code.
You are setting pin 5, HIGH in SETUP which occurs once. This value will never change
according to your code.
What would you like the motor to do? What is happening now?
There is no initialization for variable val
It's initialised to zero, but not used, so I don't see a problem.
What do YOU think runSpeed() is going to do? You have NOT told the stepper motors to be anywhere else, so they are doing exactly what you say. They are going no steps at a constant speed. Why do YOU expect different results?
You didnt have to be so sarcastic about it, but I did not realize that the runspeed function only runs at the speed of the last call to runspeed if steps are needed/called for. Thank you for that hint but an issue is also whether or not i wired it up correctly T.T