Uncategorized

JX-PDI-6221MG Digital Motor notes

Asked 
Active 21 days ago
Viewed 435 times
0

My setup is simply the servo JX-PDI-6221MG being directly activated with raspberry pi’s PWM through GPIO library. The servo is brand new, I followed this tutorial and set duty cycle values between 0 and 100. The angles it makes have no pattern, it seems to go one way from 20 to 50 and them from 60 to 90 the other.

I decide to loop through all possible duty cycles (code is below) and I confirm that the variations aren’t smooth and it doesn’t look precise. After trying to set fix values again it suddenly starts to spin in multiple directions, even without I changing anything. Not even GPIO.cleanup() or killing python related processes made it stop.

Is my Raspberry Pi getting jitter and being very imprecise or was I a victim of falsification?

Code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
pwm=GPIO.PWM(11,330) #which is the same as shown in datasheet
pwm.start(0)

for i in range(0,100):
     pwm.ChangeDutyCycle(i)
     time.sleep(0.02)

for i in range(0,100):
     i = 100 - i
     pwm.ChangeDutyCycle(i)
     time.sleep(0.02)`
share  edit  follow  flag
  • Note that software PWM on your Pi is pretty terrible. There are a limited number of hardware PWM pins available (either 1 or 2, depending on your model), and there are some workarounds for better software PWM (e.g., RPIO.PWM). This isn’t posted as an answer because it sounds like maybe there is more going on then simply slightly unstable PWM. You may want to consider asking this on raspberrypi.stackexchange.com instead. – larsks Jun 7 ’18 at 2:56

2 Answers

0

AFAIK, only GPIO 18 can be used by GPIO library for hardware PWM. try changing tht GPIO.OUT to that.

Also try using pigpio library which allows ANY GPIO pin to do hardware timed PWM.

share  edit  follow  flag
  • RPi.GPIO actually does not support hardware PWM at all. And the hardware does not support PWM on all pins. Only two PWM channels can be active simultaneously, and they are limited to a select few pins. – Henrik May 23 at 11:15
0

Servos generally need precise timing, so on a non-realtime device like the Raspberry Pi that means you need to use the hardware PWM pins. RPi.GPIO only supports software emulated PWM, so you need to use another library, e.g. pigpio.

share  edit  follow  flag
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: