Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up --- Bug Reports --- Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Stepper motor mechanism for animated cab topper  (Read 205 times)

0 Members and 1 Guest are viewing this topic.

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Stepper motor mechanism for animated cab topper
« on: August 14, 2019, 01:20:00 am »
This project thread was split from mrclean's inquiry here about using a small motor to generate linear motion.
-------------------------
Without revealing the theme, the mechanics that Josh and I have been discussing have evolved into something more complicated (and cooler  ;D) than previously discussed in this thread.

- An arm raises/lowers about 2-3(?) inches.
-- There is a 608 bearing (or similar) on the side of the arm.
-- The item being raised/lowered at the end of the arm weighs less than one ounce.

- A motor moves a platform 8-10(?) inches horizontally.
-- The arm is mounted on this platform.  The arm's fulcrum axis is perpendicular to the direction of travel.
-- This platform is WAY too heavy for the 28BYJ-48.

- The rise/fall of the arm is controlled by the bearing rolling through a track on a vertical piece of MDF (or layered acrylic?) mounted parallel to the moving platform.
-- If the arm is moving left to right and the track is shaped like this ----\__/\_/\___ the arm will start high, then dip low, pop up/down twice and end low
-- The bearing might pop out of the track if improperly aligned.  Proper design should minimize this risk.

- It's probably best to use a leadscrew, pillow bearings, and two limit switches (not shown) in the horizontal drive mech.
-- It's far more durable than a scotch yoke .
-- Used in the Z-axis of many 3d printers and CNC machines.

- Will need to find/write Arduino code to make the motor run one direction until it hits a limit switch, then run the other direction until it hits the other limit switch.
---------------------
NEMA series motors with A4988 driver boards have the power to do everything Josh wants to do, but they are much louder than the 28BYJ-48.

The hard part is finding something between the $2 28BYJ-48 (380 g-cm) and a $10-15 NEMA 17 (60oz.in ==> 4320 g-cm?) commonly used in 3d printers/CNC machines.

Any suggestions for an inexpensive, quiet stepper motor/driver combo mid-way between the 28BYJ-48 and NEMA 17?


Scott
« Last Edit: September 10, 2019, 08:06:46 pm by PL1 »

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #1 on: August 15, 2019, 06:52:31 am »
At slow speeds the noise would be less. Personally I like the bigger motor option, And would look for and upgrade to quality (brass or steel gears) for not only a good long life, but potential for less noise...But before I go I have to ask, does it really need to move something? or could the illusion of something being moved suffice? Peppers ghost is quite fun.
« Last Edit: August 15, 2019, 06:55:33 am by jennifer »

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #2 on: August 15, 2019, 10:02:16 am »
Personally I like the bigger motor option
Didn't find any mid-range options and the 28BYJ-48 obviously doesn't have the torque, so I ordered two NEMA17 motors, some A4988 driver boards, a lead screw set similar to the one pictured above, and some 608 bearings.

And would look for and upgrade to quality (brass or steel gears) for not only a good long life, but potential for less noise.
No gears in this design.
- The lead screw coupler connects directly to the motor shaft to power the horizontal drive train.
- The lifting arm will use 608 roller bearings, so that part will be very quiet.

Depending on how noisy the prototype is, I may need to add a vibration isolation mount for the motor.

But before I go I have to ask, does it really need to move something? or could the illusion of something being moved suffice? Peppers ghost is quite fun.
Yes, Peppers ghost is fun, but it wouldn't work for this theme.

The physical movement of a 3d printed part travelling 8-10 inches horizontally and 2-3 inches vertically is essential to making Josh's theme work properly.


Scott

Mike A

  • Trade Count: (0)
  • Full Member
  • ***
  • Online Online
  • Posts: 3520
  • Last login:Today at 11:25:45 am
  • card carrying purist
Re: Stepper motor mechanism for animated cab topper
« Reply #3 on: August 15, 2019, 10:33:36 am »
What is this for?

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #4 on: August 15, 2019, 11:03:59 am »
What is this for?
Read this post and the next 17 replies.  :P   :lol


Scott

Mike A

  • Trade Count: (0)
  • Full Member
  • ***
  • Online Online
  • Posts: 3520
  • Last login:Today at 11:25:45 am
  • card carrying purist
Re: Stepper motor mechanism for animated cab topper
« Reply #5 on: August 15, 2019, 11:13:08 am »
So what is it for?

