GPIO on UP²

gbeckers
gbeckers New Member Posts: 8

Hi all,

I use an UP² with kernel 5.4 and Ubuntu 18.04 installed just as described on the official wiki page. The rules to add in /lib/udev/... have also been installed.

I tried first to blink a led using pin 13 (Linux GPIO 432) and Sysfs as described on the wiki page without any success. I then had a look in the BIOS and saw in Advanced > HAT Configurations that none of the pin was tagged "GPIO". So I changed the ones I can to "GPIO" (which basically means I changed 8 pins: PWM and some others). Then I tried again to blink my led but using the pin 16 (471, PWM3 now parametrized as a GPIO in the BIOS) without any success neither...

I finally managed to make my led blink by switching back to the initial configuration in the BIOS and using either one of the 3 PWM pins. I also tried the mraa library and got an issue: mraa-list returns "No pins". However I am still able to use the python bindings provided I set raw to True and use the Linus GPIO numbers.

So here are my conclusions/questions:

1) It seems that only the pins with a given function can be used and that I need to keep the function as "PWM" even if I use it as a generic output. Am I right?

2) Is there any way to use the other pins as true GPIO? Looking at the datasheet I thought it was possible but now I am not so sure...

3) I guess I should be able to use mraa library with mraa numbering, isn't it? So any clue why my mraa-list is empty?

Thanks a lot for your help

Tagged:

Comments

  • DCleri
    DCleri Administrator, AAEON Posts: 1,213 admin

    Have you followed the steps of installing the upboard-extras packages and then added your user to the various groups as described in the wiki?
    https://github.com/up-board/up-community/wiki/Ubuntu_18.04#enable-the-hat-functionality-from-userspace

    Have you tried to use GPIO directly or via libmraa from root?

  • gbeckers
    gbeckers New Member Posts: 8

    Hi DCleri,
    Thank you for your quick response!
    I installed the upboard-extras package and checked that the rules were there.
    I added the user to GPIO only because it is the only one I need to use.

    I tried to access via the sysfs using commands such as:
    echo 432 > export

    It did export the pin. I was also able to set the direction to out and the value to 0 or 1 but nothing change on the pin. I observed a voltage ~0.3V

    I also tried using a small python script to blink the led such as:

    import sys
    import mraa
    import time

    pin_no = 432
    pin = mraa.Gpio(pin_no, owner=False, raw = True)

    time.sleep(0.1)
    pin.dir(mraa.DIR_OUT)

    while True:
    pin.write(1)
    time.sleep(0.5)
    pin.write(0)
    time.sleep(0.5)

    If I use 432 it does not blink the led on my breadboard
    If I use 471, 468 or 469 the led blinks.
    If I turn raw to false and use 16, 32 or 33 it returns a ValueError : Invalid GPIO pin specified

  • gbeckers
    gbeckers New Member Posts: 8

    I ran the command mraa-gpio version and it returns: Version 2.0.0 on Unknown platform.

    So it does not recognize the board...

    Looking at the log of libmraa:

    up2: kernel pinctrl driver unavailable
    up2: Platform failed to initialize
    imraa: Failed to open lock file
    gpio: platform doen't support chardev, falling back to sysfs
    libmraa initialised for platform 'Unknown platform' of type 98

  • DCleri
    DCleri Administrator, AAEON Posts: 1,213 admin

    What is the current BIOS version on your board?

    Can you run the command:
    uname -a

    and provide the full output?

    also please run and share the output of the following:
    dmesg | grep pinctrl

  • gbeckers
    gbeckers New Member Posts: 8

    uname -a :
    Linux ramses-UP-APL01 5.4.0-65-generic #73-18.04.1-Ubuntu SMP Tue Jan 19 09:02:24 UTC 2021 x86_64 x86_64 x_86_64 GNU/Linux

    dmesg|grep pinctrl:
    [ 0.222519] pinctrl core: initialized pinctrl subsystem

  • DCleri
    DCleri Administrator, AAEON Posts: 1,213 admin

    You are not running the UP Kernel for Ubuntu, it is normal that the functions above behaves not correctly.

    Please follow the procedure exactly as described to get the correct setup in place: https://github.com/up-board/up-community/wiki/Ubuntu_18.04#install-ubuntu-kernel-540-from-ppa-on-ubuntu-1804

    If prompted to abort kernel removal during the procedure select "No"

  • gbeckers
    gbeckers New Member Posts: 8

    Thanks a lot!

    uname -a now returns:
    Linux ramses-UP-APL01 5.4.0-1-generic #0-upboard2-Ubuntu ...

    and the GPIO works perfectly!