3 Replies Latest reply on Mar 4, 2015 9:16 AM by KurtE

    Cannot toggle gpio through sysfs

    Phil12345

      I am having trouble toggling gpio through the sysfs.

      I export the pin, set the direction to out, and confirm its pinmux is in mode0. However I cannot seem to change the value as:

       

      sudo sh -c "echo 1 > value"

      sudo cat value

      > returns 0

       

      This was working well for me until it suddenly stopped.


      Any ideas?

        • 1. Re: Cannot toggle gpio through sysfs
          mhahn

          maybe some other process intervenes? (Arduino sketch, XDK, ...)

           

          BTW: you might be interested using mraa rather than directly accessing sysfs?

          • 2. Re: Cannot toggle gpio through sysfs
            DiegoV_Intel

            Hi Phil12345,

             

            To change the value of the IO pins I run the commands below. This example is for the IO9.

            #
            # 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
            

             

            You can find more details about the GPIO configuration here: EmutexLabs

             

            Regards,

            Diego.

            1 of 1 people found this helpful
            • 3. Re: Cannot toggle gpio through sysfs
              KurtE

              It is hard to tell from your post, enough information to help.

              For example is this an Arduino board or a mini board or other?

               

              Since you are using sudo, again not sure what linux you are using and/or what version?

               

              Not sure which pin.  Would have helped if you showed actual input/output of your commands, so for example we could see what your current directory is.

               

              Have you tried doing your echo and cat with fully qualified path names? /sys/class/gpio/gpio???/value

               

              Kurt