I need to get a Stepper motor and a linear actuator to run off the same arduino board as I am building a test rig in work, so far I have got the two devices to work at the same time in roughly the sequence I need but I have some issues that I need to fix, I have never really worked with arduino before and so I am splicing bits of code together and hoping it works! my needs and problems are listed, the code I am using is also attached. Also here is the rundown of what I need the setup to do!
Stepper - Turn 180 clockwise
Piston - Extend fully up and down
Stepper - Turn 180 Anti-Clockwise
Piston - Raise up fully and lower down
then repeat 10,000 times lol
ISSUES
the stepper turns a different direction when turned off and back on
there are large delays between each cycle
I need to be able to adjust the speed of the piston
I don't really know what each piece of code does
Parts used:
-Pololou VNH5019 Motor Driver Shield
Arduino Uno
TB6600 stepper driver
Nema 23 Stepper Motor
12v Linear Actuator
Could someone direct me to a place where I can read about what code I need and how to improve this one or couls someone tell me if this is the best way to go about coding this! Let me know if I need to add anything else!
But as I said in the post I am splicing code together, I have never coded before in my life so my apologies for not having a clue!
I'm going off a user manual for the shield im using and im trying to figure this out blind! Since you seem to be so enlightened in this perhaps you could offer some constructive criticism? And once again I didn't write the code I just mashed two sets together because again, I don't know what im doing lol
I just mashed two sets together because again, I don't know what im doing
Perhaps you should get a clue, before you hurt yourself.
Write ONE sketch that makes the stepper motor step some number of times in one direction. Run it, and verify that the stepper stepped as far as you expected, and no farther.
Only when that works, should you then make the stepper step the same number of times in the other direction, to verify that the stepper returns to the original position.
Then, write another sketch (do not modify the first one) to extend the actuator. When you can control how far the actuator extends, and the speed that it does so at, then make the actuator retract.
Every time you add code to either sketch, RTFM and understand EXACTLY how to use the new statements, what the new functions do, etc.
Then, when it comes to to put it all together, you'll understand what part of the code makes the stepper dance and what part makes the actuator do the hokey pokey.
could you link me to a dictionary or something for the language as im having a hard time understanding what's going on within the IDE! For example what does RTFM mean?
As I said before this is my first time ever coding but I don't think there is any reason to worry about my physical health lol!
I recently made a project very similar to yours, albeit with some different components here and there.
Assuming your wiring is 100% correct-
I'd say FIRST, definitely get working with the "Examples>Basics" sketches found in the Arduino IDE under File>Examples. Study them. Rework them. Make them do slightly different things.
While you're doing that, use this link for reference to lines you don't understand:
After you've gone through line-for-line the first 5 or so "Basic" sketches (which will have seemingly little to do with your project at first glance, but ought to provide a few 'ah hah' moments in terms of 'how to setup arduino code') the next step is to learn to add a new library to your project.
Google this:
'How to install a library arduino'
And download/install this library from your Arduino IDE from the Sketch>Include Libraries>'Manage Libraries' tab:
'AccelStepper' (and any other libraries you might be interested in - they'll automatically install when you click on them)
Then look at this page for reference in code involved with that particular library:
Now, after all this studying, it is still not going to get you coding much on your own. What you need to do for now is go through the examples in the AccelStepper Library and start learning to take lines from one code, and put them in another. If you go through enough examples, you'll start to see it much more clearly.
Now, here's an example (I know, this is probably very different from your code):
// How to use Accelstepper for beginners
// Written by Zach Rockafellow
// May 15th 2019
#include <AccelStepper.h> // We use the #include command to tell the program what libraries we want
AccelStepper linearA(1,8,9); // This gives a name to the motor for the library to use. It can be anything you like - here I chose 'linearA'
// note Arduino is 'case-sensitive'.
// The numbers in parenthesis refer to your pins
// In this particular case, we keep '1', and replace '8' and '9' with the pins that are connected to your motors Left and Right pins (labeled MotorA or MotorB on most chips)
// AccelStepper stepper(1,6,7); // This calls the same library, but shows how you can change the name and pins to match your project.
// ^ Library ^name ^^ Pin numbers.
/*
* AccelStepper must have this info before a motor will move properly:
* a setting for the speed (setMaxSpeed)
* a setting for the acceleration (setAcceleration)
* a position to move to (i.e. 90 steps) (runToNewPosition)
*/
void setup () {
linearA.setMaxSpeed(200); // Change the number in parenthesis Higher=faster. Lower=slower (up to around 32000)
linearA.setAcceleration(2000); // Increase this to make the motor slow down a bit before it gets to the specified position. Higher = sharper transition lower = smoother transition
}
void loop () {
linearA.runToNewPosition(100); // Higher=Wider Radius, Lower = Smaller radius. If your stepper motor has 200 steps, then 200 = 360 degrees. 100 steps = 180 degrees, 50 steps = 90, etc.
linearA.runToNewPosition(-100);// The direction will correspond to your MotorA and MotorB pins. Reverse the two numbers to reverse direction (or change the value in this line and the previous from positive to negative, and vice-versa).
}
// Don't add the delay(); command anywhere, as that will make your motor pause between turns
// There are a half a dozen different ways to write this same exact code. Each will function best in slightly different situations
The library in your original code looks very niche-oriented and probably not the best first step for beginners to arduino and using libraries in general. Learn to use the libraries that have a ton of documentation and support, and that will give you the insight necessary to adapt this project.
Hope that helps!
P.S.
RTFM means 'Read the fucking manual'.
I've got a new one.
LTTTN means 'Learn to talk to Newbies'