controlling stepper with RC

Hello, I'm learning about steppers and need to control one with a radio. I've got a small one connected to an easyDriver and an Arduino UNO with a data pin from an Rx. I've tested my prototype (without the data pin) with this simple code and everything worked fine. I could change the setSpeed() in the code and re-upload and see the changes. I added a few lines to map a variable to the setSpeed so I could control it with an RC, but nothing. I've used this same logic to control an LED so I know I'm close. What's missing?

#include <AccelStepper.h>


AccelStepper postDriver(1, 3, 6); // pin 3 = step, pin 6 = direction

void setup() {
  postDriver.setMaxSpeed(400);
  
  postDriver.setSpeed(200);
  
}

void loop() {  
   postDriver.runSpeed();
  
}
#include <AccelStepper.h>


AccelStepper postDriver(1, 3, 6); // pin 3 = step, pin 6 = direction
int rxPin = 11;
int howFast;


void setup() {
  
  pinMode(rxPin, INPUT);
  
  postDriver.setMaxSpeed(400);
  
  postDriver.setSpeed(howFast);


  
  
}

void loop() {  
  int temp = pulseIn(rxPin, HIGH);
  howFast = map(temp, 1000, 1990, 0, 350);
   postDriver.runSpeed();
   
}

no you are not "close"

pulseIn is a function that waits until the signal turns high.

a standard RC-model-radio sends a HIGH-pulse of 1-2 milliseconds once every 50 milliseconds.
1-2 msecs ................50msecs..............1-2 msecs................50msecs..............1-2 msecs................50msecs..............1-2 msecs

A stepper-motor needs a highly regular pulse-train of short high-pulses on the step-input.

let's say the stepper should run at 240 rpm = 4 rps
400 steps per rotation in halfstep-mode = 1600 pulses per second
1/1600 = 625 microseconds

625 µsecs.........625 µsecs.........625 µsecs.........625 µsecs.........625 µsecs.........625 µsecs.........

runspeed must be called faster than the steps occur. but with pulsein it can't do that.

So what you need is creating the steppulses "in the backround" or receiving the RC-signal "In the backround"

creating steppulses in the backround

there is another stepmotor-library that can do that. It is called MobaTools. and the function rotate() creates an endless pulsetrain of regular step-pulses at the set speed.

this library can be installed with the library-manager

best regards Stefa

That makes sense. Thanks.

Follow up: okay that library is annotated in German and a little beyond me at this point. I can accomplish what I need to using servos. Those look more easily controllable using analogRead() for someone at my level.

Another option which would give more flexibility would be to use a second Arduino and a pair of nRF24L01+ transceiver modules to make your own Transmitter. The messages from an nRF24 won't interfere with the stepper pulses.

...R
Simple nRF24L01+ Tutorial

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