None of those posts answer my simple question.
« Last Edit: August 15, 2019, 11:16:52 am by Mike A »

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #6 on: August 15, 2019, 05:51:43 pm »
So what is it for?

None of those posts answer my simple question.
Basically it is the ideas behind an idea, (Although yes, there are some missing facts)...You should watch those videos when you got some time, You will not be dissapointed  at the lack of convention.
« Last Edit: August 15, 2019, 05:53:16 pm by jennifer »

Mike A

  • Trade Count: (0)
  • Full Member
  • ***
  • Online Online
  • Posts: 3520
  • Last login:Today at 11:25:45 am
  • card carrying purist
Re: Stepper motor mechanism for animated cab topper
« Reply #7 on: August 15, 2019, 06:13:15 pm »
I get the idea. I just want to know what the ultimate goal is.

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #8 on: August 15, 2019, 07:11:31 pm »
Does it really matter? If you understand how it is done the execution and what you are capable of, your idea could be so much better...

Mike A

  • Trade Count: (0)
  • Full Member
  • ***
  • Online Online
  • Posts: 3520
  • Last login:Today at 11:25:45 am
  • card carrying purist
Re: Stepper motor mechanism for animated cab topper
« Reply #9 on: August 15, 2019, 07:27:50 pm »
It's called curiosity. Look it up and report back to me.

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #10 on: August 15, 2019, 07:57:47 pm »
It's called curiosity. Look it up and report back to me.
Jennifer reporting back sir... I looked it up and found you to be lacking in the fabrication dept...GO BUY A WELDER!!!!

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #11 on: August 15, 2019, 08:14:29 pm »
I get the idea. I just want to know what the ultimate goal is.


Wait . . . that's not it.

The ultimate goal is . . . a     mechanically     animated     cab     topper     with     the    same    dedicated     theme     as     the     video     game     inside     the     cab . . . but for today, we'll settle for annoying the card carrying purists.   :duckhunt   jk

Picture an animated (i.e. moving) toy from a pinball game sticking out through the top of a full-width, 6" tall(?) box on top of the cab.
- The front edge of the box is directly above the marquee.
- The box hides the animation mechanism and has paint or artwork related to the theme.


Scott

Mike A

  • Trade Count: (0)
  • Full Member
  • ***
  • Online Online
  • Posts: 3520
  • Last login:Today at 11:25:45 am
  • card carrying purist
Re: Stepper motor mechanism for animated cab topper
« Reply #12 on: August 15, 2019, 08:29:25 pm »
That could be interesting.
Any specific game ideas yet?

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #13 on: August 15, 2019, 10:40:10 pm »
That could be interesting.
Any specific game ideas yet?
Yes, as implied earlier.
Without revealing the theme

If anyone wants to play along just pick a game, figure out what motion you need to tell the story, and design the track.

For example, if you wanted a Super Mario Bros. theme:

- Put a horizontal pipe on the left and a vertical pipe on the right.

- Use one motor to drive two Goombas back and forth, one on each side of a 2 or 3 block high center wall.
-- Limit switches tell the controller to reverse the motor.

- Mario is on the lifting arm platform driven by a second motor moving slightly faster horizontally than the Goomba motor.
-- An open-top guide track for the first lifting arm bearing (yellow) has a few vertical "jumps", one of them so he clears the center wall, one so he jumps into the pipe on the right, and one or two more for fun.
-- Put a second bearing on the other side of the arm that is pushed up by an angled block that is part of the Goomba mount. Instead of running into the Goomba, Mario "jumps" it.

- When Mario gets to the right side and drops into the pipe, he falls down to the bottom, and continues to move to the right. Shortly after that, the platform hits a limit switch and the Mario motor reverses.

- As Mario moves all the way to the left, the bearing (yellow) passes under a 45 degree "trapdoor" (red) which falls down behind the bearing after it passes.  Shortly after that, the platform hits a limit switch and the Mario motor reverses again.

- The bearing now rolls over the top of the 45 degree "trapdoor" and up until Mario exits the horizontal pipe, starting the cycle again.

Bonus points for adding relevant sound FX -- see WannabeJoy's project here for the board to use.

Double bonus points for getting Mario to punch a brick and have a coin pop up.

