Problem using Adafruit Blinka on Rock 4C+

I’m trying to use a temperature and humidity sensor on the Rock 4C+ (BME280).

As preliminary information, I’ve followed the for the Rock 4C+ and then followed instruction to install the libmraa library at the end of the guide.

However, after following the guide, the command mraa-gpio list gave me only no pins as response.

I’ve found on this thread (mraa not working) a link to an updated package mraa debian package to install manually. After installing the package manually, the command mraa-gpio list listed correctly the GPIOs PINs.

01         3V3:
02          5V:
03        SDA7: GPIO I2C
04          5V:
05        SCL7: GPIO I2C
...

I’m now facing the issue to use the Adafruit Blinka library. When I first tried to call import board from the library, I got an error that the libgpiod python bindings are not found:

ImportError: libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh

I’ve attempted first to install libgpiod following instructions in project Raspberry-Pi-Installer-Scripts, using:

sudo pip3 install --upgrade adafruit-python-shell click
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/libgpiod.py 
sudo python3 libgpiod.py

… but this fails with an error LIBGPIOD E: Unable to locate package raspberrypi-kernel-headers

I’ve then tried to add directly gpiod using pipenv install gpiod , then the import board triggers the following error:

File "/home/user/.local/share/virtualenvs/garden-sensors-BH19RWdn/lib/python3.8/site-packages/gpiod/libgpiodcxx/__init__.py", line 135, in open
raise OSError(
OSError: [Errno 0] Success: 'cannot open GPIO device 0'

What is the correct way to install libgpiod on the Rock 4C+ ? On the Adafruit Blinka it seems to me that the Rock 4C+ is supported, but I can’t have a working setup:

Any idea would be very helpful. Thanks in advance.

What Linux kernel version are you using, as this determines whether libgpiod can be used or not.

If you are using a Linux kernel version < 4.8 then you will need to use libmraa and then you need to make a small change to Adafruit Blinka pin files to use sysfs_pin in the pin.py file

Thanks for your answer.

My Rock 4C+ is running Linux Kernel version 4.4.

$ uname -r
4.4.194-11-rk3399-rockchip-g1bb08d49cc40

If you are using a Linux kernel version < 4.8 then you will need to use libmraa and then you need to make a small change to Adafruit Blinka pin files to use sysfs_pin in the pin.py file

Can you point me to some guide or give me more instructions regarding what change needs to be done?

Thanks in advance!

Sure. All you need to do is change pin.py back to the previous version. The changes from sysfs_pin to libgpiod_pin are shown here: https://github.com/adafruit/Adafruit_Blinka/pull/677/files

Note the location of this file… : adafruit_blinka/microcontroller/rockchip/rk3399/pin.py

You’ll need to find and modify this file on your Rock4 C+

Thanks for your answer.

I’ve updated the file adafruit_blinka/microcontroller/rockchip/rk3399/pin.py inside my venv. The error OSError: [Errno 0] Success: 'cannot open GPIO device 0' is gone, but it fails now some lines later when trying to initialize the i2C device.

i2c = board.I2C()
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

with error: ValueError: No I2C device at address: 0x77.

The device seems well to be on address 0x77:

$i2cdetect -y 7 returns well:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

Is there anything else I need to adapt?

This command is looking at whatever is set as the default I2C pins and probably not what you’re using

Better to use the busio library and use this command with your I2C bus of choice:
i2c = busio.I2C(board.SCL, board.SDA)

So if using I2C7 for example use board.SDA7 and board.SCL7 etc.

It’s now working using:

i2c = busio.I2C(board.SCL7, board.SDA7)

Thanks a lot for your help!!!

1 Like