rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Button presser with motor

Thu Jul 04, 2019 1:25 pm

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: Select all

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()
Image

pcmanbob
Posts: 6403
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Button presser with motor

Thu Jul 04, 2019 1:55 pm

May be you delay of 0.005 between step commands is to short ?

try experimenting with longer delays.

it might also be worth adding so print statements so you can watch the program operation .

Code: Select all

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.05

print("start first loop")
for x in range(step_count):
    GPIO.output(DIR, CW)
    GPIO.output(STEP, GPIO.HIGH)
    print("high")
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    print("low")
    sleep(delay)
print ("end first loop")    
sleep(1)

print("start second loop")
GPIO.output(DIR, CCW)
for x in range(step_count):
    GPIO.output(STEP, GPIO.HIGH)
    print("high")
    sleep(delay)
    GPIO.output(STEP, GPIO.LOW)
    print("low")
    sleep(delay)

print ("end second loop") 

GPIO.cleanup()
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Fri Jul 05, 2019 8:25 am

I checked with configuring the delay but it didnot work. Its skipping a step sometimes. Pressing a button in random manner at same steps.

pcmanbob
Posts: 6403
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Button presser with motor

Fri Jul 05, 2019 10:34 am

If you take the motor out of your project to allow it to be run continuously and you run it for say 200 pulses does it run smoothly ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Fri Jul 05, 2019 11:30 am

It depends on the mode in which i am using my motor. In microstepping eg. 1/32 it does run smoothly and in full stepping it kinda vibrates. But the problem is in microstepping that it doeesnt provide enough force to press the button while in full stepping it does.

pcmanbob
Posts: 6403
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Button presser with motor

Fri Jul 05, 2019 1:18 pm

Have you got a power supply that can provide the correct voltage and current for your motor and have you set the driver board up correctly to provide the correct current.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Fri Jul 05, 2019 2:16 pm

pcmanbob wrote:
Fri Jul 05, 2019 1:18 pm
Have you got a power supply that can provide the correct voltage and current for your motor and have you set the driver board up correctly to provide the correct current.
My motor has a current 1.5A so I adjusted my pololu driver motor to 0.509V when i am connecting to supple of 12V its giving current value as 0.19A. Please check the ratings of the motor if i need to change something. This driver i used.
https://eckstein-shop.de/Pololu-DRV882 ... LpKfD_BwE

i am using my motor in full step ie 1/1

pcmanbob
Posts: 6403
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Button presser with motor

Fri Jul 05, 2019 3:08 pm

So Your motor requires 1.5A but you have set the controller to only supply 0.19A !

and from the linked page " The DRV8824 can only deliver up to 0.75 A per coil without a heat sink (1.2 A max with proper cooling), "

So your controller may not even be able to supply 1.5A to the motor no matter how you configure it.

I suggest you change the configuration to supply 0.75A for a start and see if that helps, if not you may need a controller that can supply the required 1.5A
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Tue Jul 16, 2019 8:36 am

As the stepper motor wasn't looking efficient to me so i ordered a servo. But i have a doubt where we can calibrate the position of it and rotate it to certain angles. Any help would be much appreciated in this topic.

https://www.graupner.de/Servo-digital-D ... 0-mm/7945/

User avatar
B.Goode
Posts: 8034
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Button presser with motor

Tue Jul 16, 2019 8:49 am

rajbuddy007 wrote:
Tue Jul 16, 2019 8:36 am
As the stepper motor wasn't looking efficient to me so i ordered a servo. But i have a doubt where we can calibrate the position of it and rotate it to certain angles. Any help would be much appreciated in this topic.

https://www.graupner.de/Servo-digital-D ... 0-mm/7945/


gpiozero

See Simple Recipe 2.20 https://gpiozero.readthedocs.io/en/stab ... ervo#servo

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Thu Jul 18, 2019 8:05 am

B.Goode wrote:
Tue Jul 16, 2019 8:49 am
rajbuddy007 wrote:
Tue Jul 16, 2019 8:36 am
As the stepper motor wasn't looking efficient to me so i ordered a servo. But i have a doubt where we can calibrate the position of it and rotate it to certain angles. Any help would be much appreciated in this topic.

https://www.graupner.de/Servo-digital-D ... 0-mm/7945/


gpiozero

See Simple Recipe 2.20 https://gpiozero.readthedocs.io/en/stab ... ervo#servo


Thanks for the link. Is there any code where we rotate the servo to certain angle? I want to rotate my servo to 55 degree. Could you please provide any leads for it?

pcmanbob
Posts: 6403
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Button presser with motor

Thu Jul 18, 2019 8:13 am

Try this

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
p = GPIO.PWM(17, 50)

angle = 55
duty = float(angle) / 18 + 2
print (duty)
p.start(duty)
    
time.sleep(5)

GPIO.cleanup()
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Thu Jul 18, 2019 8:28 am

No it didnot work :(

User avatar
B.Goode
Posts: 8034
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Button presser with motor

Thu Jul 18, 2019 8:46 am

rajbuddy007 wrote:
Thu Jul 18, 2019 8:05 am
B.Goode wrote:
Tue Jul 16, 2019 8:49 am
rajbuddy007 wrote:
Tue Jul 16, 2019 8:36 am
As the stepper motor wasn't looking efficient to me so i ordered a servo. But i have a doubt where we can calibrate the position of it and rotate it to certain angles. Any help would be much appreciated in this topic.

https://www.graupner.de/Servo-digital-D ... 0-mm/7945/


gpiozero

See Simple Recipe 2.20 https://gpiozero.readthedocs.io/en/stab ... ervo#servo


Thanks for the link. Is there any code where we rotate the servo to certain angle? I want to rotate my servo to 55 degree. Could you please provide any leads for it?


The final example in the section of the gpiozero documentation already referenced:
Use AngularServo so you can specify an angle:

Code: Select all

from gpiozero import AngularServo
from time import sleep

servo = AngularServo(17, min_angle=-90, max_angle=90)

while True:
    servo.angle = -90
    sleep(2)
    servo.angle = -45
    sleep(2)
    servo.angle = 0
    sleep(2)
    servo.angle = 45
    sleep(2)
    servo.angle = 90
    sleep(2)


rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Thu Jul 18, 2019 9:11 am

I checked with the angular servo code but its not providing enough force to press the 1.6N button

User avatar
B.Goode
Posts: 8034
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Button presser with motor

Thu Jul 18, 2019 9:19 am

rajbuddy007 wrote:
Thu Jul 18, 2019 9:11 am
I checked with the angular servo code but its not providing enough force to press the 1.6N button


So it seems this is a problem with your choice of servo, not something that can be resolved by code running on an RPi board.

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: Button presser with motor

Wed Jul 24, 2019 8:52 am

Hello Guys,

When I am running my code on the servo it starts with jitter and then goes further which affects a slight change in position. How can I improve my code to avoid jittering or any other solution would be appreciated? HERE's My Code

Code: Select all

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()

Return to “General discussion”