Hi, I tried to use Servo.py example to run sg90 servo, but the servo didn’t rotate but the code did run smoothly. The picture below is my connetion.
I connected the servo to pin 6.
Require urgent help. Thank you in advance
Try question with ChatGpt, i’m resolved any problem
Hi @wintho.21,
Welcome to the forum!
Did you power up the servo rail? When you connect servos, there is no power on the servo rail. To power it, please connect the 5V and GND as shown in the picture:
Hi, @olesia.riman is it really nessary to use a servo rail? As I came across some saying that mini servo like sg90 don’t require servo rail.
Also can D24V50F5 (Pololu 5V, 5A Step-Down Voltage Regulator) be use as servo rail (if needed).Thank you.
The power module doesn’t provide a supply to the servos. You can check out more information about powering servos in the documentation.
You need to use BECs that provide voltage in a range of 4.8-5.3 V. We haven’t tested this D24V50F5 regulator, but looks like it would work.
Tried connecting D24V50F5 regulator, but the servo still didn’t rotate. Can please help check whether is it connection error.
I also faced permission error when i try to run it:
pi@navio:~/Navio2/Python $ sudo python try.py
Traceback (most recent call last):
File “try.py”, line 9, in
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
File “/home/pi/Navio2/Python/navio/pwm.py”, line 15, in enter
self.initialize()
File “/home/pi/Navio2/Python/navio/pwm.py”, line 34, in initialize
pwm_export.write(str(self.channel))
IOError: [Errno 1] Operation not permitted
code:
import sys
import time
import navio.pwm
import navio.util
navio.util.check_apm()
PWM_OUTPUT = 6
SERVO_MIN = 1.250 #ms
SERVO_MAX = 1.750 #ms
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
pwm.set_period(50)
pwm.enable()
while (True):
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
pwm.set_duty_cycle(SERVO_MAX)
time.sleep(1)
realised my own error (wrong pwm pin). Problem solved, thank you.
Glad to hear everything is working!