1

I'm trying to control a futaba s3003 servo motor using raspberry pi 3 but when I run the code the servo just moves a bit then stops. The servo's power is connected to external 6v power supply and I also connected the power supply ground to pi ground and the servo ground to pi ground too.

servo.py

import RPi.GPIO as gp
gp.setmode(gp.BOARD)
gp.setup(7,gp.OUT)
p = gp.PWM(7,50)
p.start(5)
p.ChangeDutyCycle(11)#tried 2,7.5,11,12 

So every time I change the duty cycle and run it, it just moves a bit then will stop and keeps going like that. I want to go from 0 to 180. What am I doing wrong?

migrated from electronics.stackexchange.com Feb 25 '17 at 1:07

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • I didn't use raspberry pi yet but let me ask something, is it making the pwm signal with 20ms of total time? (ton+toff=20ms) – Marcelo Espinoza Vargas Feb 25 '17 at 0:45
  • I have no idea, I'm just following a tutorial and this is what the guy has. – maxcc Feb 25 '17 at 0:49
0

You need to understand how hobby servos work.

Perhaps google?

You send a pulse 50 times a second. The pulse is between 1 and 2 milliseconds in length. The length of the pulse specifies an angle. Once the servo reaches that angle the servo stops.

You shouldn't use software timed pulses to control a servo. The timing jitter is not beneficial.

I suggest you use servoblaster, or RPIO.GPIO, or my pigpio to control servos.

Note, RPIO.GPIO is not the same module as RPi.GPIO which you are currently using.

1

The data sheet of the servo shows that it uses a pulse cycle of 30ms, that means the frequency of your pwm must be 1/0.03=33.333, I didn't use raspberry pi but check if using this code:

p = gp.PWM(7,1/0.03)

If it compiles well it should give you a 30ms of total pulse cycle, if not try:

p = gp.PWM(7,33.333)

  • it compiles but nothing has changed. It just moves a bit and stops. – maxcc Feb 25 '17 at 1:09
0

You didn't post the data sheet, but it seems to be a 3 phase motor, so you have to somehow rotate the magnetic field inside it. It would require 3 PWM channels and sensors. Even in sensorless topology, you would need to measure voltage on motor phases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.