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 pin number assignment for allwinner h616 #749

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lz00qs
Copy link

@lz00qs lz00qs commented Dec 6, 2023

Link to #689

Modify the format of the pin parameter to fix errors bellow:

Traceback (most recent call last):
  File "/root/oled.py", line 13, in <module>
    btn = DigitalInOut(board.PC11)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/digitalio.py", line 183, in __init__
    self.direction = Direction.INPUT
    ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/digitalio.py", line 213, in direction
    self._pin.init(mode=[Pin.IN](http://pin.in/))
  File "/usr/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py", line 56, in init
    self._line = self._chip.get_line(int(self._num))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument

Tested on orange pi zero2, archlinux, 6.1.31 orange pi official kernel.

@makermelissa
Copy link
Contributor

@twa127 since you originally added this board, do you know if something changed on the board or could it be an OS-specific thing?

@twa127
Copy link
Contributor

twa127 commented Dec 8, 2023

Away from home until 15th Dec, will respond when I get back.

@makermelissa
Copy link
Contributor

Away from home until 15th Dec, will respond when I get back.

No worries. Thank you. 🙏

@lz00qs
Copy link
Author

lz00qs commented Jan 30, 2024

Any updates on this request?

@makermelissa
Copy link
Contributor

@twa127 have you had a chance to look at this?

@twa127
Copy link
Contributor

twa127 commented Feb 27, 2024

Very sorry for the delay in getting back to you.

I am no longer using the OrangePi Zero 2 but have tested this change on my old board which is running 'Orange Pi buster with Linux 4.9.170-sun50iw9' and this proposed change does not run. The error message is as follows:

Traceback (most recent call last):
File "/var/www/cron/gpio_relay_test.py", line 64, in
main()
File "/var/www/cron/gpio_relay_test.py", line 53, in main
relay = digitalio.DigitalInOut(getattr(board, pin_num))
File "/usr/local/lib/python3.7/dist-packages/digitalio.py", line 143, in init
self.direction = Direction.INPUT
File "/usr/local/lib/python3.7/dist-packages/digitalio.py", line 173, in direction
self._pin.init(mode=Pin.IN)
File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py", line 46, in init
self._line = self._chip.get_line(int(self._num))
OSError: [Errno 22] Invalid argument

The existing version of pin.py does continue to work on my version of the OS.

Also tried updating Blinka to the latest version, still the same result.

I wonder if this user is using the OrangePi OS rather than Debian or Ubuntu and perhaps that is an issue.

@makermelissa
Copy link
Contributor

I wonder if this user is using the OrangePi OS rather than Debian or Ubuntu and perhaps that is an issue.

I believe that is the case. They say they have archlinux, 6.1.31 orange pi official kernel. Thanks for your input @twa127.

@twa127
Copy link
Contributor

twa127 commented Feb 28, 2024

Hi, I've managed to install Armbian Bookworm on my OPi Zero2
root@orangepizero2:/# uname -r
6.6.16-current-sunxi64

I get exactly the same results, ie. runs okay with existing version, fails with the proposed new version

@twa127
Copy link
Contributor

twa127 commented Feb 28, 2024

I've done a bit more testing and have installed the OPios which is based on ArchLinux. I cannot successfully install Blinka as the package manager (pacman) does not appear to work in this image and hence I cannot load the prerequisites. I would have not expected Blinka to function without perhaps some work in PlatformDetect.

@makermelissa
Copy link
Contributor

Thanks for testing @twa127. @lz00qs how were you able to get it running?

@lz00qs
Copy link
Author

lz00qs commented Feb 29, 2024

Thanks for testing @twa127. @lz00qs how were you able to get it running?

Also Thanks for testing @twa127. On my system (archlinux, 6.1.31 kernel) I was able to solve the problem by using this modification, I think it might be a difference in the underlying bsp of the kernel that is causing the problem, I'm on a business trip right now and it might take me as long as April to verify the problem. When I get back, I'll verify the issue with the official orange pi os 4.4, 5.4 and 6.1 kernels.

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

Hi, Did a bit more testing and was able to get OPios installed and pacman working, installed libgpiod and pip3, used pip3 to install Blinka. As in the previous case the existing pin.py worked okay and the modified version failed.

I tested using Python3 as below:

import board, digitalio
relay = digitalio.DigitalInOut(getattr(board, 'PC15'))
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.11/site-packages/digitalio.py", line 187, in init
self.direction = Direction.INPUT
^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/digitalio.py", line 217, in direction
self._pin.init(mode=Pin.IN)
File "/usr/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod/libgpiod_pin_2_x.py", line 52, in init
config={int(self._num): None},
^^^^^^^^^
AttributeError: 'Pin' object has no attribute '_num'

@lz00qs
Copy link
Author

lz00qs commented Feb 29, 2024

Hi, Did a bit more testing and was able to get OPios installed and pacman working, installed libgpiod and pip3, used pip3 to install Blinka. As in the previous case the existing pin.py worked okay and the modified version failed.

I tested using Python3 as below:

import board, digitalio
relay = digitalio.DigitalInOut(getattr(board, 'PC15'))
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.11/site-packages/digitalio.py", line 187, in init
self.direction = Direction.INPUT
^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/digitalio.py", line 217, in direction
self._pin.init(mode=Pin.IN)
File "/usr/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod/libgpiod_pin_2_x.py", line 52, in init
config={int(self._num): None},
^^^^^^^^^
AttributeError: 'Pin' object has no attribute '_num'

Thank you for your further testing, could you please provide the kernel version you are running? Could you please test this issue on 6.1 kernel?

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

[root@orange-os /]# uname -r
6.1.31-1+

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

Using the existing pin.py

import board, digitalio
relay = digitalio.DigitalInOut(getattr(board, 'PC15'))
relay.direction = digitalio.Direction.OUTPUT
relay.value = True
relay.value = False

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

I installed Blinka using

pip3 install --break-system-packages adafruit-blinka

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

I tried your btn = digitalio.DigitalInOut(board.PC11) on both the existing and modified versions of pin.py, again worked for the existing and failed with the modified.

@twa127
Copy link
Contributor

twa127 commented Feb 29, 2024

The reason why I used the format 'PC11 = Pin((1, 75))' is that if you run gpiodetect it gives
[root@orange-os h616]# gpiodetect
gpiochip0 [7022000.pinctrl] (32 lines)
gpiochip1 [300b000.pinctrl] (288 lines)

ie. there are 2 gpio devices on the chip, so need to distinguish between them as per the guide at https://learn.adafruit.com/adding-a-single-board-computer-to-blinka/adding-the-chip-file

@lz00qs
Copy link
Author

lz00qs commented Mar 1, 2024

The reason why I used the format 'PC11 = Pin((1, 75))' is that if you run gpiodetect it gives [root@orange-os h616]# gpiodetect gpiochip0 [7022000.pinctrl] (32 lines) gpiochip1 [300b000.pinctrl] (288 lines)

ie. there are 2 gpio devices on the chip, so need to distinguish between them as per the guide at https://learn.adafruit.com/adding-a-single-board-computer-to-blinka/adding-the-chip-file

Thanks for all your reply, after I get back, I'll test it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants