Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pull variable does not exist + Allow configuring GPIO 0/1 #8

Closed
wants to merge 2 commits into from

Conversation

cquick01
Copy link
Contributor

@cquick01 cquick01 commented Apr 8, 2024

Fixes an exception seen when trying to initialize pins

File "/home/user/my_project/venv/lib/python3.11/site-packages/RPi/GPIO/__init__.py", line 659, in setup
    if _warnings and gpio in (2, 3) and pull in (PUD_UP, PUD_DOWN):
                                        ^^^^
NameError: name 'pull' is not defined

Also updates the pin map to allow configuring GPIO 0 and 1. I've been using a little patch at the top of my script using rpi-lgpio, which works perfectly with my Pi 5

# patch RPi.GPIO (rpi-lgpio) to allow configuring ID_SD and ID_SC as GPIO pins.
GPIO._BOARD_MAP[27] = 0  # ID_SD = GPIO 0
GPIO._BOARD_MAP[28] = 1  # ID_SC = GPIO 1
GPIO._BCM_MAP = {channel: gpio for (gpio, channel) in GPIO._BOARD_MAP.items()}

Pin 27 (Board) = GPIO 0 (BCM) = ID_SD
Pin 28 (Board) = GPIO 1 (BCM) = ID_SC
@waveform80 waveform80 added the bug Something isn't working label Apr 9, 2024
@waveform80
Copy link
Owner

Argh, the first commit is definitely a bug that needs fixing. Kicking myself that I didn't spot that one.

Unfortunately, I can't accept the second commit because it's not "bug compatible" with RPi.GPIO. If you have a look at RPi.GPIO's code it doesn't include GPIO0 or 1 in the BOARD mapping and if you try and use those GPIOs from that mode it fails (the following is the "real" RPi.GPIO on a Pi 4 under Ubuntu jammy):

>>> from RPi import GPIO
>>> GPIO.setmode(GPIO.BOARD)
>>> GPIO.gpio_function(27)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The channel sent is invalid on a Raspberry Pi

You can still use GPIO 0 and 1 from the BCM mode quite happily of course, and the same is true under rpi-lgpio, but I can't justify making any deliberate differences between this and RPi.GPIO.

@cquick01
Copy link
Contributor Author

cquick01 commented Apr 9, 2024

Thanks for grabbing the first commit, and for that info! I'll see about using BCM mode in my code instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants