Regarding stepper motor wih raspberry pi to press a button

Discussion in 'Embedded Systems and Microcontrollers' started by Raj Waghmare, Jul 5, 2019.

  1. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
    Hello guys,

    I want to press a button of a subject in different intervals. For that i made a test bench of a stepper motor to press a button. I have attached a picture as well. The button operating force is 1.6N where the motor torque is 420 mN.m. The button travel length is 2mm. When i am applying my code on it, it sometimes pressing the button but most of the time its skipping the step. I am running my motor on Full step. I did check upto 1/32 but it doesnt provide enough force as compare to Full stepping. Have a look at my code, Button link, Motor link, Picture. Any leads would be wonderful.

    Thanks and regards.


    Motor = https://www.amazon.de/MVPOWER-Schrittmo ... SP0BK2CKK3

    Button = https://www.mouser.de/datasheet/2/15/SKRT-1370725.pdf

    Code =

    Code (Text):
    1. from time import sleep
    2. import RPi.GPIO as GPIO
    3.  
    4. DIR = 2   # Direction GPIO Pin
    5. STEP = 3  # Step GPIO Pin
    6. CW = 1     # Clockwise Rotation
    7. CCW = 0    # Counterclockwise Rotation
    8. SPR = 5   # Steps per Revolution (360 / 1.8)
    9.  
    10. GPIO.setwarnings(False)
    11. GPIO.setmode(GPIO.BCM)
    12. GPIO.setup(DIR, GPIO.OUT)
    13. GPIO.setup(STEP, GPIO.OUT)
    14. GPIO.output(DIR, CW)
    15.  
    16. MODE = (14, 15, 18)   # Microstep Resolution GPIO Pins
    17. GPIO.setup(MODE, GPIO.OUT)
    18. RESOLUTION = {'Full': (0, 0, 0),
    19.               'Half': (1, 0, 0),
    20.               '1/4': (0, 1, 0),
    21.               '1/8': (1, 1, 0),
    22.               '1/16': (0, 0, 1),
    23.               '1/32': (1, 0, 1)}
    24.  
    25. GPIO.output(MODE, RESOLUTION['Full'])
    26. step_count = SPR
    27. delay = 0.005
    28.  
    29. for x in range(step_count):
    30.     GPIO.output(DIR, CW)
    31.     GPIO.output(STEP, GPIO.HIGH)
    32.     sleep(delay)
    33.     GPIO.output(STEP, GPIO.LOW)
    34.     sleep(delay)
    35. sleep(1)
    36.  
    37. GPIO.output(DIR, CCW)
    38. for x in range(step_count):
    39.     GPIO.output(STEP, GPIO.HIGH)
    40.     sleep(delay)
    41.     GPIO.output(STEP, GPIO.LOW)
    42.     sleep(delay)
    43.  
    44. GPIO.cleanup()
     
  2. DNA Robotics

    Active Member

    Jun 13, 2014
    465
    174
    If you send steps too fast, a stepper motor will just vibrate. I would try a lot longer delay. You can shorten it after you get it working.
     
  3. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
    i did everything but its not working efficiently rather giving sequences of pressing once in a while with same configuration
     
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,105
    1,942
    If you are having trouble with the force in half-step mode, you might just not have enough power.

    Have you tested the stepper standalone, without pressing a button? Is it still skipping steps?

    How long is the distance from the stepper motor axle to the center point of the face in the actuating lever? This data is needed to calculate the force required.

    One thought I have, have you considered a high-torque hobby RC servo instead of a stepper motor?
     
  5. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
    Hello,

    The operation distance requires for a button to be pressed is 2mm and i am keeping motor at a random small distance and trying to press the button with adjusting the SPR. The distance of lever from the center axis is 2.2cm. It does press the button sometimes but most of the time to fails to retain its initial position and stuck a step or two in between
     
  6. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,105
    1,942
    Ahhh, fails to retain its position. I’d definitely go with a servo.
     
  7. Sensacell

    Moderator

    Jun 19, 2012
    2,344
    752
    To press a button you might consider a simple solenoid?
     
  8. dendad

    Distinguished Member

    Feb 20, 2016
    2,755
    740
    Another vote for a servo. I've used a small servo to push a camera release button for time lapse photography. The servo worked well.
    A lot easier to use that a stepper too.
     
  9. CharlesWMcDonald

    Member

    May 16, 2019
    218
    70
    Instead of using a lever, you may want to use a cam.
     
  10. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
  11. DNA Robotics

    Active Member

    Jun 13, 2014
    465
    174
    I just noticed that the "tactile feeling" of that switch means the force to operate it is
    1.6 N = .4 lb. = 6.4 oz.
    That is a lot. Maybe try a different switch.
     
  12. dendad

    Distinguished Member

    Feb 20, 2016
    2,755
    740
    Last edited: Jul 16, 2019 at 9:00 AM
  13. MrChips

    Moderator

    Oct 2, 2009
    18,721
    5,946
    Why not bridge the switch contacts with a relay?
     
    DNA Robotics likes this.
  14. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
    I cant because i am testing on a company product so I cant make any soldering to it
     
  15. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,105
    1,942
    What language are you coding in on the raspberry Pi? Dendad provided a good source, but there are a lot of others available. Search for “raspberry pi servo”. There’s even a library available.
     
  16. MrChips

    Moderator

    Oct 2, 2009
    18,721
    5,946
    In that case, use a rotating mechanism with a cam or elliptical disc.
     
  17. Raj Waghmare

    Thread Starter New Member

    May 8, 2019
    19
    0
    I am coding in python. Lets see if I can find something crucial
     
  18. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,105
    1,942
    Great! Since your coding in python, the search criteria “raspberry pi servo” results in python coding examples, a python library for servos and several tutorials.
     
Loading...