Super triple bonus points for adding a mech showing Mario running right-to-left through the underground with a guide track shaped like a wider, flatter, vertically-flipped hysteresis curve that slides the underground Mario an inch or two toward the back of the mech on the left end of the Mario motor travel so underground Mario is behind a wall as he moves to the right.  Underground Mario is pushed toward the front of the mech as he reaches the right end of the Mario motor travel.  As underground Mario travels left in front of the wall, the wall blocks the view of above-ground Mario as he also moves left.     ;D


Scott
« Last Edit: August 15, 2019, 10:47:30 pm by PL1 »

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #14 on: August 16, 2019, 11:07:45 am »
Peppers ghost is quite fun

Nice first I'm seeing Peppers Ghost, (also eerily enough this reply was made when exactly 666 views were on the topic) I've heard of Ghost Peppers don't think my stomach can handle either of them.

That could be interesting.
Any specific game ideas yet?



Well... It's a secret to mostly everybody.
2,370,650 Gun.Smoke

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #15 on: August 16, 2019, 11:55:37 am »
Well you wouldn't need to use scary ghosts, It was more about being less mechanical and complex, and still maintaining the same effect with illusion...We don't got many secrets around here, Do not be afraid to document a build for everyone to enjoy and get some ideas from.

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #16 on: August 18, 2019, 03:32:00 am »
Progress update.

Switching power supply arrived.  Thanks, Josh.   ;D

Spent several hours slogging through tutorials on YouTube.

Found a video that shows the basic motion and controls that we need for this project.   :applaud:



The video description has a link to Maker Tutor's blog post here where she posted the related code.

Code: [Select]
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int LimitSwitch_LEFT_Pin  = 10;
const int LimitSwitch_RIGHT_Pin = 11;

void setup() {

  Serial.begin(9600);

  pinMode(LimitSwitch_LEFT_Pin , INPUT);
  pinMode(LimitSwitch_RIGHT_Pin , INPUT);

  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);

  // Set Dir to Home switch
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction


}
void loop() {

    int leftSw  = digitalRead( LimitSwitch_LEFT_Pin);
    int rightSw = digitalRead( LimitSwitch_RIGHT_Pin);
   
    if( (leftSw  == HIGH && (digitalRead(dirPin) == HIGH)) ||
        (rightSw == HIGH && (digitalRead(dirPin) == LOW)) ){
   
        motorStep(1);

    }
    else if( leftSw == LOW && (digitalRead(dirPin) == HIGH) ){
          digitalWrite(dirPin,LOW);
          delay(2000);
    }
    else if( rightSw == LOW && (digitalRead(dirPin) == LOW ) ){
          digitalWrite(dirPin,HIGH);
          delay(2000);
    }
 
}
void motorStep( int MAX){

   for(int x = 0; x < MAX; x++) {
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(500);
        digitalWrite(stepPin,LOW);
        delayMicroseconds(500);
      }
     
}

One possible concern is that the code is written for and tested on a TB6560 driver board and uses proximity switches instead of physical switches.

The good news is that the basic inputs on an A4988 and a TB6560 appear to be the same.

If so, with a few minor edits this code should do exactly what we need.   ;D

Found several other neat videos by Maker Tutor.

This may come in handy if you want to test which wire pair goes to the same coil.
- Turning the shaft induces an alternating electrical charge as the north and south poles of the magnetic field pass through the coil.



How much of an electrical charge does it generate?  Enough to do this.   :lol




Scott
« Last Edit: August 18, 2019, 03:34:54 am by PL1 »

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #17 on: August 18, 2019, 01:33:08 pm »
Progress update.

Switching power supply arrived.  Thanks, Josh.   ;D


No problemo! Watched all the videos, excited to see some of those techniques applied to this particular project.  :cheers:
2,370,650 Gun.Smoke

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #18 on: August 19, 2019, 07:51:40 am »
Finished initial design for the test frame.

The left half is pretty well locked in position.

- Attach the PSU on the top/back of the 2x2x8 pieces.

- Attach the 1x4x24 on the top/front of the 2x2x8 pieces.

The right half may need to move right/left, depending on the design and placement of the moving platfrom and lifting arm.  For now, I'll use some bar clamps to hold the 1x4x24 assembly to the 1x8x12 assembly.

- Attach the 1x8x12 to the back of the 2x2x4 pieces. (NOTE: This must form a 90 degree angle so the face of the test ramp is perpendicular to the 1x4x24.)

- The 24mm tall spacer blocks create a space for the platform bearing to roll. (a 608 bearing has a 22mm o.d.)
-- It rolls between the top of the 1x4x24 and the bottom of the test ramp.
-- The bearing keeps the platform level, preventing it from rotating around the x-axis as the stepper motor drives the lead screw nut.
-- Depending on the amount of wiggle/slop in the platform drive mech, I might need to add two 608 bearings to prevent z-axis rotataion of the platform or (worst case scenario) upgrade to optical guide rod and two LM8UU bearings. (adds about $15 to the build cost)

- The test ramp rests on top of the spacer blocks.
-- It guides the lifting arm bearing, allowing you to test different arm lengths, track patterns, "trapdoor" designs, etc.
-- Include clamp arms in your test ramp so you can secure it to the 1x8x12.

The power distribution harness, Pro Micro, and A4988 drive board mount on a piece of 1x2x8 between the PSU and 1x4x24.

The stepper motor, lead screw, pillow bearings, directional switches and emergency stop switches mount on the 1x4x24. (stepper motor on the left)


Scott

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #19 on: August 19, 2019, 07:59:44 pm »
Where it says PSU I'm assuming that's the switching Power Supply Unit ? I'm confused by that typically I place them inside cabinets as opposed to ontop, figured I would just run the Ground / voltage from the Switching Power Supply with wires up to the top of the cabinet retaining the power supply on the inside of the cabinet.
2,370,650 Gun.Smoke

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #20 on: August 20, 2019, 12:27:02 am »
My pet unicorn just observed that it's unrealistic for me to expect lightning-fast bulletproof results when doing a complicated first build requiring a newly-learned skillset with a somewhat steep learning curve and few clearly relevant examples to follow.  [/snark]   :lol

Crawl.  Walk.  Run.

This is the initial test frame. (crawl)

The mechanism is too complicated to go from rough idea to working prototype in one step without engineering and CAD skills that far exceed mine.

This is where I learn what works and if certain design assumptions are valid or not.

- Is one 608 bearing enough to keep the platform moving straight or does it require two more bearings on a T-shaped platform to keep it from twisting on the z-axis or does it require an optical guide rod and two linear bearings on a T-shaped platform?

- Does the lifting arm bearing need to be in a captive track or will it work with an open edge?

- How steep of an up-ramp is possible?

- Are there any unforseen complications?  * Shakes Magic 8-ball.  "Very likely." *

It will be fairly easy to transplant the electronics and drive train to a prototype when the time comes to walk.   ;D


Scott

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #21 on: August 24, 2019, 08:25:10 pm »
Big progress on the Arduino code.   ;D

Baritonomarchetto suggested using "INPUT_PULLUP" instead of "INPUT".   :cheers:

Added extensive comments to the code so even Arduino noobs can understand and modify it.

Arduino inputs and outputs confirmed working as expected using some spare pushbuttons and LEDs (with current limiting resistors  ;) ) on pins 2 (step) and 3. (direction)
- You need to verify that your driver and motor combination will initially drive the mechanism toward the correct switch BEFORE connecting the motor to the mechanism.  Failure to do this can damage the mechanism.
- Had to add a one second troubleshooting delay to slow down the program loop long enough to see the "step" LED on pin 2 blink.  The delay is commented out in the code below. "// delay(1000);"

Added code for optional cooling pauses during direction changes.  The related nine lines are currently commented out.

Remove the "//" at the beginning of a line of code to "uncomment" it.
- Second line of code commented out.
Code: [Select]
const int dirPin = 3; // Arduino pin that connects to A4988 driver board DIR pin.
// const int enPin = 5; // Arduino pin that connects to A4988 driver board ENA(not) pin. (ENA with line over it)
- Second line uncommented.
Code: [Select]
const int dirPin = 3; // Arduino pin that connects to A4988 driver board DIR pin.
const int enPin = 5; // Arduino pin that connects to A4988 driver board ENA(not) pin. (ENA with line over it)

This code should be about 98% done.

Need to dial in the step pulse duration with a complete Arduino/driver/motor setup.

Code: [Select]
// Stepper motor mechanism controlled by an Arduino Pro Micro, an A4988 driver board, and two directional switches.

// Stepper motor goes one direction until it hits that directional switch then reverses until it hits the other switch then goes the original direction again.

// Adapted from http://www.arduinotutorialonline.com/2017/12/control-stepper-forward-and-reverse_17.html

