Having issues with mraa on rock pi-s latest image

Hi

I am using this latest debian bookworm cli rockpi-s image from https://github.com/radxa-build/rock-pi-s/releases/tag/b40

I have installed libmraa2, libmraa-dev and mraa-tools.

then why mraa-gpio list shows No pins

Also not able to install python3-mraa.

What am I missing here?

Can someone here guide please?

Update : I was able to build mraa from source somehow from steps mentioned in https://wiki.radxa.com/Mraa

Still I am having the error while enabling pwm or even with gpio

Sep 03 19:09:44 rock-pi-s libmraa[544]: libmraa version v2.1.0-26-gd59936f initialised by user 'root' with EUID 0
Sep 03 19:09:44 rock-pi-s libmraa[544]: gpio: platform doesn't support chardev, falling back to sysfs
Sep 03 19:09:44 rock-pi-s libmraa[544]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 25
Sep 03 19:09:45 rock-pi-s libmraa[544]: pwm_init: pwm0. Failed to open export for writing: No such file or directory

Sep 03 19:11:22 rock-pi-s libmraa[11145]: libmraa version v2.1.0-26-gd59936f initialised by user 'root' with EUID 0
Sep 03 19:11:22 rock-pi-s libmraa[11145]: gpio: platform doesn't support chardev, falling back to sysfs
Sep 03 19:11:22 rock-pi-s libmraa[11145]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 25
Sep 03 19:11:30 rock-pi-s libmraa[11145]: gpio79: init: Failed to open 'export' for writing: No such file or directory

How to fix this?

This is so irritating just having something basic like GPIO to work on rock pi.

The oldest image available on wiki downloads works fine with mraa but has very outdated kernel.

How to fix this error in the new images?

Please help. Why do these new images are released on github if they don’t support these functionalities.

Tried these steps now

@RadxaYuntian

My bad. The logs were from Debian 12. Same error is showing in Debian 11 with python3.9.

I have built mraa from source from these steps

git clone -b master https://github.com/radxa/mraa.git

Changed these lines in CMakeLists.txt

-option (BUILDSWIGNODE "Build swig node modules." ON)
+option (BUILDSWIGNODE "Build swig node modules." OFF)

Changed these lines in include/version.h

-const char* gVERSION;
-const char* gVERSION_SHORT;
+extern const char* gVERSION;
+extern const char* gVERSION_SHORT;

Ran these steps with root user

mkdir build
cd build/
cmake ..
make
make install
ldconfig

mraa-gpio shows correct output

root@rock-pi-s:/home/rock/mraa/build# mraa-gpio version
Version v2.1.0-26-gd59936f on Radxa ROCK Pi S
root@rock-pi-s:/home/rock/mraa/build# mraa-gpio list
01         3V3: 
02          5V: 
03     I2C_SDA: GPIO I2C  
04          5V: 
05     I2C_SCL: GPIO I2C  
06         GND: 
07 I2S0_8CH_MC: GPIO 
08    UART0_TX: GPIO UART 
09         GND: 
10    UART0_RX: GPIO UART 
11 PWM2,I2C3_S: GPIO I2C  PWM  
12 I2S0_8CH_SC: GPIO 
13 PWM3,I2C3_S: GPIO I2C  PWM  
14         GND: 
15    SPDIF_TX: GPIO 
16 I2S0_8CH_SD: GPIO 
17         3V3: 
....
...
...

Enabled pwm3 from rsetup
image

After this tried initialising pwm and gpio with python mraa, and same error is showing

>>> import mraa
>>> pin = mraa.Pwm(13)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/mraa.py", line 511, in __init__
    _mraa.Pwm_swiginit(self, _mraa.new_Pwm(pin, owner, chipid))
