paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

GPIO-27 and shell programming [solved]

Sat Dec 05, 2015 1:08 pm

I have a need to use GPIO-27 in a shell script.
Does anybody know why specifically GPIO-27 is excluded?

The information below is from the wiki.
But why not GPIO-27???

http://elinux.org/RPi_GPIO_Code_Samples

Code: Select all

#!/bin/sh
 
# GPIO numbers should be from this list
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25
 
# Note that the GPIO numbers that you program here refer to the pins
# of the BCM2835 and *not* the numbers on the pin header. 
# So, if you want to activate GPIO7 on the header you should be 
# using GPIO4 in this script. Likewise if you want to activate GPIO0
# on the header you should be using GPIO17 here.
Could this be a relic from the Rev 1 to Rev 2 change? If so, it's a bug that needs fixing.

Looking forward to hear!

paulv
Last edited by paulv on Sun Dec 06, 2015 8:36 am, edited 1 time in total.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 1:14 pm

Those looks like comments written with the Pi Rev1 in mind. You should have no problem using 27 on a Pi with a 40 pin header.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 3:10 pm

gregeric, of course I tried it, and it does not work.
This works:

Code: Select all

port22=""
echo "22" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio22/direction
port22=`cat /sys/class/gpio/gpio22/value`
echo "GPIO22 is $port22"
# clean up
echo "22" > /sys/class/gpio/unexport
However, if you substitute 27 for 22, it does not.

Did you try it?
If you managed to get it to work, can you post your code?

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 3:25 pm

Yes, works for me when modified to 27:

Code: Select all

#!/bin/sh

port22=""
echo "27" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio27/direction
port22=`cat /sys/class/gpio/gpio27/value`
echo "GPIO22 is $port22"
# clean up
echo "27" > /sys/class/gpio/unexport
Tested on & posted from RPi Zero.

What errors are you seeing?

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 4:27 pm

GPIO 27 was not connected to the expansion header on early Pis. Which model Pi are you testing on?

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 5:03 pm

Hi Joan can I ask a quick q while you're here? Are there any restriction in using bank2 gpios 32-54 in sysfs or pigpio? Was thinking of buzzing out those test pads on the back of the Zero...

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO-27 and shell programming

Sat Dec 05, 2015 5:52 pm

gregeric wrote:Hi Joan can I ask a quick q while you're here? Are there any restriction in using bank2 gpios 32-54 in sysfs or pigpio? Was thinking of buzzing out those test pads on the back of the Zero...
I rarely touch GPIO 32-53. pigpio only supports read/write/bank read/write on those GPIO. PWM, alerts (callbacks) etc. are not supported. By default the pigpio daemon only allows access to the activity LED, power LED, and USB full power GPIO in that region. You'd have to start the daemon with something like -x -1 to get access.

I'm not sure about SYSFS - it may restrict access.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: GPIO-27 and shell programming

Sun Dec 06, 2015 8:36 am

joan wrote:GPIO 27 was not connected to the expansion header on early Pis. Which model Pi are you testing on?
I use a Model B rev 2.0, but that's not the problem, it's me!
When I was preparing some more information for you, I found my goof!

This is what I normally do by using the code I showed to gregeric in the post above.
It is a piece of code that is part of a daemon installed in /etc/init.d, and runs at root level.
I use this to see if I have a certain interface connected to the P-1 header, to determine if I need to install a supporting program that runs as a daemon or not. Kinda like a "Hat" detection. I typically tie one GPIO pin high, and test for that. Normally, the daemon code checks the hardware before my Python application starts, so I can use the particular pin twice. Once for the daemon to check, and further on in my program that gets launched as a result of the "Hat" test. Normally works great.

However, this is the response I got:
pi@raspberrypi ~ $ port27=""
pi@raspberrypi ~ $ sudo sh -c "echo '27' > /sys/class/gpio/export"
pi@raspberrypi ~ $ sudo sh -c "echo 'in' > /sys/class/gpio/gpio27/direction"
sh: 1: cannot create /sys/class/gpio/gpio27/direction: Directory nonexistent
pi@raspberrypi ~ $
And that put me on the wrong track. The outdated Wiki page didn't help either, so I continued to dig in the wrong direction.

What I overlooked (face getting red fast) is that I already use GPIO-27 in /boot/config.txt

Code: Select all

# start/stop application needs a power_off signal to cut power to the Pi
dtoverlay=gpio-poweroff,gpiopin=27,active_low
The overlay gets loaded first and blocks the port, as it should be, of course!

Problem solved!
Thank you two for helping me to get back to earth.

Return to “Advanced users”