Accelstepper not working on Teensy 4.1 with DM556T driver

jonesyro

Active member
I can't get accelstepper to work on my teensy 4.1.

I'm using a DM556T Driver with a 23HS22-2804S stepper.

It works perfect on ARDUINO MEGA using the same exact wiring

The wiring is as follow:

TEENSY 4.1
DIR+ and PUL+ connected to 5V (VIN)
DIR- to pin 2
PUL- to pin 3

ARDUINO MEGA
DIR+ and PUL+ connected to 5V
DIR- to pin 2
PUL- to pin 3

Here's the code I'm using: (working on MEGA, not working on TEENSY 4.1)

Code:
// Include the AccelStepper library:
#include <AccelStepper.h>

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

void setup() {
  // Set the maximum speed and acceleration:
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(500);
}

void loop() {
  // Set the target position:
  stepper.moveTo(8000);
  // Run to target position with set speed and acceleration/deceleration:
  stepper.runToPosition();

  delay(1000);

  // Move back to zero:
  stepper.moveTo(0);
  stepper.runToPosition();

  delay(1000);
}


Is it because the Teensy only outputs 3.3V on digital pins vs 5V on Arduino mega? And if so - how can I make it run on the Teensy?
 
Additional Note:

I'm able to run the stepper without the library on the Teensy 4.1 with this wiring and code. Doesn't really help since I want to use Accelstepper for its features.

WIRING:
DIR+ and PUL+ connected to GROUND
DIR- to pin 37
PUL- to pin 33

CODE:
Code:
// Define stepper motor connections:
#define dirPin 37
#define stepPin 33

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);

  // Set the spinning direction CW/CCW:
  digitalWrite(dirPin, LOW);
}

void loop() {
  // These four lines result in 1 step:
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(0);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(0);
}
 
After some research it looks like I will need level shifting.

I purchased these level shifter boards - will get them Saturday.

https://www.amazon.com/AEDIKO-Chann...prefix=4+channel+level+shifter,aps,136&sr=8-7

Can you help me with the wiring - here's how I'm thinking of wiring this, is this how to do it?

diag.jpg
 
a.png
b.png
Have you read the DM556T data sheet?
In order to switch the inputs you must supply a minimum of 7mA with a typical of 10mA.
Are those devices capable of supplying(sinking) that current?
 
View attachment 27909
View attachment 27910
Have you read the DM556T data sheet?
In order to switch the inputs you must supply a minimum of 7mA with a typical of 10mA.
Are those devices capable of supplying(sinking) that current?

I think so? this is the datasheet for the level shifter:
https://www.ti.com/lit/ds/symlink/txs0108e.pdf

The only difference between the Arduino Mega and the Teensy 4.1 is the voltage out on digital pins. (5v vs 3.3v)

Assuming the level shifter can pass enough amps - I'm wondering if the wiring I made in post #3 is correct?
 
The only difference between the Arduino Mega and the Teensy 4.1 is the voltage out on digital pins. (5v vs 3.3v)
...and the amount of current each pin can source/sink.
I purchased these level shifter boards - will get them Saturday.

https://www.amazon.com/AEDIKO-Channe...s,136&sr=8-7
I think so? this is the datasheet for the level shifter:
https://www.ti.com/lit/ds/symlink/txs0108e.pdf
Those level shifters are different! Which do you intend to use?
 
As a very quick test, I ran the program from msg #1 without any motors, just watching the pins with my oscilloscope.

Here is the "big picture" view in *very* slow scrolling mode. This shows about 50 seconds total. You can see the 1 second gaps in step pulses (Pin3), then the direction (Pin2) changes.

file1.png

This is a "zoom in" to the first 1.8 seconds after the direction changes. You can see AccelStepper is starting the step pulses with longer gaps for slow starting motion and then gradually decreasing the time to speed up the motor.

file2.png

It certainly does seem to be working. Odds are strong this will work when you get the signal level issue resolved.
 
As a very quick test, I ran the program from msg #1 without any motors, just watching the pins with my oscilloscope.

Here is the "big picture" view in *very* slow scrolling mode. This shows about 50 seconds total. You can see the 1 second gaps in step pulses (Pin3), then the direction (Pin2) changes.

View attachment 27913

This is a "zoom in" to the first 1.8 seconds after the direction changes. You can see AccelStepper is starting the step pulses with longer gaps for slow starting motion and then gradually decreasing the time to speed up the motor.

View attachment 27914

It certainly does seem to be working. Odds are strong this will work when you get the signal level issue resolved.

Thanks for the tests Paul!
 
TEENSY 4.1
DIR+ and PUL+ connected to 5V (VIN)
DIR- to pin 2
PUL- to pin 3

Try connecting DIR+ and PUL+ to 3.3V rather than 5V.

Looks like the input circuit is basically the same as MIDI.

screenshot.png

They don't say what resistor is used and the spec is 5V, so maybe the optocoupler won't get enough current with 3.3V. Maybe. If that's true, the level shifter or a transistor circuit will be needed.

There's also a pretty good chance the optocoupler doesn't need much current and is staying 100% with only 1.7V which exists between the 5V power to normal pins at 3.3V. If so, switching DIR+ and PUL+ to 3.3V will probably just work.
 
OK, there used to be two currents stated, 4mA and 10mA.
The 4mA one seems to have been deleted now!
 
Try connecting DIR+ and PUL+ to 3.3V rather than 5V.

Looks like the input circuit is basically the same as MIDI.

View attachment 27915

They don't say what resistor is used and the spec is 5V, so maybe the optocoupler won't get enough current with 3.3V. Maybe. If that's true, the level shifter or a transistor circuit will be needed.

There's also a pretty good chance the optocoupler doesn't need much current and is staying 100% with only 1.7V which exists between the 5V power to normal pins at 3.3V. If so, switching DIR+ and PUL+ to 3.3V will probably just work.

That was a really good guess - unfortunately it doesn't work :( but the level shifters should be here tomorrow.

Really appreciate the suggestions and looking into this.
 
I can't get accelstepper to work on my teensy 4.1.

I'm using a DM556T Driver with a 23HS22-2804S stepper.

It works perfect on ARDUINO MEGA using the same exact wiring

Have you tried adding
Code:
  stepper.setMinPulseWidth(10);
in setup(), in case its just being too fast with the T4? On the Mega the code is so much slower to execute that
the minimum pulse width is always many microseconds.
 
Have you tried adding
Code:
  stepper.setMinPulseWidth(10);
in setup(), in case its just being too fast with the T4? On the Mega the code is so much slower to execute that
the minimum pulse width is always many microseconds.

OMG - that did it!!

thanks so much - I won't need these 20 level-shifters I orders after-all haha
 
I had the same problem with teensy 4.1. I haven't had this problem with teensy 4.0. Thank you very much
 
Back
Top