ValueError: Error initialising PWM on pin
>>> pin = mraa.Gpio(32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/mraa.py", line 420, in __init__
    _mraa.Gpio_swiginit(self, _mraa.new_Gpio(pin, owner, raw))
ValueError: Invalid GPIO pin specified
Sep 04 07:10:34 rock-pi-s libmraa[5717]: libmraa version v2.1.0-26-gd59936f initialised by user 'root' with EUID 0
Sep 04 07:10:34 rock-pi-s libmraa[5717]: gpio: platform doesn't support chardev, falling back to sysfs
Sep 04 07:10:34 rock-pi-s libmraa[5717]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 25
Sep 04 07:10:42 rock-pi-s libmraa[5717]: pwm_init: pwm0. Failed to open export for writing: No such file or directory
Sep 04 07:10:52 rock-pi-s libmraa[5717]: gpio79: init: Failed to open 'export' for writing: No such file or directory

I installed image b38 tag from the rockpi-s build releases - https://github.com/radxa-build/rock-pi-s/releases.

root@rock-pi-s:/home/rock# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

My objective is to access gpio, pwm etc. via mraa python in the most updated debian image for rock pi-s.

We are currently using the oldest official radxa rock pi s image from the wiki downloads but we want an image with the updated kernel.

We are using rock pi-s for our fleet of IoT-controllers and we are stuck in this. Your help will be highly appreciated.

Can you please provide answers to the following questions?

  • Since the wiki is not being maintained, Is there an updated documentation on how to use the latest builds with proper steps for mraa installation?
  • Is it possible to use mraa with python bindings in the Debian 11?
  • If yes, then what am I doing wrong, how to fix the above error and what are the right steps to install mraa?
  • What is the fully tested official debian image which is tested with mraa?

Continue from our GitHub issue.


You should just use mraa’s own documentation. It is a 3rd party library after all. In case of installation, we provide the prebuilt package under the same name as mraa’s PPA in our package repositories, as their PPA only contains outdated packages now:

Did you run python with sudo?

Upstream mraa currently does not support ROCK Pi S, so you need to self built from our fork. We currently only provide prebuilt for upstream mraa, and send PRs to them constantly.

mraa is largely agnostic to the underlying system.

Yes those tests in python were with root user only

rock@rock-pi-s:~$ sudo su
root@rock-pi-s:/home/rock# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mraa
>>> pin = mraa.Pwm(13)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/mraa.py", line 511, in __init__
    _mraa.Pwm_swiginit(self, _mraa.new_Pwm(pin, owner, chipid))
ValueError: Error initialising PWM on pin
>>> pin = mraa.Gpio(32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/mraa.py", line 420, in __init__
    _mraa.Gpio_swiginit(self, _mraa.new_Gpio(pin, owner, raw))
ValueError: Invalid GPIO pin specified
>>> 

we provide the prebuilt package under the same name as mraa’s PPA in our package repositories,

Upstream mraa currently does not support ROCK Pi S, so you need to self built from our fork. We currently only provide prebuilt for upstream mraa, and send PRs to them constantly.

Do you mean building from https://github.com/radxa-pkg/mraa ? This is the fork you are referring to?
Does it support rockpi-s?

I can see in https://github.com/radxa-pkg/mraa/tree/master/src/arm it does not contain rockpi-s.

radxa-pkg/mraa is the upstream version where we only add the packaging code, no extra feature. Those are submitted in PRs which we sync with above repo when they are accepted.

radxa/mraa is the discontinued fork that supports ROCK Pi S.

In my logs you can check I cloned from the same fork and built from there.

What do you infer from these error logs?

Sep 04 07:10:34 rock-pi-s libmraa[5717]: libmraa version v2.1.0-26-gd59936f initialised by user 'root' with EUID 0
Sep 04 07:10:34 rock-pi-s libmraa[5717]: gpio: platform doesn't support chardev, falling back to sysfs
Sep 04 07:10:34 rock-pi-s libmraa[5717]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 25
Sep 04 07:10:42 rock-pi-s libmraa[5717]: pwm_init: pwm0. Failed to open export for writing: No such file or directory
Sep 04 07:10:52 rock-pi-s libmraa[5717]: gpio79: init: Failed to open 'export' for writing: No such file or directory

Since the mraa is working fine in the legacy debian buster image with linux 4.4.143, I tried checking the differences.

in the legacy debian 10 image, looks like this

pi@controller-18794:/sys/class/pwm/pwmchip0$ ls -la
total 0
drwxr-xr-x 3 root root    0 Sep  3 22:48 .
drwxr-xr-x 3 root root    0 Sep  3 22:48 ..
lrwxrwxrwx 1 root root    0 Sep  3 22:48 device -> ../../../ff180000.pwm
--w------- 1 root root 4096 Sep  3 22:48 export
-r--r--r-- 1 root root 4096 Sep  3 22:48 npwm
drwxr-xr-x 2 root root    0 Sep  3 22:48 power
lrwxrwxrwx 1 root root    0 Sep  3 22:48 subsystem -> ../../../../../class/pwm
-rw-r--r-- 1 root root 4096 Sep  3 22:48 uevent
--w------- 1 root root 4096 Sep  3 22:48 unexport

where as in the new debian 11 image, looks like this

rock@rock-pi-s:/sys/class/pwm/pwmchip0$ ls -la
total 0
drwxrwxr-x 3 root pwm     0 Sep  4 07:23 .
drwxr-xr-x 3 root root    0 Jan  1  1970 ..
lrwxrwxrwx 1 root root    0 Sep  4 07:23 device -> ../../../ff180000.pwm
-rwxrwxr-x 1 root pwm  4096 Sep  4 07:23 export
-rwxrwxr-x 1 root pwm  4096 Sep  4 07:23 npwm
drwxrwxr-x 2 root pwm     0 Sep  4 07:23 power
lrwxrwxrwx 1 root root    0 Jan  1  1970 subsystem -> ../../../../../class/pwm
-rwxrwxr-x 1 root pwm  4096 Sep  4 07:23 uevent
-rwxrwxr-x 1 root pwm  4096 Sep  4 07:23 unexport

We can see differences in permission and group.
Can this be the cause of the error?

If the mraa is agnostic, then why simply building from the radxa fork is not working properly in the debian 11 image?

Basically we want to move away from the such an old kernel and update our legacy image.

What steps do you suggest next so that we can have a rockpi-s image with updated kernel and working mraa?

@Nasca please take a look at this issue.

you can try this.

Thank you @Nasca !

I tried this. Built the mraa from the Radxa_ROCK_PI_S branch of your fork. I did this on the latest Debian 12 image.

pi@new-controller:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm

Now, at least some Gpio’s are working fine.

But still having issues with PWM3 pin and one GPIO pin.

pi@new-controller:~$ sudo python3
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import mraa
>>> pin = mraa.Pwm(13)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/dist-packages/mraa.py", line 709, in __init__
    _mraa.Pwm_swiginit(self, _mraa.new_Pwm(pin, owner, chipid))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Error initialising PWM on pin
>>> pin = mraa.Gpio(32)
>>> pin = mraa.Gpio(18)
>>> pin = mraa.Gpio(16)
>>> pin = mraa.Gpio(22)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/dist-packages/mraa.py", line 614, in __init__
    _mraa.Gpio_swiginit(self, _mraa.new_Gpio(pin, owner, raw))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid GPIO pin specified
>>> pin = mraa.Gpio(15)
>>> pin = mraa.Gpio(11)
>>> 

As you can see, having issues with GPIO pin 22 and not able to initialise PWM on pin 13.

Have already enabled PWM3 which corresponds to PIN 13.

image

These are the mraa logs

Sep 05 14:35:48 new-controller libmraa[832]: libmraa version v2.2.0 initialised by user 'root' with EUID 0
Sep 05 14:35:48 new-controller libmraa[832]: gpio: support for chardev interface is activated
Sep 05 14:35:48 new-controller libmraa[832]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 43
Sep 05 14:35:54 new-controller libmraa[832]: pwm_init: pwm1634038367. Failed to open export for writing: No such file or directory
Sep 05 14:36:17 new-controller libmraa[832]: [GPIOD_INTERFACE]: init: pin 22 not capable of gpio

mraa-gpio list output

pi@new-controller:~$ mraa-gpio list
01         3V3: 
02          5V: 
03    GPIO0_B3: GPIO I2C  
04          5V: 
05    GPIO0_B4: GPIO I2C  
06         GND: 
07    GPIO2_A4: GPIO 
08    GPIO2_A1: GPIO SPI  UART 
09         GND: 
10    GPIO2_A0: GPIO SPI  UART 
11    GPIO0_B7: GPIO I2C  PWM  
12    GPIO2_A5: GPIO 
13    GPIO0_C0: GPIO I2C  PWM  
14         GND: 
15    GPIO0_C1: GPIO 
16    GPIO2_B2: GPIO 
17         3V3: 
18    GPIO2_B1: GPIO 
19    GPIO1_C7: GPIO SPI  UART 
20         GND: 
21    GPIO1_C6: GPIO SPI  UART 
22    GPIO2_A7: 
23    GPIO1_D0: I2C  SPI  UART 
24    GPIO1_D1: 
25         GND: 
26     ADC_IN0: AIO  
27         GND: 
28    GPIO2_B5: GPIO 
29 ADC_KEY_IN1: AIO  
30    GPIO2_B6: GPIO 
31    MICBIAS2: 
32    GPIO2_B7: GPIO 
33    MICBIAS1: 
34    GPIO2_C0: GPIO 
35       MICN8: 
36       MCIP8: 
37       MICN7: 
38       MCIP7: 
39    GPOI3_B5: GPIO I2C  SPI  UART 
40    GPOI3_B4: GPIO I2C  SPI  UART 
41    GPOI3_B3: GPIO SPI  
42    GPOI3_B2: GPIO SPI  
43    GPIO2_B4: GPIO 
44    GPIO2_B3: GPIO 
45    GPIO2_B0: GPIO 
46    GPIO2_A6: GPIO 
47       MICN2: 
48       MCIP2: 
49       MICN1: 
50       MCIP1: 
51   LINEOUT_R: 
52   LINEOUT_L: 

Is mraa detecting the rock pi s type correctly?

How to fix this?

what’s your hardware version?

Did you reboot the system after turning on overlay?

Hardware version is rock pi-s v1.3

Yes rebooted the system after turning on overlays.

Myebe you need to clean up any residue from a previously installed mraa first.

Ok will try now in a fresh image.

Do you recommend Debian 11 or Debian 12 image?

The latest release Image is debian 12, you can try it.

@Nasca

Tried this in a fresh Debian 12 image.

Had enabled the overlays and rebooted.

Screenshot after reboot
image

rock@rock-pi-s:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm

GPIO 22 not initialising.
PWM 13 not initialising.
PWM 11 working fine though.

rock@rock-pi-s:~$ sudo python3
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mraa
>>> pin = mraa.Gpio(32)
>>> pin = mraa.Gpio(18)
>>> pin = mraa.Gpio(16)
>>> pin = mraa.Gpio(22)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/dist-packages/mraa.py", line 614, in __init__
    _mraa.Gpio_swiginit(self, _mraa.new_Gpio(pin, owner, raw))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid GPIO pin specified
>>> pin = mraa.Gpio(15)
>>> pin = mraa.Gpio(11)
>>> pin = mraa.Pwm(13)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/dist-packages/mraa.py", line 709, in __init__
    _mraa.Pwm_swiginit(self, _mraa.new_Pwm(pin, owner, chipid))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Error initialising PWM on pin
>>> pin = mraa.Pwm(11)
>>> 
rock@rock-pi-s:~$ mraa-gpio get 32
Pin 32 = 1
rock@rock-pi-s:~$ mraa-gpio get 22
Could not initialize gpio 22

rock@rock-pi-s:~$ mraa-gpio get 11
Pin 11 = 0
rock@rock-pi-s:~$ mraa-gpio get 13
Pin 13 = 1

Getting value from PIN 13 but pwm not getting initialised from python mraa.

Same errors in mraa

sudo journalctl | grep mraa

Sep 05 12:25:16 rock-pi-s libmraa[1488]: libmraa version v2.2.0 initialised by user 'root' with EUID 0
Sep 05 12:25:16 rock-pi-s libmraa[1488]: gpio: support for chardev interface is activated
Sep 05 12:25:16 rock-pi-s libmraa[1488]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 43
Sep 05 12:25:52 rock-pi-s libmraa[1488]: [GPIOD_INTERFACE]: init: pin 22 not capable of gpio
Sep 05 12:26:10 rock-pi-s libmraa[1488]: pwm_init: pwm94976. Failed to open export for writing: No such file or directory
Sep 05 12:26:44 rock-pi-s libmraa[1506]: libmraa version v2.2.0 initialised by user 'root' with EUID 0
Sep 05 12:26:44 rock-pi-s libmraa[1506]: gpio: support for chardev interface is activated
Sep 05 12:26:44 rock-pi-s libmraa[1506]: libmraa initialised for platform 'Radxa ROCK Pi S' of type 43
Sep 05 12:26:50 rock-pi-s libmraa[1506]: [GPIOD_INTERFACE]: init: pin 22 not capable of gpio

Can you try in your test setup?

Requesting you to guide further how to fix this.

Hi @Nasca @RadxaYuntian

The new images are not useful if mraa doesn’t work on them.

Can we expedite this issue and find a solution?

After you turn on PWM2 for PIN_11 with rsetup, will a pwmchip2 be created in the /sys/class/pwm/ directory, and similarly, after turning on PIN_13, will a pwmchip3 be created?

I remember a few months ago the pwm driver for upstream linux was changed, pwmchip is generated from pwmchip0 by default, so here it should be caused by pwmchip not corresponding.

After you turn on PWM2 for PIN_11 with rsetup, will a pwmchip2 be created in the /sys/class/pwm/ directory, and similarly, after turning on PIN_13, will a pwmchip3 be created?

pwm2 and pwm3 both enabled in rsetup.

but only pwmchip2 is showing in /sys/class/pwm

rock@rock-pi-s:/sys/class/pwm$ ls
pwmchip0  pwmchip1  pwmchip2

And that is why you think pwm2 is working but pwm3 is not working?

I remember a few months ago the pwm driver for upstream linux was changed, pwmchip is generated from pwmchip0 by default, so here it should be caused by pwmchip not corresponding.

So due to this change only, pwmchip3 is not showing up in the /sys/class/pwm ?

I didn’t understand this pwm driver change. You mean PWM2 actually corresponds to pwmchip1 and PWM3 corresponds to pwmchip2 ?

Is this something that can be fixed in the rock-pi-s branch of your mraa fork ?