Controlling Stepper motor using RC receiver

Hi.

I am using Arduino UNO with a DM556 Micro step driver to control the Stepper motor. PUL+ --> pin 3
DIR+ --> pin 5
RC receiver --> pin 2
Using CH2 of receiver

With out the RC receiver (R9SX) everything works fine, the motor works perfectly. However I cannot figure out how to control it with RC. I tried to find a tutorial using Micro step driver but everybody appears to use Arduino Nano or some other equipment.

The code I am using makes the motor work extremely slow and only in one direction.

I'd really appreciate it if some one can point error in my code or provide me with a suitable one for my use case.

CODE:

// Define Pins
#define RCPin 2
#define DIR 5
#define STEP 3

// Set up time variables for Stepper motor
unsigned long previousMotorTime = millis();
long MotorInterval;

// Set up time variables for RC Read
volatile long Pulses = 0;
int PulseWidth = 0;

void setup() {
  Serial.begin(9600);

  // RC Read Setup
  pinMode(RCPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(RCPin), PulseTimer, CHANGE); 

  // Set DIR and STEP pins to OUTPUT
  pinMode(DIR, OUTPUT);
  pinMode(STEP, OUTPUT);

  // Set initial direction (LOW = one direction, HIGH = the other direction)
  digitalWrite(DIR, LOW);
}

void loop() {
  digitalWrite(STEP, LOW);

  // Only save HIGH pulse lengths
  if (Pulses < 2000){
    PulseWidth = Pulses;
  }

  // Stepper motor speed, bigger MotorInterval is a slower speed.
  if (PulseWidth >= 1400 && PulseWidth <= 1600) {
    digitalWrite(STEP, LOW); // Motor doesn't move if the joystick is near the midpoint
  } else if (PulseWidth < 1400) {
    digitalWrite(DIR, LOW);
    MotorInterval = map(PulseWidth, 1000, 1400, 1, 25); // Map the RC signal to the motor speed in reverse when the joystick is pulled down
  } else if (PulseWidth > 1600) {
    digitalWrite(DIR, HIGH);
    MotorInterval = map(PulseWidth, 1600, 1984, 25, 1); // Map the RC signal to the motor speed when the joystick is pushed forward.
  }
  
  // Check if the MotorInterval time has elapsed and step the motor.
  unsigned long currentMotorTime = millis(); 
  if (currentMotorTime - previousMotorTime > MotorInterval) {
    digitalWrite(STEP, HIGH);
    previousMotorTime = currentMotorTime;
  }
}

// Function to measure the length of the pulses from the remote control
void PulseTimer() {
  static long StartTime = 0;
  long CurrentTime = micros();
  if (CurrentTime > StartTime) {
    Pulses = CurrentTime - StartTime;
    StartTime = CurrentTime;
  }
}

Please post the datasheet/ operators manual for the UH2. All helpers might not have it.

What do you mean by UH2?

Sorry. The RC receiver.

Your STEP pulse width is too short. According to the DM556 manual, it needs to be greater than 2.5us

Why do you think its shorter? On an UNO you cannot create pulses shorter than about 5µs using digitalWrite().

So what is your recommendation for the pulse width and how should it be created?

The pulse width as it is created in the sketch is definitely longer than 5µs. If you say it needs to be greater than 2.5µs this should be OK. So there must be another reason for the problems.
@maaz1211 should post a schematic and a post of the sketch that works ( without RC receiver ) may be helpful.

Try sorting out your RC signal first.
Use some basic code away from the above.
Do you have a scope.
Many late model RC receivers may not give the signal you think.

Also, post your circuit diagram.

This is the sketch I used before receiver.

//int reverseSwitch = 2;
int driverPUL = 3;    // PUL- pin
int driverDIR = 5;    // DIR- pin
int spd = A0;     // Potentiometer

// Variables
int pd = 0;       // Pulse Delay period (further reduced for increased speed)
boolean setdir = LOW; // Set Direction

void setup() {
  pinMode(driverPUL, OUTPUT);
  pinMode(driverDIR, OUTPUT);
}

void loop() {
  digitalWrite(driverDIR, setdir);
  digitalWrite(driverPUL, HIGH);
  delayMicroseconds(pd);
  digitalWrite(driverPUL, LOW);
  delayMicroseconds(pd);
}

If you have the DM556 set for 400 pulses/rev and you have MotorInterval = 25ms, then it would take 0.025s x 400 = 10 seconds for a complete revolution. So, do you see how to make it faster?

the stepper motor i am using is ML23HSAP4300 - NEMA 23 Standard Hybrid Stepper Motors | MOONS'.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.