// **********************
// *** IMPORTANT NOTE ***
// **********************
// Verify that your driver and motor combination will initially drive the mechanism toward the correct switch BEFORE connecting the motor to the mechanism.
// Failure to do this can damage the mechanism.


// Define Arduino digital pin numbers.
const int stepPin = 2; // Arduino pin that connects to A4988 driver board STEP pin.
const int dirPin = 3; // Arduino pin that connects to A4988 driver board DIR pin.
// const int enPin = 5; // Arduino pin that connects to A4988 driver board ENA(not) pin. (ENA with line over it)  Not needed unless the pause code for cooling during direction switch is uncommented below.
const int DirectionalSwitch_LEFT_Pin  = 8; // Arduino pin that connects to the left directional switch.
const int DirectionalSwitch_RIGHT_Pin = 9; // Arduino pin that connects to the right directional switch.
// End of defining Arduino digital pin numbers.


// Initial settings.
void setup() {

  // Open serial port, set data rate to 9600 bps.
  Serial.begin(9600);

  // Set pins as inputs.
  pinMode(DirectionalSwitch_LEFT_Pin,INPUT_PULLUP);
  pinMode(DirectionalSwitch_RIGHT_Pin,INPUT_PULLUP);

  // Set pins as outputs.
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  // Set pin as output for A4988 driver board ENA(not) control and enable current to the motor.
  // These two lines are not used unless the pause code for cooling during direction switch is uncommented below.
  // pinMode(enPin,OUTPUT);
  // digitalWrite(enPin,LOW); // LOW enables current to the motor.  HIGH disables current to the motor.

  // Set starting direction of rotation.
  digitalWrite(dirPin,HIGH); // HIGH ==> physical left switch first.  LOW ==> physical right switch first.  See IMPORTANT NOTE at top.

}
// End of the initial settings.


// Define the program loop.
void loop() {

    // Read the switch states.
    int leftSw  = digitalRead( DirectionalSwitch_LEFT_Pin);
    int rightSw = digitalRead( DirectionalSwitch_RIGHT_Pin);
   
    // If neither switch is pressed, send motor step pulse.
    if( (leftSw  == HIGH && (digitalRead(dirPin) == HIGH)) ||
        (rightSw == HIGH && (digitalRead(dirPin) == LOW)) ){

        // delay(1000); // Delay to slow the loop enough to see an LED on stepPin blink on and off every second.  Troubleshooting use only.
        motorStep(1); // Calls motorStep function. (defined below)

    }

    // If left switch is pressed and direction pin is HIGH, change direction pin to LOW.
    else if( leftSw == LOW && (digitalRead(dirPin) == HIGH) ){
          digitalWrite(dirPin,LOW);
          // digitalWrite(enPin,HIGH); // Disable motor for motor or driver cooling.
          // delay(5000); // Miliseconds to pause for cooling.
          // digitalWrite(enPin,LOW); // Enable motor after cooling.
          delay(500); // Miliseconds to pause after switching direction.
          motorStep(100); // Take steps in the new direction to un-press the switch.
    }
   
    // If right switch is pressed and direction pin is LOW, change direction pin to HIGH.
    else if( rightSw == LOW && (digitalRead(dirPin) == LOW ) ){
          digitalWrite(dirPin,HIGH);
          // digitalWrite(enPin,HIGH); // Disable motor for motor or driver cooling.
          // delay(5000); // Miliseconds to pause for cooling.
          // digitalWrite(enPin,LOW); // Enable motor after cooling.
          delay(500); // Miliseconds to pause after switching direction.
          motorStep(100); // Take steps in the new direction to un-press the switch.
    }
 
}
// End of the program loop.


// Define the motorStep function.
void motorStep( int MAX){

   for(int x = 0; x < MAX; x++) {
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(500); // Controls step pulse high duration. Default = 500?
        digitalWrite(stepPin,LOW);
        delayMicroseconds(500); // Controls step pulse low duration.
        // Total duration of step pulse (high + low) determines speed of motor.
      }
     
}
// End of the motor Step function.

LMK if you find any errors in the code or comments.   ;D


