Controlling Servo through Navio2 PWM Output

Hi,

I’m trying to control a Tower Pro SG92R servo through Navio’s PWM Output channel 14. Is this possible and how would I do it?

I have tried the example code from Emlid that is labeled Servo.py, but all it returns is an error message that says “APM is running. Can’t launch example.”

I’m really new to this so pardon me for any dumb mistakes! All help is appreciated!

Hi @fruutypebbles,

The message “APM is running. Can’t launch example.” means that you need to stop Ardupilot on your Navio2 before launching the test. You can do it via emlidtool or with the following command:

pi@navio: ~ $ sudo systemctl stop arducopter

Thanks a lot! It removed that error!

However, when I run Servo.py now, it shows this error:
OSError: [Errno 19] No such device

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “Servo.py”, line 14, 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))
OSError: [Errno 19] No such device

My Servo.py code is
import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

PWM_OUTPUT =14
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)

Never mind, I figured out, I should put PWM_OUTPUT=13 instead of 14. thanks.

2 Likes