How to fix SG90 servo motor jitter on BeagleBone Black with PWM?

Hey guys, am developing a robotic arm control system using a BeagleBone Black running Embedded Linux using AM335x ARM Cortex-A8. The system needs to control the position of a servo motor(SG90) using PWM. I have ensured that the Adafruit_BBIO library is correctly installed and imported in my script, adjusted the duty cycle range if the servo motor does not reach the full range of motion (0-180 degrees). But am getting the error  warning: SG90 Servo motor jitter detected    
   import Adafruit_BBIO.PWM as PWM

   import time


   # Define PWM pin and servo parameters

   PWM_PIN = "P9_14"

   PWM_FREQUENCY = 50  # Servo motors typically use a 50Hz frequency


   # Initialize PWM

   PWM.start(PWM_PIN, 7.5, PWM_FREQUENCY# Start with 7.5% duty cycle (neutral position)


   def set_servo_angle(angle):

       # Convert angle to duty cycle

       duty_cycle = (0.05 * angle) / 18 + 2.5

       PWM.set_duty_cycle(PWM_PIN, duty_cycle)


   try:

       while True:

           for angle in range(0, 181, 10):  # Sweep from 0 to 180 degrees

               set_servo_angle(angle)

               print(f"Servo Angle: {angle} degrees")

               time.sleep(0.5)


           for angle in range(180, -1, -10):  # Sweep back from 180 to 0 degrees

               set_servo_angle(angle)

               print(f"Servo Angle: {angle} degrees")

               time.sleep(0.5)


   except KeyboardInterrupt:

       print("\nExiting...")


   finally:

       PWM.stop(PWM_PIN)

       PWM.cleanup()

   
   import Adafruit_BBIO.PWM as PWM

   import time


   # Define PWM pin and servo parameters

   PWM_PIN = "P9_14"

   PWM_FREQUENCY = 50  # Servo motors typically use a 50Hz frequency


   # Initialize PWM

   PWM.start(PWM_PIN, 7.5, PWM_FREQUENCY# Start with 7.5% duty cycle (neutral position)


   def set_servo_angle(angle):

       # Convert angle to duty cycle

       duty_cycle = (0.05 * angle) / 18 + 2.5

       PWM.set_duty_cycle(PWM_PIN, duty_cycle)


   try:

       while True:

           for angle in range(0, 181, 10):  # Sweep from 0 to 180 degrees

               set_servo_angle(angle)

               print(f"Servo Angle: {angle} degrees")

               time.sleep(0.5)


           for angle in range(180, -1, -10):  # Sweep back from 180 to 0 degrees

               set_servo_angle(angle)

               print(f"Servo Angle: {angle} degrees")

               time.sleep(0.5)


   except KeyboardInterrupt:

       print("\nExiting...")


   finally:

       PWM.stop(PWM_PIN)

       PWM.cleanup()

   
13 Replies
Boss lady
Boss lady3mo ago
attachment 0
ZacckOsiemo
ZacckOsiemo3mo ago
Really wanna dig into this albeit I don't have elinux exp
ZacckOsiemo
ZacckOsiemo3mo ago
I am also tuning the same motor
Boss lady
Boss lady3mo ago
@ZacckOsiemo This are the materials I studied along with BeagleBone Black documentation for this project https://www.electronics-tutorials.ws/blog/servo-motor.html https://www.learnrobotics.org/blog/pwm-basics/ https://www.packtpub.com/product/advanced-robotics-projects-with-beaglebone-black/9781788627907 You can learn bash scripting on YouTube from https://youtube.com/playlist?list=PLT98CRl2KxKGj-VKtApD8-zCqSaN2mD4w&si=n9CW8seThx86aGQm To get an extensive level of Linux experience
YouTube
Bash Scripting on Linux
The Bash Scripting Essentials series will teach you everything you need to know in order to write effective bash scripts in Linux. The series starts with som...
ZacckOsiemo
ZacckOsiemo3mo ago
I am doing it on stm32 not on embedded linux
Boss lady
Boss lady3mo ago
Ooh okay, I also came across these materials during my research but didn't bother to go through them, they might be helpful to you https://controllerstech.com/stm32-pwm-tutorial/ https://stm32-base.org/guides/servo-control https://www.st.com/content/st_com/en/applications/industrial/motor-control-and-drives.html
ZacckOsiemo
ZacckOsiemo3mo ago
Oh lovely thank you, yes currently paused because I haven't wired up my power supply 😦
ZacckOsiemo
ZacckOsiemo3mo ago
I should add I am not stuck with the same issue you are with, jitter could be caused by imprecise pwm
Boss lady
Boss lady3mo ago
What do you suggest I do to fix this
ZacckOsiemo
ZacckOsiemo3mo ago
Hey @Boss lady might be a bad motor do you have another sample to test? There is a few things either your timing is off or your motor is bad
ZacckOsiemo
ZacckOsiemo3mo ago
Lets explore a bit are you using an external power supply?
Boss lady
Boss lady3mo ago
Yes, A 4xAA alkaline battery
Nayel
Nayel3mo ago
If I remember correctly the beegleone Black as a very poor software Sometimes the PWM does not work at all
Want results from more Discord servers?
Add your server