Scott
EDIT: Almost forgot about hysteresis in microswitches.    :banghead:
Added code to take 100 steps (about 1/2 of a revolution on many stepper motors) after changing direction.
That should be far enough to release the switch that was pressed and keep the program loop from getting stuck.
« Last Edit: August 24, 2019, 09:01:28 pm by PL1 »

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #22 on: August 24, 2019, 10:03:22 pm »
Big progress on the Arduino code.   ;D

Nice!!!

"We have top men working on it right now", "who"...... "top men". - Indiana Jones

I absolutely can't wait to see all this collectively come together!!!  :applaud:



2,370,650 Gun.Smoke

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #23 on: August 25, 2019, 04:55:22 pm »
What am I missing here?   :dunno

The motorStep function is only called three places in the code.
- 1 step if neither switch is pressed. (short LED blink)
- 100 steps after changing dirPin HIGH to LOW. (long LED blink)
- 100 steps after changing dirPin LOW to HIGH. (long LED blink)

The comment for the switch not pressed section, "// If neither switch is pressed, send motor step pulse." is what the logic appears to say, but isn't what the program loop is doing.

What the program loop is expected to do:
Code: [Select]
    if( (leftSw  == HIGH && (digitalRead(dirPin) == HIGH)) ||
        (rightSw == HIGH && (digitalRead(dirPin) == LOW)) ){

        motorStep(1); // Calls motorStep function. (defined below)

    }

Code translated into a logic statement:
If (leftSwitch isn't pressed AND dirPin=high) OR (rightSwitch isn't pressed AND dirPin=low) THEN motorStep(1).

If leftSwitch is held closed and dirPin is high, it shouldn't send motorStep(1) because neither of the two IF options are true.
- First option (red) is false because leftSwitch is pressed.
- Second option (green) is false because dirPin=high.
- With both IF options false, the program loop should go to the next item (check for direction change), not execute the THEN, right?

What the program loop is actually doing:
Holding one button pressed does not stop the program loop from sending "short LED blink" single step commands.
- Changes direction when the other switch is pressed then changes back on the next program loop cycle.
- "Short LED blink" step commands sent whether dirPin is high or low.

Holding both buttons pressed does not stop the program loop from sending "short LED blink" single step commands.
- Changes direction with each program loop cycle.
- "Short LED blink" step commands sent whether dirPin is high or low.

What am I missing?


Scott
« Last Edit: August 25, 2019, 04:57:09 pm by PL1 »

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #24 on: August 26, 2019, 11:57:19 pm »
Made an OpenSCAD 3d printable mount for the lead screw bearings shown in the first pic below.
- Fully parametric.  Change any of the 12 variables to alter the part as desired.
- Part renders in the correct orientation for the strongest print.

Code: [Select]
// Bearing mount bracket (vertical face)

// Width, height, and depth variables are relative to the part being upright as installed, not on it's side as generated.

// For best part strength, print on it's side, NOT upright or face down.

/////////////////////////////
// Define variables
/////////////////////////////
FPWidth = 48;     // Faceplate width
FPHeight = 48;    // Faceplate height
FPDepth = 4;      // Faceplate depth
BoreHeight = 31;  // Center height for bearing rotation axis
BScrewDist = 37;  // Bearing screw distance (center-to-center)
BScrewDia = 5;    // Bearing screw diameter
BHoleDia = 26;    // Bearing center hole diameter

BPWidth = 48;     // Baseplate width
BPHeight = 4;     // Baseplate height
BPDepth = 20;     // Baseplate depth
BPScrewDia = 4;   // Baseplate screw diameter
BPScrewDist = 30; // Mount screw distance (center-to-center)

// Number of fragments (polygon sides) used to render a full circle.
    $fn = 180; // Default = 180  Typical range = 6 - 360
    // 6 will render a circular hole as a hexagon, 8 will render a circular hole as an octagon.
    // Lower the number for faster rendering, raise the number for smoother rendering.

/////////////////////////////
//  Make the part
/////////////////////////////

difference(){ // Faceplate minus screw and center holes
   
    translate([FPHeight/2, FPDepth/2, FPWidth/2])
    cube([FPHeight, FPDepth, FPWidth], center=true);
    // Faceplate

    rotate([90, 0, 0])
    translate([BoreHeight, (FPWidth/2)+(BScrewDist/2), -FPDepth/2])
    cylinder(FPDepth+1, d=BScrewDia, center=true);
    // Screw hole 1

    rotate([90, 0, 0])
    translate([BoreHeight, (FPWidth/2)-(BScrewDist/2), -FPDepth/2])
    cylinder(FPDepth+1, d=BScrewDia, center=true);
    // Screw hole 2

    rotate([90, 0, 0])
    translate([BoreHeight, FPWidth/2, -FPDepth/2])
    cylinder(FPDepth+1, d=BHoleDia, center=true);
    // Center hole

    } // End faceplate minus screw and center holes
