Main > Project Announcements
Stepper motor mechanism for animated cab topper
<< < (8/8)
Kingcade:
Interesting - looks like you're building something with Pac Man similar to what I'm doing with Joust for my cabinet. I can't say I completely follow the mechanics of your build - having pac-man and the ghosts chase each other, perhaps? Anyway, it looks like you've got good people on the job.   :cheers:

Mine is a joust figure moving up and down with a scrolling background, and oddly enough I've been looking at reflecting the whole thing in a Pepper's Ghost illusion. I'm going the all-mechanical route (no servos).
PL1:

--- Quote from: Kingcade on October 03, 2019, 01:27:26 am ---Interesting - looks like you're building something with Pac Man similar to what I'm doing with Joust for my cabinet. I can't say I completely follow the mechanics of your build - having pac-man and the ghosts chase each other, perhaps?

--- End quote ---
The mechanics are relatively simple, but the ramp/track may prove difficult to position and align.
- The stepper motor moves the ghost right/left.
- Hall effect limit switches signal the Arduino when to reverse stepper motor direction.
- The bearing on the tall mount under the ghost rolls on a ramp/track (see test frame diagram in reply #18 and bearing track in reply #13 above) that controls the vertical position of the ghost.
- The stepper motor, moving platform, and lifting arm are hidden in a box.  The viewer only sees the ghost.

The Pac-Man ghost is a placeholder -- it could just as easily be a knight riding an ostrich.   ;D


--- Quote from: Kingcade on October 03, 2019, 01:27:26 am ---Anyway, it looks like you've got good people on the job.   :cheers:

--- End quote ---
I just hope that this mechanism works and looks even half as good as the rest of Josh's cabinet theme.
- The marquee, bezel, and subtle speaker slots are looking great.


--- Quote from: Kingcade on October 03, 2019, 01:27:26 am ---Mine is a joust figure moving up and down with a scrolling background, and oddly enough I've been looking at reflecting the whole thing in a Pepper's Ghost illusion. I'm going the all-mechanical route (no servos).

--- End quote ---
Jennifer will be glad to hear that you're using Pepper's Ghost.   :cheers:

If you eventually decide to make it playable, consider using Hall effect switches to measure the vertical position of your knight and ostrich on one side of the Pepper's Ghost box and the position of the moving platforms on the other side.


Scott
mrclean:
 :applaud: I'm Still keepin' very busy with all my various other builds...but very soon I'll be able to finish on my end within 2 weeks. I previously text you a few days ago just to check in, not sure if you got the text msg haven't heard back, any ways hope all is well !
PL1:
E-mail sent.


Scott
PL1:
"MechDriverAdjustment" sketch for setting Vref so the driver output current does not damage the motor.


--- Code: ---// Adjustment sketch for A4988 driver board installed on stepper motor mech control board.

/*
Sketch sets direction and step pins to constant high so you have time to adjust Vref on the driver.

1. Without stepper motor attached, adjust Vref. (Initial safe setting)
  - Read voltage off metal top of potentiometer on driver.

2. Power off.

3. Attach stepper motor with jumpers, multimeter set to amps in series with coil 1.

4. Power on.

5. Adjust Vref to control current output of driver. (Final accurate setting)
*/

// Adapted from https://dronebotworkshop.com/stepper-motor-hall-effect/

// Define connections
#define DIR       8   // Arduino pin that connects to A4988 driver board DIR pin.
#define STEP      9   // Arduino pin that connects to A4988 driver board STEP pin.

void setup() {

  // Setup the stepper controller pins as Outputs and set the pins to HIGH
  pinMode(DIR,OUTPUT);
  pinMode(STEP,OUTPUT);
 
  digitalWrite(DIR,HIGH);
  digitalWrite(STEP,HIGH);
 
}
 
void loop() {

}

--- End code ---

Latest version of the "MechHallSwitchesInterrupt" sketch for hall-effect limit switches and a microswitch emergency reverse.


--- Code: ---// Stepper motor mechanism controlled by an Arduino Pro Micro, a stepper motor driver board, two Hall Effect directional limit switches, and an emergency reverse microswitch.

// Stepper motor goes one direction until it triggers one Hall Effect switch and goes the other direction until it triggers the other Hall Effect switch and goes the original direction again.

// The emergency reverse switch is there in case power is shut off when the magnet is too close to the Hall Effect sensor on the first travel direction end.
// When power is reapplied, the voltage on that input starts below logic HIGH so the Arduino doesn't see a falling transition from HIGH to LOW.

// *** Test your setup to ensure that the variables on lines 23 and 26 that control the first direction of travel and the limit switch direction changes are correct. ***

// Adapted from https://dronebotworkshop.com/stepper-motor-hall-effect/


// Define connections
#define SWITCH_A  2            // Arduino pin that connects to the limit switch closest to the stepper motor.
#define SWITCH_B  3            // Arduino pin that connects to the limit switch farthest from the stepper motor.
#define SWITCH_E  7            // Arduino pin that connects to the emergency reverse switch.
#define DIR       8            // Arduino pin that connects to the stepper driver board DIR pin.
#define STEP      9            // Arduino pin that connects to the stepper driver board STEP pin.


// Variables
int pd = 180;                  // Pulse duration period in microseconds.  Minimum value is 180 for TMC2130 in Halfstep, 85 in Qtrstep, 45? in 16 μsteps.
boolean setdir = HIGH;         // Set first travel direction to HIGH or LOW. *** Verify that the first travel direction is correct for your setup. ***
boolean emergswdir = !setdir;  // Set emergency reverse switch direction to opposite of setdir.

boolean nearswdir = HIGH;      // Set near switch new direction to either HIGH or LOW. *** Verify that the direction changes triggered by the limit switches are correct for your setup. ***
boolean farswdir = !nearswdir; // Set far switch new direction to opposite of nearswdir.

// Near limit switch interrupt handler.
void limit_a (){
  setdir = nearswdir; // Change motor travel direction.
    delayMicroseconds(pd);
  Serial.println("Go away from the motor"); // Print direction and carriage return.
} // End near limit switch interrupt handler.


// Far limit switch interrupt handler.
void limit_b (){
  setdir = farswdir; // Change motor travel direction.
  Serial.println("Go toward the motor"); // Print direction and carriage return.
} // End far limit switch interrupt handler.


// Emergency reverse switch interrupt handler.
void limit_e (){
  setdir = emergswdir; // Change motor travel direction.
  Serial.println("Emergency reverse"); // Print direction and carriage return.
} // End emergency reverse switch interrupt handler.


void setup() { // Start program setup.

// Set the stepper controller pins as outputs.
pinMode(DIR,OUTPUT);
pinMode(STEP,OUTPUT);

// Set the switches as inputs.  Use INPUT_PULLUP for an internal pullup resistor.  Use INPUT if your Arduino requires an external pullup resistor.
pinMode(SWITCH_A, INPUT);
pinMode(SWITCH_B, INPUT);
pinMode(SWITCH_E, INPUT_PULLUP);

// Attach interrupt pins to handlers.
attachInterrupt(digitalPinToInterrupt(SWITCH_A), limit_a, FALLING);
attachInterrupt(digitalPinToInterrupt(SWITCH_B), limit_b, FALLING);
attachInterrupt(digitalPinToInterrupt(SWITCH_E), limit_e, FALLING);

} // End program setup.


void loop() { // Main program loop.

    // Turn the motor one step in the current direction.
    digitalWrite(DIR,setdir);
    digitalWrite(STEP,HIGH);
    delayMicroseconds(pd);
    digitalWrite(STEP,LOW);
    delayMicroseconds(pd);
    // Print step, direction (0 or 1), and carriage return.
    Serial.print("Step ");
    Serial.println(setdir);

} // End main program loop.

--- End code ---

Breadboard wiring for a TMC2130 v1.1 and an A4988.


Scott
Navigation
Message Index
Previous page

Go to full version