I'm trying to change the value of GPIO port manually.

To change the value of gpio18 (physical port 12), I did as follow:

# gpio unexportall
# echo 18 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio18/direction
# cat /sys/class/gpio/gpio18/value #output is 0

# echo 1 > /sys/class/gpio/gpio18/value
# cat /sys/class/gpio/gpio18/value #output is 1

For gpio7 (physical port 26) I perform the exact commands as above. But the value remains 0:

# echo 7 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio7/direction
# cat /sys/class/gpio/gpio7/value #output is 0

# echo 1 > /sys/class/gpio/gpio7/value
# cat /sys/class/gpio/gpio7/value #output is 0 again

I've tried with all other gpio ports. All ports function properly except gpio7 and gpio11 (the value is always 0).

By the way before using this raspberry pi, I was working with another raspberry pi2. Strangely the gpio7 in the previous raspberry pi had the same problem too. Is it a hardware problem or I am doing something wrong?

Edit: Only Ethernet cable and power bank are connected to raspberry pi. By the way this is the first time that I'm using this raspberry pi.

  • There is no reason for GPIO 7 and 11 to behave differently to other GPIO. They are both SPI related. Do you have anything connected to the GPIO? You could try wiringPi's pintest utility (requires wiringPi) or my pigpio's gpio test (requires pigpio) to check the hardware.
    – joan
    Commented Dec 10, 2015 at 21:00
  • Whether or not it should or should not behave differently conceptually, there seems to be evidence that it does. If you look at this post on the pi forums: raspberrypi.org/forums/viewtopic.php?f=44&t=74085 you can see this poor fellow struggling with the same thing. FWIW - the difference in behavior in pin 7 seems to be tied to the fact that it's an SPI pin (there may be other special-purpose pins that also behave in this fashion)
    – T3am5hark
    Commented Dec 10, 2015 at 22:59
  • I tried to replicate the problem and could not on my model B pi - I was able to flip mode and set pin states just fine from the command line using just the file interfaces.
    – T3am5hark
    Commented Dec 11, 2015 at 0:25
  • @T3am5hark pin 7 is NOT a "SPI pin". While it is commonly used as CE in SPI, it is in fact not special.
    – Milliways
    Commented Dec 11, 2015 at 0:45
  • You can run sudo raspi-gpio get to see if the pin is set to any unusual mode. It appears that you may have damaged the pin, which is usually the case when you can't change.
    – Milliways
    Commented Dec 11, 2015 at 0:46

1 Answer 1


The WiringPi module for raspberry pi may solve this problem, if only by using a different method, your method may be the problem.


if you download this module (if your distro is debian based apt-get install will likely do the job), or it may already be installed, you can control the gpio pins direct from the command line with commands like:

gpio mode 7 out

gpio write 7 1

which would change your pin 7 to output and set it to 1, or high.

  • I think to be equivalent to what he's doing above, you need the -g option on the gpio mode command. The export command always uses the hardware pin numbering which is what you will see in the /sys/class/export file structure, but it's different from the wiringPi pin numbers used by default in mode and pin commands (when -g is not specified).
    – T3am5hark
    Commented Dec 11, 2015 at 0:09
  • I've tried with gpio module also, result is the same. Commented Dec 11, 2015 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.