control 2 steppers and a bldc motor

Status
Not open for further replies.

edrummer

Well-known member
I have a brushless dc motor and controller from a rc car. I want to eliminate the rc part and wire it to one axis of ajoy stick, along with a stepper motor on the other axis that would be used for steering, The connection on the motor controller for the receiver is 5v. There is a servo tester that can be hooked up to run the motor without the rc receiver, it just has a pot to control speed, I would need reverse as well for both motors. There will also be a third motor, another stepper that would just have a toggle switch for forward and reverse.
I have 2-L298N Dual H Bridge DC Stepper Servo Motor Drivers and a teensy 3.2 My question is would the the 3.2 be able to control all 3 motors?
 
Can you reuse the existing ESC? That would be the simplest.

The L298N is probably hopeless for high-current RC model motors. And its no use for a modern stepper, that requires something like a DRV8825 module.
 
Thanks, yes I want to use the ESC, If I get the DRV8825 drivers for the steppers the T3.2 will work for all 3 motors?
 
Yes, the T3.2 can drive those step stick drivers - all you need is step and dir. Just make sure you give it 3.3V on the logic supply input. Pololu has a number available and a good comparison chart.

Power is a different issue - many need more than 5V for motor power. Maybe you would be better off with a 5V hobby servo controller for the steering?
 
Thanks for responding, right now I'm just trying to gather the parts and materials for the project. I have the the BLDC with the ESC and 1 stepper if it's big enough. All 3 motors are 24 volts, and will need forward, reverse and speed control. the ESC for the brushless dc motor uses 5v for the radio receiver, which I want to replace with the micro controller and joystick. I would like to stick to 5v if possable even if I have to get a different board, which one would work?
There's a lot of info on how to make the steeper's work, I'm not sure how to get the BLDC to work using the teensy instead of the radio controller.
 
I found this from another forum, with a similar project. (trying to run a rc motor without the radio controller) He's talking about why a servo tester works when connected to an ESC. Anyone know how I might go about getting the teensy to do it instead?

"The ESC runs the motor, but it needs a pulse width modulated throttle signal or the ESC will not arm and will not start the motor.
A switch hooked to the ESC, a motor and battery will not run, because a switch does not produce a pwm signal.
Normally the reciever generates the pwm signal in proportion to throttle stick position, and the ESC reads that signal and sends power to the motor in proportion.
With no receiver, something needs to provide a pulse width signal to the servo lead on the ESC, and that is why the servo tester is needed.''
 
The servo tester works when connected to the ESC because (likely) the ESC has a BEC (battery elimination circuit) -- which is basically a voltage regulator to step down the battery voltage (which is some multiple of the number of battery cells you are using (7.4v 11.1v ...) down to 5v, which the servo tester needs to run.
I've done similar things to what you are talking about, just not all packaged into one project.

TeensyStep is AWESOME for making stepper motors step.
For doing anything related to RC stuff, use a Pololu Maestro servo controller (the 6 channel will be good for starters). The Maestro can output the correct pulses needed to make your ESC do its thing to make your brushless motor GO!
The Maestro has an Arduino library, is straight forward to use, doesn't cost much, and allows you to make forward progress. Its $20 cost is well worth the investment! Yes you can spend a lot of time trying to figure out how to get a library working to output the correct pulses from your Teensy (likely there have been improvements since I last looks a few years ago), but the big take away is that the Maestro is is easy and gets things going -- which IMO is the end goal.
 
Thanks, I have the BLDC working well now, which is the motor for the boat prop. It's connected to one axis of a joystick. It runs well in forward and reverse with speed control. Now I need to get the stepper motor working which is the other axis of the joystick for steering. I'm trying to modify this code Which works well but only in one direction. I need it to work just like the BLDC. (forward and reverse with speed control). any suggestions?
Code:
[CODE]
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 4; 
int customDelay,customDelayMapped; // Defines variables
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
 
  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
  
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}
[/CODE]
 
STOP writing code that uses 'delay'. that included the microdelay... (unless you REALLY know what you are doing).

You are setting yourself up for a world of hurt otherwise.

I am far from a pro coder, but have had the guidance from some very talented embedded engineers -- regurgitating their 'best practice', and ya know what, after following their advice, a lot of my headaches have slowly gone away (surprise surprise).

Please take this in constructive light for I used to be at the state you were -- we all advance with effort.
You using the microdelay in the loop reveals you have more learning to do (as I do too). There are people out there that are REALLY good -- I've found it best to learn how to massage their code so I can use it for my application. Unfortunately, these 'tools' are higher than the low-hanging fruit, so we have to work a little to reap their riches.


As stated prior, use the TeensyStep library: https://github.com/luni64/TeensyStep
https://luni64.github.io/TeensyStep/

Set up a dedicated test platform to get TeensyStep working with your Teensy, a stepper motor driver and a stepper motor. Start out with getting the stepper motor to move. Iterate through a few progressions: Go forward 800 steps, pause, reverse 800 steps (etc). Then do something like hook up a potentiometer (possibly with a detent @ center), and have the stepper motor move to an absolute offset (again, RTFM (if you don't know what that means, look it up!) on use of the TeensyStep protocol).

Take a bunch of small steps advancing your code each revision. Start simple and work your way up. If you can't get the simple one going, you won't get the challenge.
 
/*==========================================================================
* This is a minimal sketch showing the usage of TeensyStep
*
* STEP Pulses on Pin 2 (can be any pin)
* DIR Signall on Pin 3 (can be any pin)
*
* The target position is set to 1000 steps relative to the
* current position. The move command of the controller
* moves the motor to the target position.
*
* Default parameters are
* Speed: 800 steps/s
* Acceleration: 2500 steps/s^2
*
* (slow, but good to start with since they will work on any normal stepper)
*
===========================================================================*/

#include "TeensyStep.h"

Stepper motor(2, 3); // STEP pin: 2, DIR pin: 3 connected to your stepper motor driver
StepControl controller; // Use default settings


void setup()
{

motor.setMaxSpeed(1600); // stp/s
motor.setAcceleration(40000); // stp/s^2
}


void loop()
{

motor.setTargetRel(250); // Set target position to 250 steps from current position
controller.moveAsync(motor); // Do the move
delay(1000);
}
 
Status
Not open for further replies.
Back
Top