Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. gpio error
Qt 6.11 is out! See what's new in the release blog

gpio error

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
16 Posts 4 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tinashe
    wrote on last edited by
    #1

    can you please help
    i am using raspberry pi 3b with Emeria.os (embbed android os).
    my super user permission request is working fine the problem is that i can not access the gpio files.

    I art : Late-enabling -Xcheck:jni
    W System : ClassLoader referenced unknown path:
    I QtCore : Start
    W linker : /data/app/org.qtproject.example-1/lib/arm/libQt5AndroidExtras.so: unsupported flags DT_FLAGS_1=0x80
    W linker : /data/app/org.qtproject.example-1/lib/arm/libQt5Gui.so: unsupported flags DT_FLAGS_1=0x80
    W linker : /data/data/org.qtproject.example/qt-reserved-files/plugins/platforms/android/libqtforandroid.so: unsupported flags DT_FLAGS_1=0x80
    I Qt : qt started
    I art : Do partial code cache collection, code=10KB, data=26KB
    I art : After code cache collection, code=10KB, data=26KB
    I art : Increasing code cache capacity to 128KB
    E linker : normalize_path - invalid input: "C", the input path should be absolute
    W linker : Warning: unable to normalize "C"
    E linker : normalize_path - invalid input: "C", the input path should be absolute
    W linker : Warning: unable to normalize "C"
    I GRALLOC-MOD: Opening GPU0 module
    D vc4-drm-winsys: vc4 screen creation <= 38
    D vc4-drm-winsys: created new vc4 screen 40 => 0xa8fa6318
    I GRALLOC-PIPE: Created a pipe manager for vc4 and fd 38
    D vc4-drm-winsys: vc4 screen creation <= 43
    D vc4-drm-winsys: created new vc4 screen 44 => 0xa8fa6a98
    I OpenGLRenderer: Initialized EGL, version 1.4
    D OpenGLRenderer: Swap behavior 1
    W OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
    D OpenGLRenderer: Swap behavior 0
    D libconsole.so: Permission granted
    D libconsole.so: Unable to open /sys/class/gpio/export
    F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 5899 (RenderThread)
    "org.qtproject.example" died.

    #include <QCoreApplication>
    #include <stdio.h>
    #include <QDebug>
    #ifdef Q_OS_ANDROID
    #include <QtAndroidExtras>
    #endif
    #include <errno.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <unistd.h>

    int export_pin(){

    // Export the desired pin by writing to /sys/class/gpio/export

    int fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd == -1) {
        perror("Unable to open /sys/class/gpio/export");
         qDebug()<<"Unable to open /sys/class/gpio/export";
        exit(1);
    }
    
    if (write(fd, "24", 2) != 2) {
        perror("Error writing to /sys/class/gpio/export");
         qDebug()<<"Error writing to /sys/class/gpio/export";
        exit(1);
    

    }

    return fd;
    }

    int unexport_pin(){
    // Unexport the pin by writing to /sys/class/gpio/unexport

    int fd = open("/sys/class/gpio/unexport", O_WRONLY);
    

    if (fd == -1) {
    perror("Unable to open /sys/class/gpio/unexport");
    qDebug()<<"Unable to open /sys/class/gpio/unexport";
    exit(1);
    }

    if (write(fd, "24", 2) != 2) {
    perror("Error writing to /sys/class/gpio/unexport");
    qDebug()<<"Error writing to /sys/class/gpio/unexport";
    exit(1);
    }

    return fd;

    }

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    #ifdef Q_OS_ANDROID
        auto  result = QtAndroid::checkPermission(QString("android.permission.ACCESS_SUPERUSER"));
            if(result == QtAndroid::PermissionResult::Denied){
                QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(QStringList({"android.permission.ACCESS_SUPERUSER"}));
                if(resultHash["android.permission.ACCESS_SUPERUSER"] == QtAndroid::PermissionResult::Denied)
                    qDebug()<< "Permission rejected";
            }
            else{
    
             qDebug()<<"Permission granted";
    
            int fd;
    
                fd = export_pin();
                close(fd);
    
                // Set the pin to be an output by writing "out" to /sys/class/gpio/gpio24/direction
    
                fd = open("/sys/class/gpio/gpio24/direction", O_WRONLY);
                if (fd == -1) {
                    perror("Unable to open /sys/class/gpio/gpio24/direction");
                     qDebug()<<"Unable to open /sys/class/gpio/gpio24/direction";
                    exit(1);
                }
    
                if (write(fd, "out", 3) != 3) {
                    perror("Error writing to /sys/class/gpio/gpio24/direction");
                    qDebug()<<"Error writing to /sys/class/gpio/gpio24/direction";
                    exit(1);
                }
    
                close(fd);
    
                fd = open("/sys/class/gpio/gpio24/value", O_WRONLY);
                if (fd == -1) {
                    perror("Unable to open /sys/class/gpio/gpio24/value");
                    exit(1);
                }
    
                // Toggle LED 500 ms on and 500ms off forever
    
                  while (1) {
                    if (write(fd, "1", 1) != 1) {
                        perror("Error writing to /sys/class/gpio/gpio24/value");
                        exit(1);
                    }
                    else{
    
                      qDebug()<< "ON";
                    }
                    usleep(500000);
    
                    if (write(fd, "0", 1) != 1) {
                        perror("Error writing to /sys/class/gpio/gpio24/value");
                        exit(1);
                    }
                    else{
    
                      qDebug()<< "OFF";
                    }
    
                    usleep(500000);
                }
    
                close(fd);
    
                fd = unexport_pin();
    
                close(fd);
    
    
            }
    #endif
    
    
    return a.exec();
    

    }

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      I suggest you to use pigpio or wiringpi library in order to manage raspberry pi gpios.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      1
      • T Offline
        T Offline
        tinashe
        wrote on last edited by
        #3

        Thanks mrdebug
        but i do not think it will work because i tried the following
        code since /dev/gpiomem does not need root permission
        int fd = open("/dev/gpiomem", O_RDONLY) ;

        if (fd == -1) {

           qDebug()<<"Unable to open /dev/gpiomem";
          exit(1);
        

        }
        else{

          qDebug()<< "gpio /dev/gpiomem";
        

        }
        and still unable to access the file

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Since you are using Emeria.os, you should ask their folks on whether these GPIO's are accessible and if so, how.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          0
          • T Offline
            T Offline
            tinashe
            wrote on last edited by tinashe
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Since you are using Emeria.os, you should ask their folks on whether these GPIO's are accessible and if so, how.

              T Offline
              T Offline
              tinashe
              wrote on last edited by
              #6

              @SGaist
              thank you for the reply
              Sorry its Emteria.os
              i was told to
              the gpios are accessable
              Make sure those files are accessible from your application. Check Linux file permissions. and how do i check for these permissions?

              jsulmJ 1 Reply Last reply
              0
              • T tinashe

                @SGaist
                thank you for the reply
                Sorry its Emteria.os
                i was told to
                the gpios are accessable
                Make sure those files are accessible from your application. Check Linux file permissions. and how do i check for these permissions?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @tinashe said in gpio error:

                and how do i check for these permissions?

                ls -lh /sys/class/gpio/unexport
                

                You should read about UNIX/Linux basics.
                To get access for the group your user is in:

                chmod g+rw /sys/class/gpio/unexport
                

                For user

                chmod u+rw /sys/class/gpio/unexport
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                T 2 Replies Last reply
                0
                • jsulmJ jsulm

                  @tinashe said in gpio error:

                  and how do i check for these permissions?

                  ls -lh /sys/class/gpio/unexport
                  

                  You should read about UNIX/Linux basics.
                  To get access for the group your user is in:

                  chmod g+rw /sys/class/gpio/unexport
                  

                  For user

                  chmod u+rw /sys/class/gpio/unexport
                  
                  T Offline
                  T Offline
                  tinashe
                  wrote on last edited by
                  #8

                  @jsulm
                  thank you very much
                  how do i run this in my main file or c++ file because i have seen these commands run in cmd terminal.

                  jsulmJ T 2 Replies Last reply
                  0
                  • T tinashe

                    @jsulm
                    thank you very much
                    how do i run this in my main file or c++ file because i have seen these commands run in cmd terminal.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @tinashe said in gpio error:

                    how do i run this in my main file or c++ file because i have seen these commands run in cmd terminal

                    Why do you want to do it in your app? Just do it once in a terminal...
                    The commands I provided to set access rights need root access (via sudo for example):

                    sudo chmod g+rw /sys/class/gpio/unexport
                    

                    So, your app will not be able to do this.
                    But you should really check how access rights are handled in Emteria.os

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    T 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @tinashe said in gpio error:

                      and how do i check for these permissions?

                      ls -lh /sys/class/gpio/unexport
                      

                      You should read about UNIX/Linux basics.
                      To get access for the group your user is in:

                      chmod g+rw /sys/class/gpio/unexport
                      

                      For user

                      chmod u+rw /sys/class/gpio/unexport
                      
                      T Offline
                      T Offline
                      tinashe
                      wrote on last edited by
                      #10

                      @jsulm said in gpio error:

                      For user
                      unfortunately i can not do it on the terminal.
                      or can i do this in the cmd.txt found in boot folder?

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @tinashe said in gpio error:

                        how do i run this in my main file or c++ file because i have seen these commands run in cmd terminal

                        Why do you want to do it in your app? Just do it once in a terminal...
                        The commands I provided to set access rights need root access (via sudo for example):

                        sudo chmod g+rw /sys/class/gpio/unexport
                        

                        So, your app will not be able to do this.
                        But you should really check how access rights are handled in Emteria.os

                        T Offline
                        T Offline
                        tinashe
                        wrote on last edited by
                        #11

                        @jsulm
                        unfortunately the ssh server is locked for demo which am using currently

                        jsulmJ 1 Reply Last reply
                        0
                        • T tinashe

                          @jsulm
                          unfortunately the ssh server is locked for demo which am using currently

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @tinashe See "man 2 chmod".
                          But most probably your user will need to start the app as root (sudo for example).

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          T 1 Reply Last reply
                          0
                          • T tinashe

                            @jsulm
                            thank you very much
                            how do i run this in my main file or c++ file because i have seen these commands run in cmd terminal.

                            T Offline
                            T Offline
                            tinashe
                            wrote on last edited by
                            #13

                            @tinashe

                            i was told to do permission seeting in /data/init.d

                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @tinashe See "man 2 chmod".
                              But most probably your user will need to start the app as root (sudo for example).

                              T Offline
                              T Offline
                              tinashe
                              wrote on last edited by
                              #14

                              @jsulm
                              chmod g+rw /sys/class/gpio/unexport
                              cd /etc/udev/rules.d/
                              touch local.rules
                              ACTION=="add", KERNEL=="gpio", MODE="0666"
                              and did notwork

                              jsulmJ 1 Reply Last reply
                              0
                              • T tinashe

                                @jsulm
                                chmod g+rw /sys/class/gpio/unexport
                                cd /etc/udev/rules.d/
                                touch local.rules
                                ACTION=="add", KERNEL=="gpio", MODE="0666"
                                and did notwork

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @tinashe This does not have anything to do with Qt now, please find out how to do this with Linux.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                T 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @tinashe This does not have anything to do with Qt now, please find out how to do this with Linux.

                                  T Offline
                                  T Offline
                                  tinashe
                                  wrote on last edited by
                                  #16

                                  @jsulm
                                  thank you very much will do that

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved