9 Replies Latest reply on Aug 11, 2015 1:35 PM by Sogybot

    Can't setup GPIO

    ylg

      Hi again , i need to setup GP12 as input and GP183 as output,

      but i'm stuck


      root@x:echo -n "183" > /sys/class/gpio/export

      root@x:~# echo -n "257" > /sys/class/gpio/export

      sh: write error: No such device

      root@x:~# echo -n "225" > /sys/class/gpio/export

      sh: write error: No such device

      root@x:~# echo -n "12" > /sys/class/gpio/export

      root@x:~# echo -n "251" > /sys/class/gpio/export

      sh: write error: No such device

      root@x:~# echo -n "219" > /sys/class/gpio/export

      sh: write error: No such device

      root@x:~# echo -n "219" > /sys/class/gpio/export

      sh: write error: No such device

        • 1. Re: Can't setup GPIO
          mhahn

          have you had a look at MRAA?

          • 2. Re: Can't setup GPIO
            ylg

            MRAA fail, maybe it's not compatible with the mini breakout board ? on Arduino board it was ok :/

            • 3. Re: Can't setup GPIO
              mhahn

              the mini board is supported - see mraa/edison.md at master · intel-iot-devkit/mraa · GitHub. Could you pls send more details on what failed with MRAA on mini breakout board?

              • 4. Re: Can't setup GPIO
                DiegoV_Intel

                Hi ylg,

                 

                To configure the GPIO12 as input and the GPIO183 as output follow the commands below:

                 

                #
                # Setting IO3 as input with pull-up disable
                #
                
                echo 12 > /sys/class/gpio/export # IO3
                echo 251 > /sys/class/gpio/export # Output enable (high = output)
                echo 219 > /sys/class/gpio/export # Pull-up enable
                echo 214 > /sys/class/gpio/export # Tri-State (set it low before configure the rest, then set it high)
                
                echo low > /sys/class/gpio/gpio214/direction # Set Tri-State to low
                echo low > /sys/class/gpio/gpio251/direction # Set gpio12 as input (Output enable = low)
                echo in > /sys/class/gpio/gpio219/direction # Disable internal pull-up
                echo mode0 > /sys/kernel/debug/gpio_debug/gpio12/current_pinmux # Set the pin as gpio mode
                echo in > /sys/class/gpio/gpio12/direction # Set the gpio pin as input
                echo high > /sys/class/gpio/gpio214/direction # Set the Tri-State to high
                
                # To read: cat /sys/class//gpio/gpio12/value
                
                #
                # Set IO9 as output
                #
                
                echo 183 > /sys/class/gpio/export # IO9
                echo 257 > /sys/class/gpio/export # Output enable (high = output)
                echo 225 > /sys/class/gpio/export # Pull-up enable
                echo 214 > /sys/class/gpio/export # Tri-State (set it low before configure the rest, then set it high)
                
                echo low > /sys/class/gpio/gpio214/direction # Set Tri-State to low
                echo high > /sys/class/gpio/gpio257/direction # Set gpio183 as output (Output enable = high)
                echo mode0 > /sys/kernel/debug/gpio_debug/gpio183/current_pinmux # Set the pin as gpio mode
                echo out > /sys/class/gpio/gpio183/direction # Set the gpio pin as output
                echo high > /sys/class/gpio/gpio214/direction # Set the Tri-State to high
                
                # To write high: echo 1 > /sys/class/gpio/gpio183/value
                # To write low:  echo 0 > /sys/class/gpio/gpio183/value
                

                 

                If you get the following message when you are exporting the gpio:

                sh: write error: Device or resource busy

                It means that the gpio is already exported.

                 

                I hope you find this helpful.

                 

                Regards,

                Diego.

                • 5. Re: Can't setup GPIO
                  KurtE

                  MRAA should work.  It is setup to work with both boards.

                  Note: In your first posting, several of the IO pins you are outputting to are not pins of the Edison, but are instead logicial IO pins associated with the Arduino breakout board.  If the values are greater than about 183 it is not part of the mini breakout board.

                   

                  Also MRAA uses logical IO pins unless you try to init RAW.

                   

                  So for GPIO12 as input

                  On Arduino board, this is on logical pin 3, on Mini breakout board this is logical pin 20.

                   

                  For GPIO183

                  Arduino: Pin 9, Mini pin 21

                   

                  Kurt

                  1 of 1 people found this helpful
                  • 6. Re: Can't setup GPIO
                    ylg

                    I understand you found the logical numbers there https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md

                     

                    so i do this

                      dt = new mraa::Gpio(20);

                      slk = new mraa::Gpio(21);

                      dt->dir(mraa::DIR_IN);

                      slk->dir(mraa::DIR_OUT);

                     

                    and output is

                     

                    Failed to write to export

                    Intel Edison Failed to initialise Arduino board TriState,                         check i2c devices! FATAL

                    terminate called after throwing an instance of 'std::invalid_argument'

                      what():  Invalid GPIO pin specified

                    • 7. Re: Can't setup GPIO
                      KurtE

                      Sorry not enough information here to reproduce. Do you have a simple program that can be run to verify this.

                       

                      Again assuming mini board from your description earlier.  When your program starts up, the MRAA system will give some errors associated with tristate, that is how it detects if you are running on Arduino or assumed mini:

                      ie. it has the code:

                        tristate = mraa_gpio_init_raw(214);
                          if (tristate == NULL) {
                              syslog(LOG_INFO, "edison: Failed to initialise Arduino board TriState,\
                                      assuming Intel Edison Miniboard\n");
                              if (mraa_intel_edison_miniboard(b) != MRAA_SUCCESS) {
                                  goto error;
                              }
                              return b;
                          }
                      

                       

                      Now if you are instead actually running your code snip-it on an Arduino board,   The code will fail as pins 20,21 are not valid pins (0-19) so the dt and lk will probably be NULL, and the dt->dir call will probably faul, or throw exception.  Again if you are running on Arduino board, the mraa pin numbers for those two are 3, 9

                      • 8. Re: Can't setup GPIO
                        ylg

                        Ok , mraa was 0.4.4

                        upgrading fixed the errors

                        • 9. Re: Can't setup GPIO
                          Sogybot

                          I'm having the a similar problem, in that , I have a write error

                           

                          root@edisonwireless:~# echo 49 > /sys/class/gpio/export

                          sh: write error: Device or resource busy

                          root@edisonwireless:~#

                          root@edisonwireless:~#

                           

                          I'm following the spark fun tutorial on how to get to a blinking led with Python.

                          Videos - SparkFun Electronics