Regarding stepper motor wih raspberry pi to press a button

Thread Starter

Raj Waghmare

Joined May 8, 2019
32
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:
from time import sleep
import RPi.GPIO as GPIO

DIR = 2   # Direction GPIO Pin
STEP = 3  # Step GPIO Pin
CW = 1     # Clockwise Rotation
CCW = 0    # Counterclockwise Rotation
SPR = 5   # Steps per Revolution (360 / 1.8)

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(DIR, GPIO.OUT)
GPIO.setup(STEP, GPIO.OUT)
GPIO.output(DIR, CW)

MODE = (14, 15, 18)   # Microstep Resolution GPIO Pins
GPIO.setup(MODE, GPIO.OUT)
RESOLUTION = {'Full': (0, 0, 0),
              'Half': (1, 0, 0),
              '1/4': (0, 1, 0),
              '1/8': (1, 1, 0),
              '1/16': (0, 0, 1),
              '1/32': (1, 0, 1)}

GPIO.output(MODE, RESOLUTION['Full'])
step_count = SPR
delay = 0.005

for x in range(step_count):
    GPIO.output(DIR, CW)
    GPIO.output(STEP, GPIO.HIGH)
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    sleep(delay)
sleep(1)

GPIO.output(DIR, CCW)
for x in range(step_count):
    GPIO.output(STEP, GPIO.HIGH)
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    sleep(delay)

GPIO.cleanup()
 

Attachments

DNA Robotics

Joined Jun 13, 2014
647
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.
 

Thread Starter

Raj Waghmare

Joined May 8, 2019
32
i did everything but its not working efficiently rather giving sequences of pressing once in a while with same configuration
 

djsfantasi

Joined Apr 11, 2010
9,156
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?
 

Thread Starter

Raj Waghmare

Joined May 8, 2019
32
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?
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
 

dendad

Joined Feb 20, 2016
4,451
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.
 

DNA Robotics

Joined Jun 13, 2014
647
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.
 

djsfantasi

Joined Apr 11, 2010
9,156
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.
 

Thread Starter

Raj Waghmare

Joined May 8, 2019
32
Hello,

I am getting a problem of jittering in servo while running my code which is affecting the position of a servo by millimetres and thus not pressing the button. Please guide me on how to fix it. Here's is my code

Code:
from gpiozero import Servo
from time import sleep

myGPIO=16

myServo = Servo(myGPIO)

print("Using GPIO16")
print("Using GPIO defaults for the servo class")

while True:
    myServo.mid()
    print("Set to middle position")
    sleep(1)
    myServo.min()
    print("Set to minimum position")
    sleep(1)


GPIO.cleanup()
 
Top