stepper motor + dual motor shield

crylikebaby

  • Newbie
  • *
    • Posts: 1
    • View Profile
Hello,

I'm trying to control a mini stepper motor with a dual motor shield, but I haven't yet make it work. I wired it to shield and uploaded the code, but nothing happened. I want to simply control the speed and phase of the motor spinning. You can see how the motor looks like on the attached image.

(FYI, talking about the specification of the motor, it is 4 wire 2 phase mini stepper motor requiring 1.5 - 3V. For more information, you can check out this link - https://www.amazon.com/dp/B01GWJD0F4/ref=sr_ph_1?ie=UTF8&qid=1485282732&sr=sr-1&keywords=micro+stepper+motor.)

So, here below are the problems that I'm struggling with.

1. I'm not sure if I wired the motor to the shield correctly. It has four wires (brown-orange-yellow-red), and I'm not sure which one is + or -. Also, same on the board. I can see two holes on M1 and M2 parts on the board respectively, but can't see one which one is negative/positive. I just hooked the brown and orange wires to M1 and yellow and red wires to M2, and it didn't work.

2. I have the sample code of the dual motor shield, provided on the tutorial page. However, I don't think this is for running a stepper motor.

#include <Wire.h>
#include "MotorDriver.h"

MotorDriver motor(0);//value passed is the address- remove resistor R1 for 1, R2 for 2, R1 and R2 for 3

int maxPWM=10000;
int steps=100;
int stepSize=maxPWM/steps;

void setup(){
  Serial.begin(9600);
  Wire.begin();
  //The value passed to begin() is the maximum PWM value, which is 16 bit(up to 65535)
  //This value also determines the output frequency- by default, 8MHz divided by the maxPWM value
  if(motor.begin(maxPWM)){
    Serial.println("Motor driver not detected!");
    while(1);
  }
  //The failsafe turns off motors if a command is not sent in a certain amount of time.
  //Failsafe is set in milliseconds- comment or set to 0 to disable
  motor.setFailsafe(1000);
}

void loop(){
  int i;
  for(i=-maxPWM;i<maxPWM;i+=stepSize){
    delay(10);
    motor.setMotor(1,i);
    motor.setMotor(2,i);
  }
  for(i=maxPWM;i>-maxPWM;i-=stepSize){
    delay(10);
    motor.setMotor(1,i);
    motor.setMotor(2,i);
  }
}

-

Could anyone please help me to run the motor with this shield? Any advice on wiring and coding would be helpful!
I also strongly hope TinyCircuit provide more information and examples of controlling various type of motors with this shield ...

« Last Edit: January 25, 2017, 02:37:42 PM by crylikebaby »


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
Hi, missed things on the forum for a few days- the Dual Motor Driver TinyShield is intended for brushed motors/DC loads as stated in the product description, but it's definitely possible to spin a stepper with some software work. A four wire bipolar stepper has two separate coils, one pair of leads for a coil should be connected to the M1 connections, one pair to the M2 connections. For the code, it needs to flip the polarity on the coils in a certain order to spin the motor, something like:

Code: [Select]
#include <Wire.h>
#include "MotorDriver.h"

MotorDriver motor(0);//value passed is the address- remove resistor R1 for 1, R2 for 2, R1 and R2 for 3

int maxPWM=100;

void setup(){
  Serial.begin(9600);
  Wire.begin();
  //The value passed to begin() is the maximum PWM value, which is 16 bit(up to 65535)
  //This value also determines the output frequency- by default, 8MHz divided by the maxPWM value
  if(motor.begin(maxPWM)){
    Serial.println("Motor driver not detected!");
    while(1);
  }
  //The failsafe turns off motors if a command is not sent in a certain amount of time.
  //Failsafe is set in milliseconds- comment or set to 0 to disable
  motor.setFailsafe(1000);
}

void loop(){
  motor.setMotor(1,maxPWM);
  delay(10);
  motor.setMotor(2,-maxPWM);
  delay(10);
  motor.setMotor(1,-maxPWM);
  delay(10);
  motor.setMotor(2,maxPWM);
  delay(10);
}

I tested this with a typical NEMA 17 stepper, at ~4V it's spinning slowly as expected. This won't be doing any CNC stuff, but it could definitely do the job in other applications.


riphill

  • Newbie
  • *
    • Posts: 4
    • View Profile
Thanks for posting this, I was about to ask about this shield and stepper motors as I realised after purchasing the shield that the PWM is sent over I2C to control the output of the H-Bridge.  It seems to me you need to pulse each input in the expected sequence and the motor should step (in theory), not tried it yet.  It would seem that instead of relying on existing libraries, I'll have to come up with my own loop  (would it be possible to microstep do you think?)

For my application I want to use a stepper like an accurate pointer, like the hour hand on a clock, so I just need to move it to a pre-determined angle and then return to the starting point.  With no particular feedback I guess I'll just need to count the steps carefully.


 

SMF spam blocked by CleanTalk