rm-hull / opi.gpio Goto Github PK
View Code? Open in Web Editor NEWRPi.GPIO drop-in replacement library for Orange Pi Zero and other SBCs
Home Page: https://opi-gpio.readthedocs.io/
License: MIT License
RPi.GPIO drop-in replacement library for Orange Pi Zero and other SBCs
Home Page: https://opi-gpio.readthedocs.io/
License: MIT License
Hi, really an excellent job @rm-hull first of all!
Not sure if it is expected but when I configure a pin as output and forget to use GPIO.cleanup() at the end of my script, it is no more possible to change the value of the output. E.g. if I run:
import OPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
pin = 11
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
And then:
import OPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
pin = 11
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
I get the following error:
Traceback (most recent call last):
File "gpio.py", line 4, in <module>
GPIO.setup(pin, GPIO.OUT)
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 241, in setup
sysfs.export(pin)
File "/usr/local/lib/python2.7/dist-packages/OPi/sysfs.py", line 20, in export
fp.write(str(pin))
IOError: [Errno 16] Device or resource busy
I guess because GPIO.setup tries to export the pin again causing the error and preventing the program to continue running. Not using setup() or catching the error results in a Channel is not configured message.
Thanks
Hello,
the original RPi.GPIO is written in C because in python is not possible to have real multithreading
behaviour. When you decided to port the original library and switch to python only, has you
considered this issue?
https://realpython.com/python-gil
Please note that I'm just curious, I didn't find any mention to that into provided documentation. I've started to adjust the original RPi.GPIO to work with other boards when I discovered your project.
Thanks,
I'm trying to convert a project which is using pyA20 to OPi.GPIO to avoid running software as root.
I succeeded converting it but OPi.GPIO now is too slow at switching GPIO state.
I need fast switching GPIO to turn ON/OFF an infrared LED and communicate with an Air Conditioned unit.
Is there any way to speed up the switching of OPi.GPIO?
I have added my OPiGPIO files in my Android Studio project as a module. But, I cannot retrieve the library of the OPiGPIO. Can you help me with this?
I like the idea of adding SBC based mappings, but I would also like the BCM mappings. What I started with was adding dicts BOARD_DUO and BCM_DUO dicts. What do you think? Also, does it make sense to call the project OPi when it's really sysfs.GPIO? Let me know if you like the dicts idea and I'll do a PR for Duo. There's also the Duo Mini Shield, so I'm going to see if I need another set of dicts or if I can just use the Duo mappings.
writing byte-compilation script '/var/tmp/portage/dev-python/OPi-GPIO-0.5.0/temp/tmpdqhcd8x1.py'
/usr/bin/python3.8 /var/tmp/portage/dev-python/OPi-GPIO-0.5.0/temp/tmpdqhcd8x1.py
File "/usr/lib/python3.8/site-packages/orangepi/pi4B.py", line 21
import orangepi.4
^
SyntaxError: invalid syntax
now i wonder why it faults there ?
Does it support orange pi 3lts?
It would be great (if not too complex) to add support for the RPi.GPIO pull_up_down
argument of setup() since it is very common to have pull up/down set when reading an input.
I've tried the trick to output e.g. HIGH before reading but I correctly got an error saying the pin is supposed to be an input not an output.
Alternatively, I'd recommend adding the pull_up_down option anyway and just print out a warning saying it is not implemented so to ensure compatibility with existing code. A similar approach can be used for bouncetime and other optional parameters in this way the code will be fully compatible even if the functionality is not implemented.
Thanks
OPi.GPIO is a very good support for writing python applications to interact with GPIO on SBC based on H3/H5 etc. Currently, the latest OS distributions based on Debian 12 and higher using kernel 6.x do not have access to GPIO via /sysfs, only via libgpiod. Does OPi.GPIO support interaction with GPIO via libgpiod?
I found info https://linux-sunxi.org/GPIO
Accessing the GPIO pins through character device with mainline kernel
The sysfs GPIO interface is now deprecated in favor of character devices /dev/gpiochipX
I found a project called RPI.GPIO2
https://github.com/underground-software/RPi.GPIO2/tree/master?tab=readme-ov-file
which allows you to maintain the communication syntax with GPIO but by using libgpiod.
Maybe it would be possible to make OPi.GPIO2 versions in a similar way, so that we could still use our python scripts on 6.x series krenels and use the settings and communication with GPIO via libgpiod?
Hello,
The newest Orange Pi PC pin mapping is not in PyPi. Since I'm using the Orange Pi One, this means that my pin mapping does not match with the correct pin mapping.
Would it be possible to tag and release the newest pin mapping to PyPi so somebody else doesn't have the same issue, haha...
Hello,
please can explain how you calculate BCM pinout mapping? I'm searching for it on the web all the day but found nothing about the link of physical with BCM pins.
(i'm trying to add pin mapping for NanoPi Neo board)
Thanks
I have in issue trying to detect any gpio input changes from within an event detection callback.
My goal is to read an ir remote with the GPIO's, when an input is detected (a falling edge) I want to enter a function where i measure the number and duration of pulses of the remote for a fixed time. so far I can detect the initial pulse and enter the callback function however once inside the input seems to be fixed to high (1) and does not change. I know this is not correct as if i just print the inputs in the main loop then I can detect both 0's and 1's.
Any idea or guidance on this would be hugely appreciated!
import OPi.GPIO as GPIO
from time import sleep
from time import perf_counter
LED_gpio = 7 # pin name = PA6 wPi = 2 GPIO = 6
ir_gpio = 5 # pin name = SCL.0 wPi = 1 GPIO = 11
GPIO.setboard(GPIO.PCPCPLUS)
GPIO.setmode(GPIO.BOARD) # set up BOARD BCM SUNXI numbering
GPIO.setup(LED_gpio, GPIO.OUT) # set pin as an output (LED)
GPIO.setup(ir_gpio, GPIO.IN)
def inputChange(channel):
print("input interupt detected")
timeout = perf_counter()+3 #stay in this loop for 3 seconds
counter_1 = 0
counter_0 = 0
while perf_counter()<timeout:
if GPIO.input(ir_gpio)==1: # 1 if high 0 if low tells you input value
counter_1 = counter_1 +1
else:
counter_0 = counter_0 +1
print("callback ended")
print ("number of 1's detected = ", counter_1)
print ("number of 0's detected = ", counter_0)
GPIO.add_event_detect(ir_gpio, GPIO.FALLING, callback = inputChange, bouncetime = 3200) #bouncetime stops the callback from being run again for a set time in miliseconds. needs to be length of ir command
try:
GPIO.output(LED_gpio, 0)
print("running program press ctrl+c to stop")
while 1:
sleep(4) #comment out when measuring all values
#print("mainloop pin value = ", GPIO.input(ir_gpio)) #display all values
except KeyboardInterrupt:
print("")
print("program stopping")
GPIO.cleanup()
Just wondering if this library will work out of the box for a Rock 4. I see the directory for the Rock pi S and Zero..but not Rock 4.
I'd be happy to help in any way I can to implement. Have been looking at pin mappings!
Hey wonderful people,
Having issues getting gpio working from my pygame script..
as per title keep getting PermissionError: Permission Denied /sys/class/gpio/export
running as sudo doesnt fix the issue as im running a virtual environment due to "Environment maintened externally" error when trying to install pip packages as sudo.. (some packages are installable with the --break-system-packages line but that doesnt fix the issue here..)
any help would be greatly appreciated!
Please could you update version from 0.5.2 -> 0.5.3 version in pypi.org
Thanks.
I'm fairly new to this domain, so please bear with me with some "so obvious to you" questions. :-)
This is a drop-in replacement lib for RPi.GPIO. But how exactly should I port this new lib for OPi? Should I install RPi library first as normally would do, then install this new lib as described in doc $ sudo pip install --upgrade OPi.GPIO
? Thanks!
I've tried to update your Travis config for newer versions of python3 (my default is 3.7) to the Github/Travis defaults up to 3.10, and I seem to be getting some test failures relating to RuntimeError raising (or not raising) OSError. Tests are a little out of my python experience so far, so I wonder if you could shed some light on what's going wrong (you can peruse my fork, and the travis tests on travis-ci.com/mjeveritt hopefully).
I also unwittingly tried to port the Travis configuration over to github actions (you'll see this in other branches of my repo), and can't seem to fathom how best to set up tox and coveralls as you had done. I'm sure it's reasonably trivial if you know what you're doing!!
Thanks in advance!
I have an udev rule in place that allows me to use the GPIOs as a normal user
SUBSYSTEM=="gpio", ACTION=="add", RUN="/bin/sh -c '\
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
chown -R root:gpio /sys$DEVPATH && chmod -R 770 /sys$DEVPATH"
The problem is that, after writing to the /sys/class/gpio/export files, udev takes a little time to adjust the permissions, so when the library accesses the gpio file it doesn't have the permission to do so.
As a workaround I added a delay in GPIO.py (see attached patch opi.zip) but I think there should be a better way .
See also https://forum.armbian.com/index.php?/topic/5225-gpio-from-python-user-space-opigpio-app/
I for the life of me can't get it to work. Here's the code I am using:
import OPi.GPIO as GPIO
import orangepi.pc
import time
def pin_number(letter, digit):
return (ord(letter) - ord('A')) * 32 + digit
pin = pin_number('A', 13)
GPIO.setmode(orangepi.pc.BOARD)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def event_callback(channel):
print('Event detected: %s' % GPIO.input(pin))
GPIO.add_event_detect(pin, GPIO.BOTH, callback=event_callback, bouncetime=50)
while True:
time.sleep(1)
I simply never get an edge detected. Output works just fine.
Could you please elaborate more on the sunxi numbering system. Thank you
Can anyone pointout how to add support to OrangePI Zero 2 having H616 chip?
The Orange Pi Zero 3 uses an Allwinner H618 processor which appears to be very similar to the H616 used in the Zero 2. In fact, the pin mappings may even be identical. Here's a link to the Zero 3 schematic: OrangePi-Schematic of ZERO3.pdf
As soon as I get my Zero 3 in the mail, I'll see if I can figure out the physical to GPIO pin mappings and create a pull request. In the meantime, I'd love to hear if anyone has experimented with it yet!
Hello there,
thanks a lot for your library, it helps me quite a lot.
Today, I decided to give a go at PWM, so I cloned your repo, built it, and then tried the PWM demo.
Here is what I got:
Traceback (most recent call last):
File "pwm.py", line 10, in <module>
p = GPIO.PWM(PWM_chip, PWM_pin, frequency_Hz, Duty_Cycle_Percent) # new PWM on channel=LED_gpio frequency=38KHz
TypeError: function takes exactly 2 arguments (4 given)
The code begins like that:
import OPi.GPIO as GPIO
if __name__ == "__main__":
PWM_chip = 0
PWM_pin = 0
frequency_Hz = 3800
Duty_Cycle_Percent = 100
p = GPIO.PWM(PWM_chip, PWM_pin, frequency_Hz, Duty_Cycle_Percent) # new PWM on channel=LED_gpio frequency=38KHz
[...]
What did I do wrong?
Can you help?
Thanks.
I tried both BOARD and BCM using OrangePi-PC.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import orangepi.pc
import OPi.GPIO as GPIO
from time import sleep # this lets us have a time delay
pin=26
GPIO.setmode(orangepi.pc.BOARD) # set up BOARD numbering
GPIO.setup(pin, GPIO.OUT) # set pin 26 as an output (LED)
try:
print ("Press CTRL+C to exit")
while True:
GPIO.output(pin, 1) # set port/pin value to 1/HIGH/True
sleep(0.1)
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
sleep(0.1)
GPIO.output(pin, 1) # set port/pin value to 1/HIGH/True
sleep(0.1)
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
sleep(0.1)
sleep(0.5)
except KeyboardInterrupt:
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
GPIO.cleanup() # Clean GPIO
print ("Bye.")
It work fine.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import orangepi.pc
import OPi.GPIO as GPIO
from time import sleep # this lets us have a time delay
pin=7
GPIO.setmode(orangepi.pc.BCM) # set up BCM numbering
GPIO.setup(pin, GPIO.OUT) # set BCM7 (pin 26) as an output (LED)
try:
print ("Press CTRL+C to exit")
while True:
GPIO.output(pin, 1) # set port/pin value to 1/HIGH/True
sleep(0.1)
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
sleep(0.1)
GPIO.output(pin, 1) # set port/pin value to 1/HIGH/True
sleep(0.1)
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
sleep(0.1)
sleep(0.5)
except KeyboardInterrupt:
GPIO.output(pin, 0) # set port/pin value to 0/LOW/False
GPIO.cleanup() # Clean GPIO
print ("Bye.")
It don't work.
I changed orangepi/pc.py as follows
# NanoPi Duo BCM pin to actual GPIO pin
BCM = {
2: 12, # I2C0_SDA/PA12 (TWI0_SDA/DI_RX/PA_EINT12)
3: 11, # I2C0_SCL/PA11 (TWI0_SCK/DI_TX/PA_EINT11)
4: 6, # PA6 (SIM_PWREN/PWM1/PA_EINT6)
14: 13, # PA13 (SPI1_CS/UART3_TX/PA_EINT13)
15: 14, # PA14 (SPI1_CLK/UART3_RX/PA_EINT14)
17: 1, # PA1 (UART2_RX/JTAG_CK/PA_EINT1)
18: 110, # PD14
27: 0, # PA0 (UART2_TX/JTAG_MS/PA_EINT0)
22: 3, # PA3 (UART2_CTS/JTAG_DI/PA_EINT3)
23: 68, # PC4
24: 71, # PC7
10: 64, # PC0 (SPI0_MOSI)
9: 65, # PC1 (SPI0_MISO)
25: 2, # PA2 (UART2_RTS/JTAG_DO/PA_EINT2)
11: 66, # PC2 (SPI0_CLK)
8: 67, # PC3 (SPI0_CS)
7: 21, # PA21 (PCM0_DIN/SIM_VPPPP/PA_EINT21)
0: 19, # PA19 (PCM0_CLK/TWI1_SDA/PA_EINT19)
1: 18, # PA18 (PCM0_SYNC/TWI1_SCK/PA_EINT18)
5: 7, # PA7 (SIM_CLK/PA_EINT7)
6: 8, # PA8 (SIM_DATA/PA_EINT8)
12: 200, # PG8 (UART1_RTS/PG_EINT8)
13: 9, # PA9 (SIM_RST/PA_EINT9)
19: 10, # PA10 (SIM_DET/PA_EINT10)
16: 201, # PG9 (UART1_CTS/PG_EINT9)
26: 20, # PA20 (PCM0_DOUT/SIM_VPPEN/PA_EINT20)
20: 198, # PG6 (UART1_TX/PG_EINT6)
21: 199, # PG7 (UART1_RX/PG_EINT7)
}
orangepi zero2 python3
import time
import OPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
not working
GPIO.setmode(GPIO.orangepi.zero2)
not working
import orangepi.zero2
from OPi import GPIO
GPIO.setmode(orangepi.zero2.BOARD)
not working
GPIO.setboard(GPIO.ZERO2)
GPIO.setmode(GPIO.BOARD)
not working
how to working in GPIO.setboard
I want to know how to turn off or turn on the machine.
how to serboard, setmode
I wonder how to set it up.
Hi,
Just wondering if OPi.GPIO could be used on an OR Pi with 40 pins.
/Gerry
Hello,
Do you plan to add Pwm support the the library?
Ubuntu 16.04
Jetson TX2 board (aarch64, ARMv8)
Hello all.
Thanks to LUMA libs, my robot has eyes.
I need to run my python without root privileges, and it produces an error !
python /home/nvidia/catkin_ws/src/alfred_eyes/src/RandomOledEyes.py
Traceback (most recent call last):
File "/home/nvidia/catkin_ws/src/alfred_eyes/src/RandomOledEyes.py", line 21, in <module>
serial = spi(port=3, device=0, bus_speed_hz=8000000, transfer_size=2048, gpio=GPIO, gpio_DC=1, gpio_RST=2)
File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 253, in __init__
bitbang.__init__(self, gpio, transfer_size, DC=gpio_DC, RST=gpio_RST)
File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 153, in __init__
self._DC = self._configure(kwargs.get("DC"))
File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 164, in _configure
self._gpio.setup(pin, self._gpio.OUT)
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 366, in setup
sysfs.direction(pin, direction)
File "/usr/local/lib/python2.7/dist-packages/OPi/sysfs.py", line 32, in direction
with open(path, "w") as fp:
IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio298/direction'
Does anyone has idea to correct it ? Anything like udev ?
Thanks, Vincent.
Hello,
I am currently trying to port a python script from Raspberry to Orangepi 3 lts. Not a python coder or a coder at all. Some scripting I can do but this is too difficult for me.
This is the script I have been attempting to port to OPi.GPIO https://fissio.fi/fissio.py
Any help would be appreciated.
Timo
I am sorry I am reading though everything and this is just what I need to migrate my weather station from a Pi to a non-pi board. (price of a pi is out of control) I am using the Libre Le Potato. Below is the info I have on the BD. I need help to create the pin_mapping for this non-pi bd. Is there anyone that can help or point me in the correct direction?
See my post on Armbian forum https://forum.armbian.com/topic/6069-rpigpio-replacement-for-orange-pi-zero-and-nano-pi-duo and the reply. Also see https://forum.armbian.com/topic/5655-armbianio-api-proposal and https://www.cnx-software.com/2017/11/03/learn-more-about-linuxs-new-gpio-user-space-subsystem-libgpiod
Any plans to wrap libgpiod?
E assert 71 in {}
E assert False
E + where False = <function edge_detected at 0x7f4cfb0b5aa0>(23)
E + where <function edge_detected at 0x7f4cfb0b5aa0> = event.edge_detected
E Failed: DID NOT RAISE <type 'exceptions.RuntimeError'>
when we will be able to utilize this library in opi5 and opi5 +
Hi!
After a recent OS (dietpi) and firmware update on my OPi Zero, my python code stopped working. I found that the problem is around "GPIO.setup(..., pull_up_down=GPIO.PUD_UP)".
When I run the code it spits out "AttributeError: 'module' object has no attribute 'PUD_UP' ".
Probably I screwed up something but I could not figure out what.
my code:
#!/usr/bin/python
import OPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(11,GPIO.IN,pull_up_down=GPIO.PUD_UP)
when run with ./mycode.py
it replies:
Traceback (most recent call last):
File "./test.py", line 6, in <module>
GPIO.setup(11,GPIO.IN,pull_up_down=GPIO.PUD_UP)
AttributeError: 'module' object has no attribute 'PUD_UP'
Thanks for reading ;)
Hi all,
So i've got a OrangePi Zero Plus2 H5 board and am trying to get 4 buttons to work. The buttons have four pins each, pushing the button shorts the bottom two pins, where i've connected the cable that goes to the board. (physical pin 15). Also i've connected a 10k resistor between the 3.3v power pin and the top two pins of the button.
In the following code i'm just trying to get one button to work
import orangepi.zeroplus2
from OPi import GPIO
from time import sleep
GPIO.setmode(orangepi.zeroplus2.BOARD)
orangePin = 15
GPIO.setwarnings(False)
GPIO.setup(orangePin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def event_callback(channel):
print(f'Event detected: {GPIO.input(orangePin)}')
try:
GPIO.add_event_detect(orangePin, GPIO.BOTH, callback=event_callback, bouncetime=50)
while True:
sleep(1)
except KeyboardInterrupt:
print('Done')
GPIO.cleanup()
The readings are not consistent. But when i press the button the event_callback function is not triggered. (when released i get this behavior)
Event detected: 0
Event detected: 1
Event detected: 0
Event detected: 1
Event detected: 0
Event detected: 1
Event detected: 0
Event detected: 1
Event detected: 0
Also tried to increase the bounce time (just to test out). a couple of other types of resistors and a few other pins on the board but the problem unfortunately remains
Hoping that someone can give me any pointers on how to resolve this.
Thanks !
I have encountered a problem when using
GPIO.add_event_detect(channel)
on an orangepi zero
As soon as i use this function, the GPIO.input(channel) is random and static
The interrupt is working, but i cannot read the input any longer with the actual value, instead i get a constant 0 or a constant 1, but this seems to endependent of the input-state.
The PullUp is still active and even the Pin is no output - i just get no actual value.
If i skip the add_event_detect i can read the actual value of the pin.
I have installed OPi.GPIO with "sudo pip install OrangePi.GPIO" - at the moment i don't know which version i have.
OrangePi Zero 2W
6.1
kernelOPi.GPIO
is installed, but import doesn't work.wiringpi
code works.3.4.0
?mkdir blink-opi && cd blink-opi
python -m venv .venv
pyenv local 3.10.0 # this version is installed via pyenv on system
pip install OPi.GPIO
# create blink-opi.py
sudo python blink-opi.py
Traceback (most recent call last):
File "/home/opi/code/blink-opi/blink-opi.py", line 3, in <module>
import OPi.GPIO as GPIO
ModuleNotFoundError: No module named 'OPi'
#!/usr/bin/env python
# import RPi.GPIO as GPIO
import OPi.GPIO as GPIO
from time import sleep
ledPin = 8
GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
GPIO.setup(ledPin, GPIO.OUT)
try:
while True:
GPIO.output(ledPin, 1)
sleep(0.5)
GPIO.output(ledPin, 0)
sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup() # resets all GPIO ports used by this program
import wiringpi
from time import sleep
import sys
from wiringpi import GPIO
wiringpi.wiringPiSetup()
NUM = wiringpi.getGpioNum()
ledPin = 3 # Physical 8
wiringpi.pinMode(ledPin, GPIO.OUTPUT)
try:
while True:
wiringpi.digitalWrite(ledPin, GPIO.HIGH)
sleep(0.5)
wiringpi.digitalWrite(ledPin, GPIO.LOW)
sleep(0.5)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)
Hi, I'm working on OPi Lite 2 board and came across this page for porting RPi.GPIO lib into OPi board. Is anyone working on getting Lite 2 board supported by this drop-in lib yet? If yes, I might want to give it a try.
thanks,!
Hardware: OrangePi PC (H3)
OS: Armbian 22.05.3 Jammy with Linux 5.15.48-sunxi
Issue: running sudo usermod -aG gpio
produces error: usermod: group "gpio" "does not exist"
I created the group manually (per #47), and continued to follow the instructions but am still not able to access GPIO with non-root user (Permission denied '/sys/class/gpio/gpio7/direction'
).
Can it be there is a comma error in the instructions?
The instruction use "Right Double Quotation Mark", "Left Double Quotation Mark" and "Left Single Quotation Mark" instead of the more common "Quotation Mark" and "Apostrophe"
I replaced the above with the common chars, but am still not able to obtain non-root access:
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'" SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
Hi,
I am trying to setup the following PA10 pin as input in the "BOARD" mode.
Other references to this pin:
Orange Pi = SIM_DET/PA_EINT10/PA10
Physical Pin = 26
My code:
import OPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(26, GPIO.IN)
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 356, in setup
sysfs.unexport(pin)
File "/usr/local/lib/python2.7/dist-packages/OPi/sysfs.py", line 26, in unexport
fp.write(str(pin))
IOError: [Errno 22] Invalid argument
I don't get this error in any other pins when I try to set them as input. Am I missing something?
Not sure this is related to the library but just in case...
When I run the test script below, it works fine but then when I press ctrl+c, it does not exit.
import OPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
pin = 9
GPIO.setup(pin, GPIO.IN,initial=GPIO.HIGH)
def event_callback(pin):
print pin
print GPIO.input(pin)
GPIO.add_event_detect(pin, GPIO.FALLING, callback=event_callback)
while True:
time.sleep(10)
Looks like the interrupt is caught hence sleep() is interrupted but then the only way to close the script is to kill it from a different console.
Traceback (most recent call last):
File "gpio.py", line 12, in <module>
time.sleep(10)
KeyboardInterrupt
If I comment out GPIO.add_event_detect(pin, GPIO.FALLING, callback=event_callback), it exists normally.
Thanks
Hi!
I try to use the OPi.GPIO with radxa zero pinout. But i get a "KeyError: 25" in the pin_mappings.py, line 80, in get_gpio_pi return _pin_map[mode][channel]
I'm not that experienced, so i might be doing something very wrong or missing out.
Thank you for your help!
Hello,
I wanted to use a RPi script to use a rotary dialer, https://github.com/Szpeja/RotaryPi/blob/master/modules/RotaryDial.py
But it seem that rising edge detection is somewhat inaccurate, sometime detecting one less change in input than it should.
While I don't know much about Python at all, I tried a simple script to actively monitor the "button"
import OPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN)
while True:
input_state = GPIO.input(2)
if input_state == True:
print('Button Pressed')
time.sleep(0.01)
else:
print('nope')
time.sleep(0.01)
I've ran both at the same time, and while the output of that small script was what I expected (10 "Button Pressed" for 10 impulsion)
...
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
Button Pressed
nope
nope
nope
nope
The output of the one depending on rising edge detection only detected 9 changes
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[INPUT] 1 (2)
[INPUT] 0 (2)
[DIGIT] Got digit: 9
[NUMBER] We have: 9
You can especially see at the line 5 and 6 that it didn't detect one of the change.
It get it right sometime, but not always, and it doesn't seem to be an hardware issue as monitoring the pin manually give me the correct number of value change, I don't know if it's fixable but the problem definitively seem to be around rising edge detection.
Hi everyone,
I am using "Ubuntu image" to lunch my board. when I use "gpio readall" command, it shows me all pins info well. I want to use physical pin 7 (GPIO 2) to control an LED on/off as a test. Controlling the pin with bash is ok, and all these command like "gpio mode 2 out", "gpio write 2 0" works fine and could control LED as well.
--- So, the pin is OK and can control LED with bash command ---
The problem rises when I am using "OPi.GPIO" to control LED condition. I change the "pin_mapping" file to comply "Orange pi 5" board's pin_mapping. Now, everything also goes well and when I run my python code it change the value inside "/sys/class/gpio2/value" file from 0 to 1 and vice versa as it was demanded.
--- So, the code is also OK ---
But, It has no effect on the LED condition!
I mean it can change the value inside "value" file as programmed in "GPIO.py and sysfy.py" files, but has no effect on pin.
Thank anybody in advance if has any idea!? Do I miss something here?
I have an issue with events detection in my OrangePi One Plus . I'm running this script as a root user:
import orangepi.oneplus
import OPi.GPIO as GPIO
from time import sleep
channel = 21
GPIO.setmode(orangepi.oneplus.BOARD)
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
print('This is a edge event callback function!')
print('Edge detected on channel %s'%channel)
print('This is run in a different thread to your main program')
GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback)
while True:
sleep(.5)
GPIO.cleanup()
print("Bye")
The output is:
inputsInterruptions.py:8: UserWarning: Pull up/down setting are not (yet) fully supported, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
inputsInterruptions.py:8: UserWarning: Channel 21 is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/OPi/event.py", line 74, in run
sysfs.edge(self._pin, NONE)
File "/usr/local/lib/python2.7/dist-packages/OPi/sysfs.py", line 84, in edge
with open(path, "w") as fp:
IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio67/edge'
Traceback (most recent call last):
File "inputsInterruptions.py", line 20, in <module>
GPIO.cleanup()
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 572, in cleanup
cleanup(list(_exports.keys()))
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 578, in cleanup
cleanup(ch)
File "/usr/local/lib/python2.7/dist-packages/OPi/GPIO.py", line 582, in cleanup
event.cleanup(pin)
File "/usr/local/lib/python2.7/dist-packages/OPi/event.py", line 162, in cleanup
remove_edge_detect(pin)
File "/usr/local/lib/python2.7/dist-packages/OPi/event.py", line 144, in remove_edge_detect
_threads[pin].cancel()
File "/usr/local/lib/python2.7/dist-packages/OPi/event.py", line 45, in cancel
self.join()
File "/usr/local/lib/python2.7/dist-packages/OPi/event.py", line 81, in join
raise e
IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio67/edge'
gpio readall output:
$ gpio readall
+------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 230 | 0 | SDA.1 | ALT4 | 0 | 3 || 4 | | | 5V | | |
| 229 | 1 | SCL.1 | ALT4 | 0 | 5 || 6 | | | GND | | |
| 228 | 2 | PWM1 | OFF | 0 | 7 || 8 | 0 | OFF | PD21 | 3 | 117 |
| | | GND | | | 9 || 10 | 0 | OFF | PD22 | 4 | 118 |
| 120 | 5 | RXD.3 | ALT2 | 0 | 11 || 12 | 0 | OFF | PC09 | 6 | 73 |
| 119 | 7 | TXD.3 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 122 | 8 | CTS.3 | OUT | 0 | 15 || 16 | 0 | IN | PC08 | 9 | 72 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC07 | 10 | 71 |
| 66 | 11 | MOSI.0 | OFF | 0 | 19 || 20 | | | GND | | |
| 67 | 12 | MISO.0 | IN | 1 | 21 || 22 | 0 | ALT2 | RTS.3 | 13 | 121 |
| 64 | 14 | SCLK.0 | OUT | 0 | 23 || 24 | 0 | OFF | CE.0 | 15 | 69 |
| | | GND | | | 25 || 26 | 0 | OFF | PH03 | 16 | 227 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+
what i'm doing wrong?
Actually I have success with inputs polling method and controlling outputs.
Thank you in advance!!!
Hello,
I'm sure this library works just fine but I'm missing some piece here. I'm trying to drive an SSD1351 LCD with OPi.GPIO + Luma.OLED however I'm not having much luck. Here is what I did:
apt-get update
apt-get install python3 python3-pip python3-pil libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libopenjp2-7 libtiff5 -y
pip3 install luma.oled
pip3 install --upgrade OPi.GPIO
MOSI > GPIO1_A7 > SPI1_RXD > M4 Pin 21 > LCD DIN Pin (blue)
SCK > GPIO1_B1 > SPI1_CLK > M4 Pin 23 > LCD CLK Pin (yellow)
CS > GPIO1_B2 > SPI1_CSn0 > M4 Pin 24 > LCD CS Pin (orange)
RST > GPIO1_A1(3V) > M4 Pin 11 > LCD RST Pin (white)
DC > GPIO1_A3(3V) > M4 Pin 13 > LCD DC Pin (green)
ls /dev/spi*
/dev/spidev1.0
python3 luma.examples/examples/3d_box.py
--display=ssd1351
--interface=spi
--width=128 --height=128
--spi-bus-speed=16000000
--bgr
--spi-device=1 --spi-port=0
--gpio-reset=35
--gpio-data-command=33
--gpio=OPi.GPIO
--gpio-mode=nanopi.m4.BOARD
From what I understand of https://github.com/rm-hull/OPi.GPIO/blob/master/nanopi/m4.py my physical pin 11 maps to GPIO 33 and physical pin 13 to GPIO 35. Is this even correct?
Now it fails with the following output:
Traceback (most recent call last):
File "luma.examples/examples/3d_box.py", line 129, in <module>
device = get_device()
File "/root/luma.examples/examples/demo_opts.py", line 61, in get_device
device = cmdline.create_device(args)
File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 246, in create_device
device = Device(serial_interface=interface(), **params)
File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 161, in spi
gpio=self.gpio or GPIO)
File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 299, in __init__
bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 187, in __init__
self._DC = self._configure(kwargs.get("DC"))
File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 200, in _configure
self._gpio.setup(pin, self._gpio.OUT)
File "/usr/local/lib/python3.7/dist-packages/OPi/GPIO.py", line 470, in setup
pin = get_gpio_pin(_mode, channel)
File "/usr/local/lib/python3.7/dist-packages/OPi/pin_mappings.py", line 80, in get_gpio_pin
return _pin_map[mode][channel]
KeyError: 33
SBC: NanoPi M4V2
System: Armbian 5.10.35-rockchip64 #21.05.1 SMP PREEMPT Fri May 7 13:53:11 UTC 2021 aarch64 GNU/Linux
Display: https://www.ebay.com/itm/203101646517
Datasheet: https://www.waveshare.com/w/upload/5/5b/1.5inch_RGB_OLED_Module_User_Manual_EN.pdf
Thank you.
Hi,
I just installed OPi.GPIO on my OrangePi Zero running Armbian buster with Linux 5.4.31-sunxi.
I followed the documentation but got the following error:
sudo pip3 install --upgrade OPi.GPIO
Collecting OPi.GPIO
Downloading https://files.pythonhosted.org/packages/32/88/be49fa348875993d033cd4234ff4f27fab97265fe3e2687de3009816190d/OPi.GPIO-0.4.0-py2.py3-none-any.whl
Installing collected packages: OPi.GPIO
Successfully installed OPi.GPIO-0.4.0
sudo usermod -aG gpio poddingue
usermod: group 'gpio' does not exist
Do I have to create the group gpio by myself, or should the pip3 install do it for me?
Thanks.
import orangepi.lite
import OPi.GPIO as GPIO
GPIO.setmode(orangepi.lite.BOARD)
GPIO.setup(16, GPIO.IN)
GPIO.wait_for_edge(16, GPIO.RISING)
gives
[Errno 2] No such file or directory: '/sys/class/gpio/gpio68/edge'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.