Teensy 3.0 and stepper motors

Status
Not open for further replies.

MichaelMeissner

Senior Member+
I recently bought some cheap ebay stepper motors to experiment with (http://www.ebay.com/itm/221393363619?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649). Given these are 5v motors, if I were to control them via Teensy 3.0, I'm wondering what kind of voltage level converter I need.

I assume I need to plug in the power to the motor to 5v, either VIN or a separate 5v power source.

I imagine I need to do level converters for each of the 4 pins. Is the stepper motor communication one way, or do I need use level converters that are bi-directional? Are some of the 4 pins always output pins and some always input? Or is it a mixture? If I were to go to the Teensy 3.1, would I need level converters at all (i.e. would I be able to drive the motor from 3.3v on the Teensy, and any input from the motor would work on the 5v tolerant pins).

Assuming I need to do level converters, would I need to use a fast acting converter like the 74HCT245 that is recommended for neopixels (but that might not work with bi-directional pins).

Is there a level converter that is recommended for stepper motors?

Are there any limits on the Teensy to having more than one stepper motor?

I assume there are no differences in wiring the Stepper motors between the standard Stepper library and the AccelStepper library?
:confused::cool:
 
I'd not use USB power for the motors- but rather, a wall transformer.
motors are said to be 200 ohms, 4-phase.
The driver chip ULN2 003, as I read the data sheet(attached here), will work OK with 3.3V logic level inputs.

Your code/library code has to generate the 4 phase pulsing - for speed and rotation direction.
 

Attachments

  • ULN200e.pdf
    237.9 KB · Views: 236
Those stepper motors look identical to the ones I bought awhile back, and it just worked. I'm not in front of them, but I'll check if I have something on file on my computer.

edit:
Yep, I bought this one from amazon. I might have also gotten one off ebay.
http://www.amazon.com/gp/product/B0089JV2OM/
 
Last edited:
Thanks everybody. It looks fairly simple. After reading about neopixels and the need for high speed voltage converters, I figured I would ask.
 
I imagine I need to do level converters for each of the 4 pins.

The ULN2003 datasheet says 2.4V is enough to get up to 200 mA output to the motor, so the 3.3V output from Teensy should be plenty.

Since those motor coils are 200 ohms, the most they should need from the ULN2003 is 25 mA per output.

Is the stepper motor communication one way,

Yes, it's unidirectional.

Are some of the 4 pins always output pins and some always input? Or is it a mixture? If I were to go to the Teensy 3.1, would I need level converters at all

All 4 appear to be inputs, which can work with the 3.3V signals. Looks like it should work with a direct connection.

Are there any limits on the Teensy to having more than one stepper motor?

Power is the main issue. Each motor could use about 50 mA.

I assume there are no differences in wiring the Stepper motors between the standard Stepper library and the AccelStepper library?
:confused::cool:

Either should work. Use the 4-wire unipolar constructor, since these are 4 wire unipolar motors.
 
T3.1 with 28BYJ-48 5V stepper, and ULN2003 darlington driver

I have this same 28BYJ-48 geared 5V stepper motor, which comes with a ULN2003 driver board. I got mine from http://www.amazon.com/gp/product/B00DUSYEWY/
I'm using it with a T3.1 and a separate 5V supply for the driver board, which works OK. Now according to this Arduino forum post this motor wants an 8-step sequence, such as for example

Code:
void counterclockwise () {
  PORTB = 0b0001;  delay(motorSpeed);
  PORTB = 0b0011;  delay(motorSpeed);
  PORTB = 0b0010;  delay(motorSpeed);
  PORTB = 0b0110;  delay(motorSpeed);
  PORTB = 0b0100;  delay(motorSpeed);
  PORTB = 0b1100;  delay(motorSpeed);
  PORTB = 0b1000;  delay(motorSpeed);
  PORTB = 0b1001;  delay(motorSpeed);
}

and I have confirmed this works as expected; that is, when stepping slowly, each one of those 8 bit patterns moves the motor incrementally in the same direction. (Thanks Paul for making teensy so compatible we can pretend "PORTB" actually exists on an ARM cpu :) )

I don't know if this is considered "half-stepping" or what, but it seems the normal "Stepper" and "AccelStepper" libraries use only four bit patterns (always two out of four lines active at any time). Is there a way to get AccelStepper to use this 8-step pattern, instead of 4 ?
 
Nice.

Code:
void clockwise() {
  PORTB = 0b1000; delay(motorSpeed);
  PORTB = 0b1100; delay(motorSpeed);
  PORTB = 0b0100; delay(motorSpeed);
  PORTB = 0b0110; delay(motorSpeed);
  PORTB = 0b0010; delay(motorSpeed);
  PORTB = 0b0011; delay(motorSpeed);
  PORTB = 0b0001; delay(motorSpeed);
  PORTB = 0b1001; delay(motorSpeed);
}

I assume clockwise works as well. I put it here for reference.
 
Turns out I can simply pass a parameter when declaring the stepper object, saying if I want full or half-stepping, as explained here: http://forum.arduino.cc/index.php?P...63t394oocu8h0&topic=85335.msg657365#msg657365
and with more info at this wiki: http://arduino-info.wikispaces.com/SmallSteppers

For example:
Code:
#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 8;	// Blue   - 28BYJ48 pin 1
int motorPin2 = 9;	// Pink   - 28BYJ48 pin 2
int motorPin3 = 10;	// Yellow - 28BYJ48 pin 3
int motorPin4 = 11;	// Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

... and so on.

By the way, this is a geared stepper and I have verified the gear ratio is very close to 63.68395:1 which means a full revolution is not a very round number number of steps. It takes 4075.7728 half-steps per revolution. Using a double precision float for my step accumulator, I can do many revolutions and still not loose registration. The major error is of course backlash in the cheap geartrain.
 
Last edited:
Mostly for my own reference, here is my test code to prove to myself I can keep the stepper aligned after many rotations in the same direction, updated to turn off the current while the motor is not moving. With this code, a flag/pointer on the shaft stops in the same place after 8688 full rotations in 11.6 hours, so I'll consider it good.

EDIT: I have also tried microstepping, which reduces noise and vibration at low speeds: http://forum.pjrc.com/threads/26359-256-microstepping-example-for-stepper-motors

Code:
// Test program for 28BYJ-48 stepper motor
// J.Beale  23 July 2014

// see also: http://arduino-info.wikispaces.com/SmallSteppers

#include <AccelStepper.h>

#define STEPS_PER_REV (4075.7728)  // 28BYYJ-48 stepper motor with 64 steps/rev and 63.68395:1 gear
#define FULLSTEP 4
#define HALFSTEP 8

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
//AccelStepper stepper2(STEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper(HALFSTEP,2,4,3,5); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

double posOffset;  // floating point, since we don't have integer # of steps per revolution
long unsigned int cycle;

void setup()
{  
  Serial.begin(115200);  // start serial port
  cycle = 0;
  stepper.setMaxSpeed(2000);
  stepper.setAcceleration(2000);
  posOffset = 2*STEPS_PER_REV; // two full rotations before stopping
}

void loop()
{
    if (stepper.distanceToGo() == 0) {  // have we reached previous target?
      cycle++;
      stepper.moveTo(posOffset * cycle);
      Serial.print(cycle-1);  // how many cycles we have already finished
      Serial.print(",");   Serial.println(millis());  // how long it's been
      delay(10); // settling time
      stepper.disableOutputs();  // turn all phases off - save power
      delay(4000);  // pause for this long at endpoint, with motor stopped
      stepper.enableOutputs();  // turn outputs back on, to move again
      delay(10); // settling time
    }
    stepper.run();  // do one motor step, if required
}
 
Last edited:
Status
Not open for further replies.
Back
Top