RPi.GPIO not working on Rpi 2 B

Hi dear Navio community!

I have a problem running a simple example program provided by this page. I need 4 additional digital outputs for my application that should work parallel with APM. 2 of those need to be PWM. I tried this example just to see if the basic stuff works. And it’s not working. Program runs as expected. No errors. But nothing happens on the actual digital pin. I also tried using GPIO pins 17, 18, 24, 25 (board pins 11, 12, 18, 22) as they are unused by the Navio+ and APM.

I’m using Raspberry pi 2 B with Navio + and APM works normally.

Is there anything different between the image Emlid provided and the usual raspbian image that could cause this problem?

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

p = GPIO.PWM(12, 50)  # channel=12 frequency=50Hz
p.start(0)
try:
    while 1:
        for dc in range(0, 101, 5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
        for dc in range(100, -1, -5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass
p.stop()
GPIO.cleanup()

Hi,

I have a similar problem. I need extra pwm and simple digital pins controllable from C++ or python application on raspberry while simultaneously running ArduPlane. Is there a way to use your Navio/C++/Navio/gpio.h while APM is running? Or any other advice on how to control these extra pins are more than welcome!

Thank you!

@epicfoox

Hello there!

I can confirm that this code snippet doesn’t work as expected. It has to do with the RPi.GPIO package rather than with the image OS itself. The library used to be a little bit unstable at the time of creating of the image. It’ll be fixed in the next release.

For now you need to uninstall the older version:

sudo apt-get remove python-rpi.gpio

And then install the newer one like this:

cd raspberry-gpio-python-code
sudo python setup.py install```

After these steps the code will work. 

<img src="/uploads/default/original/1X/aecceb779760640fe9635a33377fde77f7b95358.png" width="690" height="85"> 

May I ask how exactly are you intending to use these pins? There might be a conflict with the APM I'm very frightened of. If I remember correctly, this library allows software PWM as well as DMA-driven PWM. The former can easily burn all the CPU (it's also very inaccurate (~100us errors) and prone to jitter due to context switches) and latter might conflict with PPM handling which also uses DMA extensively. So... you should be very careful!

@GreenSCV

Hi!

I’m pretty sure the C++ code will work, because it access the raw memory. But I strongly encourage you to use APM userhooks and droneapi. This is way cleaner. We have a lot of spare PWM outputs in APM. The software PWM is prone to jitter, that’s why you won’t actually be able to control a servo reliably.

Take a look at this thread. It might shine a light on the issue at hand.

1 Like

Both of these answers are very helpfull! Thank you. I’ll post here if I make it work.

I need PWM to control the angle of a few motors for VTOL. And i can’t use RC directly because it has to be fully automated - done from raspberry pi 2 with ROS.

Hello,

I replaced RPi.GPIO with gpiozero, it works!