Using GPIO on Rock4C+ and Ubuntu Server

Hello everyone,

I can’t find how to use the GPIO with Python of my Rock4C+.

I found this link, https://wiki.radxa.com/Rock/GPIO , but when I copy and run the Python sample script it crashes.

Traceback (last call last):
  File "GPIO_test.py", line 20, in <module>.
    initpin(172, 'out')
  File "GPIO_test.py", line 9, in initpin
    f.write(str(pin))
IOError: [Errno 22] Invalid argument

I just want to enable/disable the 3.3V output. How can I do it?

Thank you very much.

you can refer to this wiki

This wiki says I need to install

sudo apt-get update
sudo apt-get install python3-libgpiod

But then I try to run on Python

  • import libgpiod and ERROR. Doesn’t exist this module
  • import gpiod and ERROR. Doesn’t exist this module

So what do I need to import?

I tried other options like,

pip install libgpiod
pip install python3-libgpiod

But that did not work either.

Finally I found this pip install gpiod, but it installs the deprecated 1.5.4 version.

It’s hard to understand why it’s so hard to find an example scrypt, e.g. blinking a led.

@Nasca please help to give some advice

there are some python examples you can refer to.

Can you say me your gpiod version please?

Or, you can refer to libgpiod official examples.

I think I did something similar to led_blink.py, the problem is that I obtain this error, the problem is that appears errors like the once below,

(FruitFlyIAvenv) root@rock-4c-plus:/home/rock/FruitFlyIA# python GPIO_test.py
Traceback (most recent call last):
  File "GPIO_test.py", line 7, in <module>
    chip = gpiod.chip(chip_name)
  File "/home/rock/FruitFlyIA/FruitFlyIAvenv/lib/python3.8/site-packages/gpiod/libgpiodcxx/__init__.py", line 105, in __init__
    self.open(device, how)
  File "/home/rock/FruitFlyIA/FruitFlyIAvenv/lib/python3.8/site-packages/gpiod/libgpiodcxx/__init__.py", line 132, in open
    chip_struct = func(device)
  File "/home/rock/FruitFlyIA/FruitFlyIAvenv/lib/python3.8/site-packages/gpiod/libgpiod/__init__.py", line 1098, in gpiod_chip_open_lookup
    chip = gpiod_chip_open_by_label(descr)
  File "/home/rock/FruitFlyIA/FruitFlyIAvenv/lib/python3.8/site-packages/gpiod/libgpiod/__init__.py", line 1065, in gpiod_chip_open_by_label
    chip_iter = iter(gpiod_chip_iter())
TypeError: iter() returned non-iterator of type 'NoneType'

That’s why I’m asking about version (or maybe I’m installing the wrong library). Because my pip gpiod it’s 1.5.4 and wiki says it’s deprecated and don’t have the gpiod.chip() method.

Thank you very much for answering :slight_smile:

First off, which image you are using? BTW We don’t officially support Ubuntu so I’d suggest you use a recent Debian system instead.

Secondly, once you installed python3-libgpiod (and make sure you uninstall the one from pip), you should find a few samples under /usr/share/doc/python3-libgpiod/examples/. Please try if you can run those.

The Ubuntu 20 Server(Linux 4.4) of your “downloads” web page.

concretely 20.04.6 LTS

Please test this Debian image.

@Peter.Wang we need to do something with the Wiki download page.

Hello everyone,

I tried the Debian image provided by @RadxaYuntian and I still have the same problem.

When I install the python3-libgpiod and then I import gpiod an error appears saying that this library doesn’t exist.

But if I pip install this message doesn’t appear.

Assuming the pip library is ok, I’m trying to run the @Nasca blink_led.py and it crashes again…

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

Did you try those samples to see if they work? Are you trying to run python 2? Python 2 is not supported.