PeersC
Posts: 30
Joined: Fri Apr 01, 2016 6:35 pm

Rpi2 and 3 servo controi difference

Sun Feb 19, 2017 5:13 pm

Hi There,

I have a question regarding the raspberry pi 3 and 2 with pwm servo control.

My development board is a Pi3 with touch screen, Pi Cobbler and powered bread board.

My Robot is a pi 2, 2 x stepper motors, battery pack and a servo operated ultrasonic module.
I test everything on the development board and can control the servo perfectly - my code works
however when I use the same program on the robot (pi2), the servo rotates all way left and refuses to move to any other position - all GPIO ports and wiring are the same - if I ground both pi together move the signal pin then it ' ll run on the PI3

Anyone got any ideas???

Peers

User avatar
joan
Posts: 14469
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Rpi2 and 3 servo controi difference

Sun Feb 19, 2017 5:43 pm

Power supply?

When you say pwm servo control how are you generating the PWM?

PeersC
Posts: 30
Joined: Fri Apr 01, 2016 6:35 pm

Re: Rpi2 and 3 servo controi difference

Sun Feb 19, 2017 6:51 pm

Here is the test code that I used from my PC I may have changed some details on the PI's

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
servoPin=19
GPIO.setup(servoPin, GPIO.OUT)
pwm=GPIO.PWM(servoPin,50)
pwm.start(10)
for i in range(0,3):
desiredPosition=i * 80
DC=(desiredPosition) / 14 + 2.5
pwm.ChangeDutyCycle(DC)
time.sleep(5)
pwm.stop()
GPIO.cleanup()



yeah just checked the pin out on the pi - it's 13 not 19

any ideas?

Peers

PeersC
Posts: 30
Joined: Fri Apr 01, 2016 6:35 pm

Re: Rpi2 and 3 servo controi difference

Sun Feb 19, 2017 6:56 pm

Sorry - just noticed it didn't copy the indents in the loop just cut and pasted DOH!!
it's supposed to cycle through left center and right.

Peers

User avatar
joan
Posts: 14469
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Rpi2 and 3 servo controi difference

Mon Feb 20, 2017 11:16 am

You may edit the post and enclose the script in code quotes (highlight the text and press the Code button in the toolbar of the edit window).

I don't see any reason for the code to cause the servo to move as you describe.

However you would be better of sending hardware timed pulses to a servo, software timed pulses can introduce jitter. Have a look at (my) pigpio, or servoblaster, or RPIO.GPIO which can all generate hardware timed pulses.

User avatar
joan
Posts: 14469
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Rpi2 and 3 servo controi difference

Mon Feb 20, 2017 12:34 pm

supra wrote:You're missing one

Code: Select all

GPIO.output(servoPin, True)
I think that will just set the servo pin high, which will rather defeat the point of using PWM to pulse the pin.

Return to “Automation, sensing and robotics”