paulornothing:
A few last questions. I was just planning on doing the setup you have except utilizing a USB 10,000 mah battery back up. One arudino would just give power to the motor and the other arduino runs the code. There are two powered usb outs from the battery pack. I assume that should work fine (just tested out the motor doing the same thing except using usb from my computer for power). Any concerns with the setup I explained?
I don't quite understand why you feel that you need a second Arduino just to provide power. Ignore what the guy who wrote that article did.
I assume that the outputs from the battery pack are 5V, so why connect a second Arduino? Connect one 5V output to the stepper driver, the other to the Arduino, and you're good to go. (They should share a common ground, so you shouldn't need to do that externally.)
Make sure that you connect the 5V supply to the Arduino's 5V rail, NOT to the Vin input or the barrel jack. In my test, I just used a single supply as shown, a 12V 7Ah SLA battery regulated by a 5V 5A DC-DC converter. I put a 100uF cap on the 5V rail for smoothing any noise created by the motor.
Any ideas on what I should do if I wanted to add a start stop button to this setup?
Needless to say, you'll have to write some code to do that. You'll need a button debounce, and a 'state' variable to flag whether the motor should be running or stopped.
Something like:-boolean runEnabled;
Use the button press to toggle that variable between true and false like this:-runEnabled ^= 1;
then:-
if(runEnabled)
stepper1.runSpeed();
I won't write it for you - it's a good chance for you to learn a bit, but this might help with debounce:-
/* SimpleDebounce.ino
*
* Notes:-
* A test of a simple but effective button debounce function.
*
* This returns true if the button has been pressed:-
* bool checkButton(byte currentButton, unsigned long *pPrevButtonMillis)
*/
// Defines:-
#define DEBOUNCE_DELAY 250
// Pin allocations:-
const byte button1Pin = 2;
const byte led1Pin = 3;
const byte button2Pin = 4;
const byte led2Pin = 5;
void setup()
{
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop()
{
static bool led1State = 0;
static bool led2State = 0;
static unsigned long prevButton1Millis = 0;
static unsigned long prevButton2Millis = 0;
// Check pushbutton1:-
if (checkButton(button1Pin, &prevButton1Millis))
{
led1State ^= 1;
digitalWrite(led1Pin, led1State);
}
// Check pushbutton2:-
if (checkButton(button2Pin, &prevButton2Millis))
{
led2State ^= 1;
digitalWrite(led2Pin, led2State);
}
}
bool checkButton(byte currentButton, unsigned long *pPrevButtonMillis)
{
unsigned long currentMillis = millis();
if (currentMillis - *pPrevButtonMillis >= DEBOUNCE_DELAY)
{
if (digitalRead(currentButton) == LOW)
{
*pPrevButtonMillis = currentMillis;
return true;
}
}
return false;
}