Power & Source of Big Ideas

Help with RPi.GPIO_NP on Neo2 in python 3 project

Moderators: chensy, FATechsupport

Hello.

I am trying to manipulate a GPIO pin to reset a radio that communicates serially on the NanoPi Neo2's UART1. I am using the Ubuntu Core image from 6/30/2017, which according to the Wiki has RPi.GPIO_NP already installed, so the installation directions simply say you don't have to install it since it is already installed.

Well, this is a bit of an issue for me, because I have written my whole project in python 3, and after experiencing a radio lockup which requires resetting the radio to recover, I decided I needed a wire to the radio reset which I will pulse whenever a certain amount of time passes since the radio last communicated with the Neo2. After running:

find /usr | grep -i gpio

I'm able to see that the RPi.GPIO is installed in the python 2.7 directory. I would like to install it for python 3, but can't find where I can obtain it to install it. If I try to install regular RPi.GPIO (for a real RasPi) I get "This module can only be run on a Raspberry Pi!". If I try to force my project to run with python 2, it finds the correct module and doesn't throw this error, and gets well past it before failing due to python3/2 incompatibilities.

This was my first ever python program, I'd rather not have to rewrite it for python 2 if there is a way to get RPi.GPIO for the Neo2 installed for python 3.

Any help would be greatly appreciated.
You have to rebuild the RPi.GPIO_NP for python3, honestly I would rewrite the program for python2 instead.

Anyway, I asked the source code of this library to friendlyarm support email for RPi.GPIO_NP and I did not received reply. I rewrote my own version here https://github.com/auto3000/RPi.GPIO_NP consequently this is not exactly equivalent to the preinstalled version on Ubuntu.
Thanks. I just grabbed your github repo, ran

Code: Select all

sudo python3 setup.py install
like normal, checked the install with

Code: Select all

find /usr | grep -i gpio
which gave the following output:

Code: Select all

(myVenv) pi@NanoPi-NEO2:~/pyGateway/pyEnvs$ find /usr | grep -i gpio
/usr/bin/gpio_test.sh
/usr/local/bin/gpio
/usr/local/lib/python2.7/dist-packages/RPi/GPIO.so
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.8.egg-info
/usr/local/lib/python3.5/dist-packages/RPi/GPIO.cpython-35m-aarch64-linux-gnu.so
/usr/local/lib/python3.5/dist-packages/RPi/GPIO
/usr/local/lib/python3.5/dist-packages/RPi/GPIO/__init__.py
/usr/local/lib/python3.5/dist-packages/RPi/GPIO/__pycache__
/usr/local/lib/python3.5/dist-packages/RPi/GPIO/__pycache__/__init__.cpython-35.pyc
/usr/local/lib/python3.5/dist-packages/RPi/_GPIO.cpython-35m-aarch64-linux-gnu.so
/usr/local/lib/python3.5/dist-packages/RPi.GPIO-0.5.11.egg-info
/usr/local/lib/python3.5/dist-packages/RPi.GPIO-0.6.3.egg-info
/usr/local/share/man/man1/gpio.1


It appeared to me as if it installed correctly. However, upon running my python code, with the first line being

Code: Select all

import RPi.GPIO as GPIO

I get

Code: Select all

ImportError: No module named 'RPi'


Any thoughts on what I'm missing here?
Seems it wasn't finding it while in my virtual environment. Using

Code: Select all

python3 myCode.py
after deactivating the virtual environment, I'm able to run my project, at least until the point of failure from a bug in a new, unrelated feature I've implemented but haven't debugged yet.

If you know how to make it work from my virtual environment, I'd be very appreciative. If not, thanks for getting me this far already :D
Thanks for your feedback, good to see you already fixed most problems.

If you know how to make it work from my virtual environment, I'd be very appreciative. If not, thanks for getting me this far already :D

I can't really help, may stackoverflow help you or another user there. Anyway I got this behavior in the past while installing a python library (with pip3 I think) and fixed the issue by deleting my virtual environment and regenerate the whole.
Try running

Code: Select all

sudo python3 setup.py install

while you're in your virtual environment in the first place

Who is online

In total there are 15 users online :: 0 registered, 0 hidden and 15 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 15 guests