help with 28BYJ-48 stepper and ASCOM driver - edit : FIXED IT :)

First post so hello everyone!

I am completely new to Arduino and have set out to make an auto guider camera mount for astrophotography. I have bought an Uno R3 and two 28BYJ-48 stepper motors with UNC2003 boards and I’m currently working on getting one of the two motors running from PHD2 auto guiding software using a driver from this forum.

I’ve managed to get the motor responding to E and W manual guide commands in PHD2 so the interface and code is working however the motors will only complete one step per pulse from PHD2.

If I keep pulsing the output the motor continues to step in the required direction but at one step per pulse.

Can someone take a peek at my code (modified from code found on here so not all my own work!) and advise as to why the motor will not complete the defined number of steps every time the input is received?

Also the motor rotates correctly for E and W but also rotates when N or S are sent (always the same direction as W).

Thanks you so much in advance!

my_arduino_RA_mount.ino (3.38 KB)

so I fixed this problem, had to completely change the if statements to run the full motor sequence if the desired input is detected. works nicely, just need to mount the motors to the EQ mount and fine tune the number of steps per pulse.

For those interested in my progress:

#include <AccelStepper.h>
#define HALFSTEP 8
#include <avr/io.h>
#include <avr/interrupt.h>

int RAspeed = 400.0; 
int DECspeed = 400.0;
int trackRate = 400.0;
int incomingByte = 0;  

AccelStepper RAstepper(HALFSTEP,3,5,4,6); 
AccelStepper DECstepper(HALFSTEP,8,10,9,11);

boolean isPulseGuiding = false;
String logString;
unsigned long timeWait;

void setup() {

  // initialize serial:
  Serial.begin(57600);
  Serial.flush();
  
  logString.reserve(400);

  // initialize Timer1
  TCCR1A = 0;     // set entire TCCR1A register to 0
  TCCR1B = 0;     // same for TCCR1B
 
  // set compare match register to desired timer count:
  // turn on CTC mode:
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR1B |= (1 << CS10);
  TCCR1B |= (1 << CS12);
  
  sei();
  
  
  OCR1A = trackRate;
  TIMSK1 |= (1 << OCIE1A);
  TCNT1 = 0; //Reset counter

  RAstepper.setMaxSpeed(RAspeed);
  RAstepper.move(1);
  RAstepper.setSpeed(RAspeed);

  DECstepper.setMaxSpeed(DECspeed);
  DECstepper.move(1);
  DECstepper.setSpeed(DECspeed);  

}

void loop()
{
  if(isPulseGuiding)
  {
    if(timeWait < millis())
    {
        OCR1A = trackRate;
	TIMSK1 |= (1 << OCIE1A);
	TCNT1 = 0; //Reset counter
        isPulseGuiding = false;
    }
  }
}

// RA Axis step routine
ISR(TIMER1_COMPA_vect)
{

}

/* SerialEvent occurs whenever a new data comes in the hardware serial RX.
 This routine is run between each time loop() runs, so using delay inside
 the loop() can delay response.  Multiple bytes of data may be available. */
void serialEvent() {
  if(Serial.available()>0) {
    String inCmd;
    inCmd = Serial.readStringUntil('#');
    logString += inCmd + "\n\r";
    
    if(inCmd == "I")
    {
      if(isPulseGuiding)
      {
        Serial.println("TRUE#");
      }
      else
      {
        Serial.println("FALSE#");
      }  
    }
    
    if(inCmd == "E") //RA + EAST
    {
        inCmd = "";
        
        while(inCmd.toInt()==0)
          inCmd = Serial.readStringUntil('#');
          
        logString += inCmd + "\n\r";

        RAstepper.enableOutputs();
        RAstepper.move(RAspeed);
        RAstepper.setSpeed(RAspeed);
        RAstepper.setAcceleration(RAspeed);
        RAstepper.runToPosition();
        RAstepper.disableOutputs();

    }
    
    if(inCmd == "W") //RA - WEST
    {
        inCmd = "";
        
        while(inCmd.toInt()==0)
          inCmd = Serial.readStringUntil('#');
          
        logString += inCmd + "\n\r";
        
        RAstepper.enableOutputs();
        RAstepper.move(-RAspeed);
        RAstepper.setSpeed(-RAspeed);
        RAstepper.setAcceleration(-RAspeed);
        RAstepper.runToPosition();
        RAstepper.disableOutputs();
    }
    
    if(inCmd == "U") //DEC + NORTH
    {
        inCmd = "";
        
        while(inCmd.toInt()==0)
          inCmd = Serial.readStringUntil('#');
          
        logString += inCmd + "\n\r";

        DECstepper.enableOutputs();
        DECstepper.move(DECspeed);
        DECstepper.setSpeed(DECspeed);
        DECstepper.setAcceleration(DECspeed);
        DECstepper.runToPosition();
        DECstepper.disableOutputs();
    }
    if(inCmd == "D") //DEC - SOUTH
    {
        inCmd = "";
        
        while(inCmd.toInt()==0)
          inCmd = Serial.readStringUntil('#');
          
        logString += inCmd + "\n\r";

        DECstepper.enableOutputs();
        DECstepper.move(-DECspeed);
        DECstepper.setSpeed(-DECspeed);
        DECstepper.setAcceleration(-DECspeed);
        DECstepper.runToPosition();
        DECstepper.disableOutputs();
    }
    if(inCmd == "N")
    {
      	OCR1A = trackRate;
	TIMSK1 |= (1 << OCIE1A);
	TCNT1 = 0; //Reset counter
        isPulseGuiding = false;

    }
    
    if(inCmd == "L")
    {
      	Serial.println(logString);
        logString = "";
    }
    

  }
}