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

Support for Orange Pi GPIO module #240

Open
edwardjarchibald opened this issue Apr 29, 2021 · 4 comments
Open

Support for Orange Pi GPIO module #240

edwardjarchibald opened this issue Apr 29, 2021 · 4 comments

Comments

@edwardjarchibald
Copy link

edwardjarchibald commented Apr 29, 2021

I found the luma modules and examples today and worked through a few small issues that I found when getting everything running on an Orange Pi Zero LTS. I would like to contribute the changes back to this code base.

Type of Raspberry Pi

Orange Pi Zero LTS running Armbian

Linux Kernel version

Linux elephant.local 5.10.16-sunxi #trunk SMP Wed Feb 17 06:59:22 PST 2021 armv7l armv7l armv7l GNU/Linux

Expected behaviour

After figuring out the correct configuration, shown here, I tried to run the 3d_box.py example. I expected to see the example running on my ssd1351 display.

--interface=spi
--gpio=OPi.GPIO
--spi-port=1
--spi-device=0
--display=ssd1351
--width=128
--height=128

Actual behaviour

I got the following traceback:

Traceback (most recent call last):
  File "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.8/dist-packages/luma/core/cmdline.py", line 246, in create_device
    device = Device(serial_interface=interface(), **params)
  File "/usr/local/lib/python3.8/dist-packages/luma/core/cmdline.py", line 152, in spi
    GPIO = self.__init_alternative_GPIO()
  File "/usr/local/lib/python3.8/dist-packages/luma/core/cmdline.py", line 208, in __init_alternative_GPIO
    GPIO.setmode(GPIO.BCM)
ValueError: Please use setboard(board) before setmode()

Proposed change to cmdline.py

  1. Add a command line option called gpio-board which takes a string for the board definition from the GPIO library. In my example, the board is defined, in OPi.GPIO as 'ZERO' and is initialized as the integer '1'
  2. If an 'alternative gpio module is specified, then also look to see if gpio-board is set and , if so, call the 'setboard()' function with the argument supplied.

Here are diffs for the proposed change made to luma.core 2.3.1:

202,204d201
<             if hasattr(self.opts, 'gpio_board') and self.opts.gpio_board is not None:
<                 GPIO.setboard(getattr(GPIO, self.opts.gpio_board))
< 
328d324
<     gpio_group.add_argument('--gpio-board', type=str, default=None, help='Board in use for alternative RPI.GPIO compatible implementation (SPI interface only)')

Behavior after the proposed change

All of the examples run perfectly except for those that rely on Raspberry Pi video etc. Love the examples!

@thijstriemstra
Copy link
Collaborator

thanks for the details. can you make a pull request?

@edwardjarchibald
Copy link
Author

edwardjarchibald commented May 6, 2021 via email

@Shaggy013
Copy link

and dont forget the

lib.py
def rpi_gpio(self):

little strange OPi-GPIO on the same github sp why is it not in luma ?

@thijstriemstra
Copy link
Collaborator

Sure, happy to do that. It will take a bit more time before I get to it

Still interested to make a PR?

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

No branches or pull requests

3 participants