0

I'm trying to do the simple hello world of the pi world. I have been having problems actually turning pin 7 off. I tried moving my rib position in the socket (flipping the white side facing the sd card and away). Ive tried turn it off and on, but it just stays on.

So after some googling I came across a post that suggested checking the pin state. Below is the output of all the pins, to me I see error and think, yes that cant be good. Some calrity on the output below would be appreicated.

Pin State

new: gpio version is:  0.6.2
1  has error
2  has error
Pin 3 is HIGH!
4  has error
Pin 5 is HIGH!
6  has error
Pin 7 is HIGH!
Pin 8 is LOW
9  has error
Pin 10 is LOW
Pin 11 is LOW
Pin 12 is LOW
Pin 13 is HIGH!
14  has error
Pin 15 is LOW
Pin 16 is LOW
17  has error
Pin 18 is HIGH!
Pin 19 is LOW
20  has error
Pin 21 is HIGH!
Pin 22 is LOW
Pin 23 is LOW
Pin 24 is LOW
25  has error
Pin 26 is LOW
27  has error
28  has error
29  has error
30  has error
31  has error
32  has error
33  has error
34  has error
35  has error
36  has error
37  has error
38  has error
39  has error
40  has error

Code Source (https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=93877)

import RPi.GPIO as GPIO
import time

#my b+ gpio pins
GPIO.setmode(GPIO.BOARD)
mypins =  range(1, 41)


#GPIO.setmode(GPIO.BCM)
#mypins = [2, 3, 4, 14, 15, 17, 18, 27, 22, 23, 24, 10, 9, 25, 11, 8, 7, 5, 6, 12, 13, 19, 16, 26, 20, 21]
print 'new: gpio version is: ', GPIO.VERSION

for PIR_PIN in mypins:
    try:
        GPIO.setup(PIR_PIN, GPIO.IN)
        read_input = GPIO.input(PIR_PIN)

        if read_input:
            print 'Pin', PIR_PIN, 'is HIGH!'
        else:
            print 'Pin', PIR_PIN, 'is LOW'   


    except:
        print PIR_PIN, ' has error'
        continue

print 'cleaning up and exiting'
GPIO.cleanup()

System Info

pi@raspberrypi:~ $ sudo cat /proc/cpuinfo
processor   : 0
model name  : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS    : 697.95
Features    : half thumb fastmult vfp edsp java tls 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xb76
CPU revision    : 7

Hardware    : BCM2708
Revision    : 000e
Serial      : 00000000******

Configuration

pi@raspberrypi:~ $ lsmod |grep i2c
i2c_bcm2708             5740  0 
i2c_dev                 6578  0 
pi@raspberrypi:~ $ lsmod |grep spi
spi_bcm2835             7424  0 
pi@raspberrypi:~ $ 

Code To Turn Off and On

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)

for i in range(50):
    GPIO.output(7, True)
    time.sleep(0.2)
    GPIO.output(7, False)

GPIO.cleanup()

GPIO Test

pi@raspberrypi:~ $ ./gpiotest 
This program checks the Pi's (user) gpios.

The program reads and writes all the gpios.  Make sure NOTHING
is connected to the gpios during this test.

The program uses the pigpio daemon which must be running.

To start the daemon use the command sudo pigpiod.

Press the ENTER key to continue or ctrl-C to abort...

Testing...
Skipped non-user gpios: 0 1 5 6 12 13 16 19 20 21 26 
Tested user gpios: 2 3 4 7 8 9 10 11 14 15 17 18 22 23 24 25 27 28 29 30 31 
Failed user gpios: None
  • Do you mean physical pin 7 (GPIO 4) is always high? What is connected to pin 7? How are you switching it low? – joan Oct 12 '16 at 7:59
  • @joan Yes physical 7. I am using this breakout https://www.adafruit.com/products/1754. I have a jumper wire attached to pin 7 (#4 on the breakout) to an LED to a resistor to a gnd pin. – iNoob Oct 12 '16 at 17:54
  • The has error messages are because of two reasons. 1) that pin on the expansion header is connected to 5V, 3V3, or ground so is not a GPIO. 2) you have a 26 pin expansion header so pins 27-40 are not present at all. GPIO4 has an internal pull-up to 3V3 activated at boot. It will stay high until you connect something which pulls it to ground with a stronger force, or you switch it to be an output. – joan Oct 12 '16 at 18:58
  • 1
    It will turn on and off with that code. Check your connections. A common problem is connecting cobblers back to front. – joan Oct 12 '16 at 19:08
  • 1
    If my test passed it means the GPIO is okay. I'd dump the cobbler and wire direct to the breadboard. – joan Oct 14 '16 at 15:44
-1

Please check the /sys/class/gpio/ directory. You can only control those GPIOs which are exported to userspace. You can do this by echoing the GPIO number to /sys/class/gpio/export but be aware there may be a kernel driver which needs access to a particular GPIO, so don't mess it up.

  • 3
    That is not true. Most Pi GPIO libraries talk directly to the GPIO for performance reasons and no use is made of /sys/class/gpio. The sysfs GPIO interface is comparatively slow. – joan Oct 12 '16 at 13:16
  • @joan: I had to double-check it but IIRC the export mechanism exposed in /sys/class/gpio not only affects /sys/class/gpio itself, but general exposing to userspace. – Janka Oct 12 '16 at 13:20
  • 1
    I don't dispute that the sysfs interface to the GPIO exists. I am just pointing out that most Pi GPIO libraries do not use it. Most libraries map the GPIO register space into user memory using /dev/mem or /dev/gpiomem and program the GPIO registers directly. E.g. my pigpio, wiringPi, bcm2835, RPi.GPIO etc. etc. – joan Oct 12 '16 at 13:56
  • I was referring to the problem the OP has: errors when accessing GPIOs. To my understanding, all these interfaces you mentioned only work for the GPIOs which are exported to userspace. And you can check if they are through listing /sys/class/gpio. Even when you don't want to use the sysfs interface for your actual program. It's just to check for the source of the problem. – Janka Oct 12 '16 at 14:23
  • 1
    I can only say that is incorrect so many times. Run pigpio. Switch GPIO high or low with pigpio. It does not care if a GPIO is exported by sysfs or not. The errors shown in the question are because those GPIO are not connected to the expansion header on the Pi model being used by the questioner. – joan Oct 12 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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