Error with Navio2 Servo.py Example

Can anyone help with resolving these errors which I initially got while trying to run

python Servo.py

?:

Traceback (most recent call last):
File “my_servo.py”, line 20, in
pwm.set_period(50)
File “Navio2/Python/navio/pwm.py”, line 53, in set_period
with open(self.channel_path + “period”, “w”) as pwm_period:
IOError: [Errno 13] Permission denied: ‘/sys/class/pwm/pwmchip0/pwm0/period’

Following the foregoing error, I ran

emlidtool test

then I followed the prompt and updated RCIO by running

sudo emlidtool rcio update

However, I received yet another error:

Traceback (most recent call last):
File “my_servo.py”, line 19, in
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
File “Navio2/Python/navio/pwm.py”, line 15, in enter
self.initialize()
File “Navio2/Python/navio/pwm.py”, line 34, in initialize
pwm_export.write(str(self.channel))
IOError: [Errno 5] Input/output error

I also noticed that when I now run:

python RCInput.py

the following is displayed as the PPM channel output

0 0 0 0

as opposed to the typical receiver values such as:

1500, 1100, 1500, 1500

which correspond to values on Channels 1, 2, 3, 4 on the radio transmitter. Once, again, I observed that this happened after I ran:

sudo emlidtool rcio update

Please can anyone help with this? I appreciate your help in advance.

P.S.: During the first initial setup, I followed the guidelines as found on the emlid docs and flashed the Raspberry Pi using the same Buster OS image provided on the Navio2 website page.

Hi @ayoesquire,

Have you edited the script in any way? The error looks similar to the one discussed in this thread:

1 Like

Thank you @olesia.riman for your response and for sharing the link.

This above mentioned code for

is actually a replica of

The only difference is the file name. Furthermore, the issue is yet to be resolved. Also, I cloned Navio2.git and ran

from within the git repo.

Do you see the same error if you log in as root?

Can you also revert the Navio2/Python repository to the initial state and test it again?

1 Like

@olesia.riman:
Yes, I had to re-flash the entire Raspbian Buster OS image and restart RPi/Navio2 from scratch.

I have also been able to get the

program in the Navio2/Python directory to work without the ‘permission denied’ errors using the command:

sudo python Servo.py

Hint for other potential new users like me: As is, the

code works when you run the command:

sudo python Servo.py

However, because it doesn’t display any value or content at runtime (except for a blinking cursor at the bottom left corner of the screen), the program’s status might go unnoticed or be mistaken as non-responsive.

Thus, it might be helpful to include some print statement in the while loop, e.g.:

while (True):
print(“online”)
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
[rest of the code goes here…]

That way, there is a visual cue to tell if the programming is working or not.

@olesia.riman Update: I still have other issues. The motor of the servo hardware itself is yet to move when I run the Servo.py code even though it is connected to the 2.54mm header Pin #1 of the Navio2 HAT.

Please do you have any suggestions? Here is the wiring configuration that I used:

I have also tried switching between the Orange and Brown wires, but the servo motor does not move yet.

Here is the full code as well:

import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

count = 0
PWM_OUTPUT = 1
#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):
angle = float(input())
result = 0.6 + (2.4 - 0.6) * ((angle - 0) / (180 - 0))
print(“Result = {}”.format(result))
print(“Count = {}”.format(count))
pwm.set_duty_cycle(result)
time.sleep(1)
count = count + 1

@All Please anyone with suggestions on why the servo connection/wiring might not be working?

Can you share some photos of your setup?


@olesia.riman Thank you for the gesture to help. I have attached the screenshot of the connection here.

Interestingly, the servo motor works when I use only RPi without the Navio2 hat. That is, using the GPIO (BCM) Pin board/configuration.

So, I wonder why the servo motor doesn’t turn when the Navio2 hat is installed.

Because Navio2 servo rail is not powered by RPi. You need to plug a 5V bec in the servo rail…

https://docs.emlid.com/navio2/hardware-setup/#powering-servo-rail

2 Likes

@mlebret Thank you very much for pointing that out. Please to be sure I understand, could you please share an image of how that setup would look like?

I tried to look for a picture on the Navio2 hardware setup web page that will illustrate this step so that I don’t misunderstand what was being said.
Or is the picture of the device in the he link that you referenced, that of an BEC or ESC?

Also, the servo I am using appears to work with 3.3V power supplies.

Looking forward to your response. Thanks once again.

It is an ESC with BEC. For your test you can use what you want, a 1S Lipo, a BEC…

3.3V is the lower voltage able to power the servo. 5V is the normal voltage, HV servo can work with a 2S Lipo.

1 Like

@mlebret @olesia.riman
Thank you very much, Servo.py now works! Although, as a temporal alternative to the BEC, I used another RPi to provide 5V power supply and connected a common ground to the RPi with the Navio2 Hat.

PWM_OUTPUT was set to zero (0) as indicated in the following code:

import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

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

I have also attached a photo of the hardware setup here: