Punch Machine Remix

Hi Everyone,

I'm very late to this type of fun but hope you all will not be too hard on me.
I own a Boxing Club and am interested in introducing an after school program that would include Arduino based projects and 3D printing.
I would like to build a few myself first and have a better understanding before doing so and hope you may all be of great help.
I have printed out one of these punch machines (2 actually, one will house a full sized glove)
I would like to have this activated off of a push button.
any help would be appreciated. here is the resource information i have been using before i realized i was out of my wheel house.

Again I do realize what I'm asking here and do try not to be too hard on me.

If you have all the 'component list' hardware from the second (matterhackers) link you posted.

COMPONENT LIST (What you will need)

Printed Parts (doanload them on this page)
1×NEMA 17 Stepper Motor
1×Polulu Stepper Motor Driver
1×OpenBeam 24 cm Extrusion
34×623ZZ Ball Bearings3mm ID, 9.5mm OD
14×M3 x 12 Bolts
2×M3 x 20 Bolts
18×M3 x 8 Bolts
30×M3 Nuts
20×M3 Washers

and add to it an Arduino and a simple push to make switch then the sample code (also posted in your link) is pretty much what you need to control the stepper, you just need to add the button reading bit to call the punch subroutine.
Search and you will find lots of examples of how to connect a switch to an Arduino. Read the switch and act on the result (pushed of not). Then add in the servo control code (after slight editing) and you should have what you need.

If you get stuck then ask more questions so we can point you in the right direction.

That's great news, I do have everything from the list so will spend some time today.
Thank you for your insight, I will make sure I have everything possible covered with a set of detailed questions if I need more help.
Thanks again!!

So I was able to get the Button Set up and was able to change the code so the led is on until pushed,

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:
if (buttonState == LOW) {
// turn LED off:
digitalWrite(ledPin, HIGH);
} else {
// turn LED on:
digitalWrite(ledPin, LOW);
}
}

So i do i make it so the punch is representative of the led?
Sorry I'm just so confused, I Can see what I did with the led, reversing it I mean.
I feel like I'm lost once again.

case 42: // G42
if(code_seen('F')) {
punch(code_value());
} else {
punch(50);
}

void punch(float speed)
{
int delayLength = 1000 / (speed*2);
SERIAL_ECHOLN("WHAM!");
// Enable driver
digitalWrite(PUNCH_ENABLE_PIN, LOW);
// Set direction
digitalWrite(PUNCH_DIR_PIN, HIGH);
// Punch
// Idea: Ramp up speed
for (int i=0; i<150; i++) {
delay(delayLength);
digitalWrite(PUNCH_STEP_PIN, HIGH);
delay(delayLength);
digitalWrite(PUNCH_STEP_PIN, LOW);
}
// Reverse direction
digitalWrite(PUNCH_DIR_PIN, LOW);
// Retract
for (int i=0; i<150; i++) {
delay(10);
digitalWrite(PUNCH_STEP_PIN, HIGH);
delay(10);
digitalWrite(PUNCH_STEP_PIN, LOW);
}
// Disable driver
digitalWrite(PUNCH_ENABLE_PIN, HIGH);
}

Your doing okay getting as far as you have.
It is now just a case of adding the slightly modified punch() code.
I do not know how you have the stepper motor driver wired up or what pin the button is on but just adjust the code to suit.

#define PUNCH_ENABLE_PIN 10 
#define PUNCH_DIR_PIN 11
#define PUNCH_STEP_PIN 12

#define LED 13
#define BUTTON 8

void setup() {
  // initialize the LED pin as an output:
  pinMode(LED, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(BUTTON, INPUT_PULLUP);
  // init the stepper driver pins
  pinMode(PUNCH_ENABLE_PIN, OUTPUT);
  pinMode(PUNCH_DIR_PIN, OUTPUT);
  pinMode(PUNCH_STEP_PIN, OUTPUT);
}

void loop() {
  // read the state of the pushbutton value:
  byte buttonState = digitalRead(BUTTON);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is LOW:
  if (buttonState == LOW) 
  {
    // turn LED off:
    punch(50);
    digitalWrite(LED, HIGH);
  } 
  else 
  {
    // turn LED on:
    digitalWrite(LED, LOW);
  }
}

void punch(float speed)
{
  int delayLength = 1000 / (speed*2);
  // Enable driver
  digitalWrite(PUNCH_ENABLE_PIN, LOW);
  // Set direction
  digitalWrite(PUNCH_DIR_PIN, HIGH);
  // Punch
  // Idea: Ramp up speed
  for (int i=0; i<150; i++) {
    delay(delayLength);
    digitalWrite(PUNCH_STEP_PIN, HIGH);
    delay(delayLength);
    digitalWrite(PUNCH_STEP_PIN, LOW);
  }
  // Reverse direction
  digitalWrite(PUNCH_DIR_PIN, LOW);
  // Retract
  for (int i=0; i<150; i++) {
    delay(10);
    digitalWrite(PUNCH_STEP_PIN, HIGH);
    delay(10);
    digitalWrite(PUNCH_STEP_PIN, LOW);
  }
  // Disable driver
  digitalWrite(PUNCH_ENABLE_PIN, HIGH);
}

Wow thank you, I should have mentioned before I'm using the drv8825 setup from pololu.com
So I will still need to figure out how to get that button involved.
Also the led is in the button, SPST tactile button red momentary w/red led SWTAC510442
Was puzzled by the extra 2 prongs at the bottom(has 6) where my other buttons only have 4.

miketheboxer:
Wow thank you, I should have mentioned before I'm using the drv8825 setup from pololu.com
Either connect the driver board to the pins defined in the sketch or alter the sketch to match your connections.
So I will still need to figure out how to get that button involved.
The code I posted already has the button included.
Also the led is in the button, SPST tactile button red momentary w/red led SWTAC510442
Was puzzled by the extra 2 prongs at the bottom(has 6) where my other buttons only have 4.
You will need to check if a resistor is needed inline with the LED to reduce the current drawn from the Arduino pin else you could damage the Arduino.

I don't know if this will work but i posted a little message on my Facebook page, I'm not too sure how to post images here.
Please have a look. I have been messing around a bit trying to combine the two setups but once again hitting that wall with ideas.
You have been so patient and helpful with this whole process. One this thing gets finished I plan on giving you praise and credit for without you i do not think i would be able to finish this great project.

If you have any solutions I would be ever so grateful once again

I don't use Facebook but following the link shows a couple of images but it's impossible for me to determine what wire goes where.

Please have a look. I have been messing around a bit trying to combine the two setups but once again hitting that wall with ideas.

What two setups are you talking about? The code I posted should be a finished working program that just needs the relevant drv8825 pins connected as per sketch or the sketch pin numbers altered to match how you currently have it wired to the Arduino.

Try and draw an image of how the drv8825 board is wired to the Arduino or list the pin numbers/names on each side in a table.
The Pololu site shows the board wired like this...

and the code defines the Arduino pins like this...

#define PUNCH_ENABLE_PIN 10
#define PUNCH_DIR_PIN 11
#define PUNCH_STEP_PIN 12