standby:
Thank you both of you!
Dear Carsten53T,
I have made the following wiring between arduino MEGA and the Drivers:
Digital Pin 2 -> PUL+ (driver 1)
Digital Pin 3 -> DIR+ (driver 1)
Digital Pin 4 -> ENA+ (driver 1)
Digital Pin 5 -> PUL+ (driver 2)
Digital Pin 6 -> DIR+ (driver 2)
Digital Pin 7 -> ENA+ (driver 2)
Digital Pin 8 -> PUL+ (driver 3)
Digital Pin 9 -> DIR+ (driver 3)
Digital Pin 10 -> ENA+ (driver 3)
And the PUL-, DIR- to the Arduino GND and ENA- unconnected.
All 3 motors are connected to A+B- and B+B- each coil.
Is there something wrong in wiring?
It sounds reasonable. It runs, so it cann't me much off ;o)
.. maybe it's the unconnected ENA- that slows down the speed. I'm not that much of a specialist, but my impression is that EN takes time. Do you involve EN between each step or just at stepper-start and stepper-stop?
I have used digitalwrite directly (LOW->HIGH to start) but the speed is low and also I can't make them run in different speed each other. With accelstepper library the speed is tragically low.
Thank you!
About the speed .. if it works as my driver, you deside the 'delay' between each step. If it's short, the steppers steps fast. Notice below the inverse relation between velocity and 'delay' [it's not an Arduino delay(time), but rather time between two visits of cStepper::setTime()]
I'm not sure weather your driver takes care of the details of which pin to pull and what fase to choose, but I can make this code work for mine.
I've combined three steppers to work in unison ( in a cPen-class), but I'm retreating to have only 2 steppers in the pen. The last days it's fooled me and doesn't comply to my wishes. I'm trying to deal with a time discrepency when two motors does equal things .. and to code myself out of burning the drivers off (it happened once). My code is executing fine and I havent got a clue of why the steppers just buzzes instead of moves. The code is rather ugly and pretty lengthy with a lot of redundant code. I can pop part of the geometry-stuff that applies to two steppers that works on a plane if you'r interested.
#include <cStepper.h>
//-------------------------------------------------------------
const int x_EA = 41 ;
const int x_i2 = 39 ;
const int x_i1 = 38 ;
const int x_EB = 40 ;
const int x_i4 = 37 ;
const int x_i3 = 36 ;
cStepper stpX( x_EA, x_EB, x_i1, x_i2, x_i3, x_i4 ) ;
const int y_EA = 33 ;
const int y_i2 = 31 ;
const int y_i1 = 30 ;
const int y_EB = 32 ;
const int y_i4 = 29 ;
const int y_i3 = 28 ;
cStepper stpY( y_EA, y_EB, y_i1, y_i2, y_i3, y_i4 ) ;
const int z_EA = 49 ;
const int z_i2 = 47 ;
const int z_i1 = 46 ;
const int z_EB = 48 ;
const int z_i4 = 45 ;
const int z_i3 = 44 ;
cStepper stpZ( z_EA, z_EB, z_i1, z_i2, z_i3, z_i4 ) ;
...............
from class cStepper:
cStepper::cStepper( int EA , int EB , int i1 , int i2 , int i3 , int i4 )
{
x_i4 = i4 ;
x_i3 = i3 ;
x_i2 = i2 ;
x_i1 = i1 ;
x_EA = EA ;
x_EB = EB ;
pinMode( EA , OUTPUT ) ;
pinMode( i2 , OUTPUT ) ;
pinMode( i1 , OUTPUT ) ;
pinMode( EB , OUTPUT ) ;
pinMode( i4 , OUTPUT ) ;
pinMode( i3 , OUTPUT ) ;
deEnable() ;
Stop() ;
position_x = 0.0f ;
fase = 0 ;
mVelocity = 0.0f ; // mVelocity and mDelay are inverse
mDelay = 1000 ; //unsigned long
mMinDelay = 2 ; //in millis. test this out! unsigned long
mMaxVelocity = 500.0f ; // in steps pr sec (1000 millis )
oldTime = 0 ;
mDirection = true ;
misOn = false ;
}// end constructor
.... and the most troublesome member: The one that is 'in the loop' and 'listens' for the time ticking:
//-------------------------------------------------------
void cStepper::setTime(){
if ( cStepper::misOn ){
if( ( (oldTime + mDelay) < millis()) ){
cStepper::Step() ;
cStepper::oldTime = millis() ;
}
}//
} // end cStepper::setTime
some other members members:
//velocity in steps pr sec (1000 millis )
boolean cStepper::setVelocity( float velocity ){
mVelocity = velocity ;
boolean res = false ;
if( mVelocity < mMaxVelocity ){
res = true ;
if( 0 < mVelocity ){ mDelay = long( 1000/mVelocity) ; }
}
else{ mDelay = mMinDelay ; }
return res ;
}
//----------------------------------
//-----------------
void cStepper::Step()// one step at a time!
{
if( cStepper::mDirection == true ){ cStepper::fase +=1 ; cStepper::position_x += 1 ; }
else{ cStepper::fase -=1 ; cStepper::position_x -= 1 ; }
if( 3 < cStepper::fase ){ cStepper::fase = 0 ; }
if( cStepper::fase <0 ){ cStepper::fase = 3 ; }
switch( cStepper::fase )
{
case 0:
cStepper::x1_faseOne() ;
break ;
case 1:
cStepper::x2_faseOne() ;
break ;
case 2:
cStepper::x1_faseTwo() ;
break ;
case 3:
cStepper::x2_faseTwo() ;
break ;
}// end switch
}// end Step
//-------------------------------
void cStepper::x1_faseOne()
{
digitalWrite( x_i4 , LOW ) ;
digitalWrite( x_i3 , LOW ) ;
digitalWrite( x_i1 , LOW ) ;
digitalWrite( x_i2 , HIGH ) ;
}//A_faseOne
//-------------------------------
void cStepper::x1_faseTwo()
{
digitalWrite( x_i4 , LOW ) ;
digitalWrite( x_i3 , LOW ) ;
digitalWrite( x_i2 , LOW ) ;
digitalWrite( x_i1 ,HIGH ) ;
}//A_faseTwo
//------------------------------
void cStepper::x2_faseOne()
{
digitalWrite( x_i2 , LOW ) ;
digitalWrite( x_i1 , LOW ) ;
digitalWrite( x_i3 , LOW ) ;
digitalWrite( x_i4 , HIGH ) ;
}//B_faseOne
//------------------------------
void cStepper::x2_faseTwo()
{
digitalWrite( x_i2 , LOW ) ;
digitalWrite( x_i1 , LOW ) ;
digitalWrite( x_i4 , LOW ) ;
digitalWrite( x_i3 , HIGH ) ;
}
//------------------------------
void cStepper::Enable(){
analogWrite( x_EA , 255 ) ;
delay(100) ;
analogWrite( x_EB , 255 ) ;
delay(100) ;
cStepper::misOn = true ;
}
void cStepper::deEnable(){
analogWrite( x_EA , 0 ) ;
analogWrite( x_EB , 0 ) ;
cStepper::mVelocity = 0.0f ;
cStepper::misOn = false ;
}
void cStepper::Stop(){
digitalWrite( x_i1 , LOW ) ;
digitalWrite( x_i2 , LOW ) ;
digitalWrite( x_i3 , LOW ) ;
digitalWrite( x_i4 , LOW ) ;
cStepper::mVelocity = 0.0f ;
}
//--------------------------
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
don't take it granted that this will work exactly (I've got too mený versions of the code ;o/) :
//velocity in steps pr sec (1000 millis )
boolean cStepper::changeSpeed( float change ){
boolean res = true ;
mVelocity += change ;
if( abs(mVelocity) < mMaxVelocity ){
if( 2 < mVelocity ){
mDelay = long( 1000/mVelocity) ;
res = false ;
mDirection = true ;
}
else if( mVelocity < -2 ){
mDelay = long( 1000/mVelocity) ;
res = false ;
mDirection = false ;
}
else{ }
}
else{
mDelay = mMinDelay ;
if( 2 < mVelocity ){ mDirection = true ; }
if( mVelocity < -2 ){ mDirection = false ; }
res = false ;
}
return res ;
}// cStepper::changeSpeed
//------------------------------------------------------- ~100
Take note that, if you run two motors in unison and one of them is waiting while it 'works' .. it will likely burn off the driver. Ask in if you need details.