SG92R Micro Servo control with Adafruit 16-Channel 12-bit PW

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

SG92R Micro Servo control with Adafruit 16-Channel 12-bit PW

Post by MCG »

Dear Admin,

I'm trying to figure out how to control the micro servo, i'm using the example python code:

Code: Select all

def setServoPulse(channel, pulse):
  pulseLength = 1000000                   # 1,000,000 us per second
  pulseLength /= 60                       # 60 Hz
  print "%d us per period" % pulseLength
  pulseLength /= 4096                     # 12 bits of resolution
  print "%d us per bit" % pulseLength
  pulse /= pulseLength
  pwm.setPWM(channel, 0, pulse)

pwm.setPWMFreq(60)                        # Set frequency to 60 Hz
setServoPulse(0, 1000)
time.sleep(2)
setServoPulse(0, 1500)
time.sleep(2)
setServoPulse(0, 2000)
I modified the code a bit, removed "pulse *= 1000", and i call setServoPulse 3 times with 1000, 1500, 2000 us parameters.
So if i'm right 1000 should be the -90, 1500 is the 0 position and 2000 is the 90 degree.
The problem is that, it doesn't seems to work like that, and also sometimes it rotate weird.

Thanks,
Gabor

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by adafruit_support_bill »

Please describe exactly how the servo responds to that code.

User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by MCG »

I try to describe what happens but anyway i uploaded a video when i set 1000 us first and 1500 and then 2000.
https://www.youtube.com/watch?v=PiFU_eq ... e=youtu.be
There is some delay between them. So as you can see it's less than 180 degree of rotation.
Other problem is sometimes the servo seems noisy, the second video shows what i mean exactly.
http://youtu.be/A8gRl0TcP3g

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by adafruit_support_bill »

There is no delay after the move to 2000, so it does not have time to move to that position before you send the next command.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by Franklin97355 »

Have you tried values less than 1000 and greater than 2000? Servos are not precise devices and vary much in their behavior.

User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by MCG »

Okay, i played with it and the max angle is much better, but i still don't understand that "flickering" it can't be the lack of sleep because when i recorded the videos i added it.So the second youtube link showed at the beginning and at the and that weird behavior.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by adafruit_support_bill »

It also looks like you are resetting the PWM frequency each time. That should only be done once at startup.

User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by MCG »

Thanks for your replies.
Here is a little bit modified code:

Code: Select all

# Initialise the PWM device using the default address
pwm = PWM(0x40)
pwm.setPWMFreq(60)                        # Set frequency to 60 Hz
# Note if you'd like more debug output you can instead run:
#pwm = PWM(0x40, debug=True)

def setServoPulse(channel, pulse):
  pulseLength = 1000000                   # 1,000,000 us per second
  pulseLength /= 60                       # 60 Hz
  print "%d us per period" % pulseLength
  pulseLength /= 4096                     # 12 bits of resolution
  print "%d us per bit" % pulseLength
  #pulse *= 100
  pulse /= pulseLength
  pwm.setPWM(channel, 0, pulse)

# pulse = int(sys.argv[1])
while (True):
  setServoPulse(0, 500)
  time.sleep(5)
  setServoPulse(0, 2300)
  time.sleep(5)
Now i can change the angle between ~0-180, but that previous annoying behavior is still exists!
https://www.youtube.com/watch?v=lHl7wUB ... e=youtu.be
Almost good but at 15sec you can see the problem.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by adafruit_support_bill »

Post a photo showing your soldering and connections to the PWM board.

User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by MCG »

I attached a photo of my board.
Attachments
board.JPG
board.JPG (444.65 KiB) Viewed 625 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by adafruit_support_bill »

That's not one of our boards. Looks like one of the eBay clones.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by Franklin97355 »

Please contact the seller for support or a replacement/refund.

User avatar
MCG
 
Posts: 12
Joined: Sat May 09, 2015 7:32 am

Re: SG92R Micro Servo control with Adafruit 16-Channel 12-bi

Post by MCG »

Thanks, for your help!I will contact with them.

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”