//
difference(){ // Baseplate minus screw holes
   
    translate([BPHeight/2, BPDepth/2, BPWidth/2])
    cube([BPHeight, BPDepth, BPWidth], center=true);
    // Baseplate

    rotate([0, 270, 0])
    translate([(BPWidth/2)+(BPScrewDist/2), (BPDepth/2)+FPDepth/2, -BPHeight/2])
    cylinder(BPHeight+1, d=BPScrewDia, center=true);
    // Screw hole 1

    rotate([0, 270, 0])
    translate([(BPWidth/2)-(BPScrewDist/2), (BPDepth/2)+FPDepth/2, -BPHeight/2])
    cylinder(BPHeight+1, d=BPScrewDia, center=true);
    // Screw hole 2

    } // End baseplate minus screw holes
//

You may want to avoid this type of bearing.



This type is the better choice.
- Less hardware to mount. (2 screws per bearing vs. 4)
- Stronger mount.  (A flat vertical spacer is less likely to break than the L-shaped bracket posted above.)




Scott
« Last Edit: August 27, 2019, 12:03:10 am by PL1 »

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #25 on: August 29, 2019, 10:32:21 pm »
Printed mount brackets for the pillow bearings.

Designed and test printed inner and outer 608 bearing holders.
- Very snug fit.  Both worked perfectly first try.   8)

They will be used in a lifting arm mechanism similar to the right 2/3rds of this Roberval Balance.
- The center vertical will be attached to the moving platform.  (left side of a parallelogram)
- The track bearing will be attached to the center of the right vertical.  (right side of a parallelogram)
- As the track goes up and down, the right vertical rises and falls without tilting.




Scott

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #26 on: September 08, 2019, 10:23:37 pm »


I see the whacky inflatable flailing arm guy for the big sale is coming along nicely!


In all seriousness just seeing that thing is really getting me excited!! I'm starting to really see this come together! Sorry for the delayed response, I've got about 3-4 weeks before I'm ready to start on my end...

2,370,650 Gun.Smoke

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #27 on: September 09, 2019, 04:54:13 am »
 :lol

That pic is just a bearing mount and parallelogram example from Thingiverse.

The actual parts look like this and are parametric so anyone can easily adjust them to suit their build.
- The ghost is optional, you can import any other .stl by changing the filename and translate/rotate values in that part of the code or change the platform variables as desired to support a non-printed item.
- I'll post the code after finishing the comments and making the design change mentioned below.

For best part strength, print Lift_Arm_Vert on its side definitely with supports and maybe with a raft, left edge down. (rotate 90 degrees CCW along the Y axis)
- Printed one as rendered and the bearing mounts are easy to break if you do something foolish like trying to remove a bearing using a screwdriver for leverage.   :embarassed:



Print Moving_Platform on its side with supports to avoid having to clean supports from the leadscrew holes.

I need to change the back of the vertical bearing arm on the moving platform -- the tapered back makes the part lighter, but also makes it hard to install the horizontal lift arms and bearings.   :banghead:   :lol



Here you can clearly see the two track bearings.
- The left one rolls in the 24mm vertical gap shown on the test frame diagram.
- The right one rolls on the ramp that controls the rise and fall of the lift arm.



Looks like this setup will provide up to 3-1/2" of lift with the default settings.





Still need to design microswitch holders, code some printable installation/removal tools for the bearings, select some components, and build the test frame, but things are coming along nicely.   ;D


Scott
EDIT: Do those last two pictures remind anyone else of a Miniature Schnauzer?   :duckhunt
« Last Edit: September 09, 2019, 05:13:27 am by PL1 »

jennifer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2216
  • Last login:Yesterday at 09:05:35 pm
Re: Stepper motor mechanism for animated cab topper
« Reply #28 on: September 10, 2019, 07:23:03 pm »
Now that IS cool, Good job!... :applaud:

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #29 on: September 10, 2019, 08:57:25 pm »
Now that IS cool, Good job!... :applaud:
Thanks, Jennifer.   :cheers:

Squared off the back of the vertical bearing arm on the moving platform.
- It's now much easier to install the arms and bearings.

Made a version of the vertical lift arm with the ramp bearing, platform, and ghost on the left instead of the right.

The fully commented OpenSCAD code for these parts is almost ready.   ;D


Scott

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #30 on: September 11, 2019, 09:04:26 pm »
Now that IS cool, Good job!... :applaud:
Thanks, Jennifer.   :cheers:

Squared off the back of the vertical bearing arm on the moving platform.
- It's now much easier to install the arms and bearings.

Made a version of the vertical lift arm with the ramp bearing, platform, and ghost on the left instead of the right.

The fully commented OpenSCAD code for these parts is almost ready.   ;D


Scott

I really can't express how incredibly grateful I am that Scott (PL1) :applaud: is helping me take on this element. I couldn't of partnered with anyone better to bring an idea which became bigger and better with suggestion, brainstorming, research & development etc. I'm truly super excited to see the purpose of what was envisioned which evolved & this finalized... What Scott has revealed in regards to what you see the Pac-Man Ghost is just simply a place holder. It gives a good representation of what it's mechanically going to do. Until it's completion on both Scott's & my end majority of it's still being kept a secret. Once I complete the rest of the build on my end I'll be doing a reveal of the purpose of this along side the completed game. As I had discussed with Scott likely +/- 4-6 weeks or so middle to the end of October is when I plan to tackle the project. The good news is that once I have time to start, majority of the elements are already done, however I've got many other things on my plate so It will need to wait until that time frame. I don't have a deadline nor does Scott, It won't be revealed until completed so he's got all the time he needs on his end as we had discussed in the beginning on this project should it line up to when I'm ready on my end great! 
2,370,650 Gun.Smoke

bperkins01

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 351
  • Last login:Today at 10:49:10 am
  • Plenty of skills.. gaining experience..
Re: Stepper motor mechanism for animated cab topper
« Reply #31 on: September 11, 2019, 09:35:55 pm »
I think I'm late to this thread- but this guy (I watch a lot of his videos) just did one on steppers and Hall Effect sensors as limit switches.
What's nice about them is they are triggered my magnetism (no contacts or leds). 

They are pretty cool and he covers what you are trying to do.

See here:
My Arcade Build and other projects here:
https://bperkins.wordpress.com/

mrclean

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1503
  • Last login:Yesterday at 10:42:04 am
  • World Record Holder for Gun Smoke Dedicated & MAME
    • Guscade
Re: Stepper motor mechanism for animated cab topper
« Reply #32 on: September 11, 2019, 10:09:41 pm »
I think I'm late to this thread- but this guy (I watch a lot of his videos) just did one on steppers and Hall Effect sensors as limit switches.
What's nice about them is they are triggered my magnetism (no contacts or leds). 

They are pretty cool and he covers what you are trying to do.


That's neat, next project ! ..... anyways I already have some Hall Effects  ;D .... but those are inside my Escape From The Planet Of The Robot Monsters.

Side note I think I'm more impressed with that guys organization of his tools.
« Last Edit: September 11, 2019, 10:13:26 pm by mrclean »
2,370,650 Gun.Smoke

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 7393
  • Last login:Today at 11:24:28 am
  • Designated spam hunter
Re: Stepper motor mechanism for animated cab topper
« Reply #33 on: September 12, 2019, 07:53:46 am »
this guy (I watch a lot of his videos) just did one on steppers and Hall Effect sensors as limit switches.
That's one of the better videos on the subject.   :cheers:

He uses a more advanced programming approach with interrupts that probably is better, but it is harder to convert for physical switches than the code from the other video.  :dunno

I'm trying to keep the hardware requirements as simple, inexpensive, and flexible as possible for anyone else who wants to build something like this, so it's best to be able to handle either type of switch.

apparently there is a way to drive stepper motors to make them nearly silent. it has to do with ramping up the current at the beginning of the step (or some voodoo like that) it's something being implemented in 3d printers to cut down on the noise.
Interesting.

Driver boards like the A4988 can work with inline motor filter boards like these or piggy-back on filter boards like these or there are some driver boards like the TMC2208 and TMC2100 designed for silent motor operation.

Adding a filter board or a silent driver board is more expensive than using A4988 drivers, but the noise reduction may be worth the extra cost.   :cheers:




Scott