Page 1 of 1

Correct PINOUT identification: GPIO in/out RASP PI Zero and model B SOLVED

Posted: Wed Jun 20, 2018 10:52 am
by asbesto
Hi there,

I can't solve this, I'm banging my head on the wall since a week.

I simply can't get GPIO doing ANYTHING.

I tried to read an input (pin 22), I get nothing at all.

I tried to blink a led, same pin again - I get nothing. I can't even measure any voltage on that pin, so it seem dead.

My system is raspbian Jessie: Linux raspberrypi 4.4.11+ #888 Mon May 23 20:02:58 BST 2016 armv6l GNU/Linux

This is about Python and GPIO I'm using:

Code: Select all

root@raspberrypi:~# python
Python 2.7.9 (default, Mar  8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import RPi.GPIO as GPIO
>>> import RPi.GPIO as GPIO
>>> GPIO.VERSION
'0.6.2'
>>>
root@raspberrypi:~#
And those are the program that didn't work at all:

Led blink:

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
for i in range(50):
    GPIO.output(22, True)
    time.sleep(1)
    GPIO.output(22, False)
    time.sleep(1)
GPIO.cleanup()
and

Reading of GPIO 22 as input:

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.IN)
a=GPIO.input(22)
while True:
    print "This is what I read on pin 22: ",a
    time.sleep(0.1)
I get no error from python at all.

Any help?

TY all :)

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 11:45 am
by joan
In your final example the GPIO is not read within the while loop.

The prior a=GPIO.input(22) assigns the current value of the GPIO to a. It does not declare a function "a" to read the GPIO.

Also see https://pinout.xyz/

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 12:27 pm
by asbesto
OK - fixed that - nothing changed :(

Trilple checked pinout, is correct :/

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 12:34 pm
by joan
Try

sudo pigpiod

pigs w 4 1 r 4 w 4 0 r 4

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 1:37 pm
by pksato
asbesto wrote:
Wed Jun 20, 2018 12:27 pm
OK - fixed that - nothing changed :(

Trilple checked pinout, is correct :/
Check connection pin again.
Image

You configured to use a physical pin 22 (number on gray box).

On you input test program, enable pull up.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.IN,pull_up_down=GPIO.PUD_UP) # Set as input and enable pull up internal resistor.
while True:
    print "This is what I read on pin 22: ",GPIO.input(22)
    time.sleep(0.1)
Before run, probe voltage between GND (20) and Input (22), Its is zero or 3.3V?
If is 3v3 change code to enable a pull down resistor, GPIO.setup(22, GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
Run and probe voltage, now, the situation can be inverted.
With pull up enabled, the test program print True with out nothing connected. If connect pin 22 and pin 20, can print False.

I not recommend to use pull down at this time (test), to change state need do connect pin 22 to pin 1 (3v3), that is very close to 5V pin. And 5V is fatal to RPi.

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 1:53 pm
by asbesto
Really I can't believe it! This is so damn against any concept of usability.

So, GPIO.setup and GPIO.output don't use the GPIO number, as one normally can think, but the PIN number?!?!?!?!?

:shock:

It works.

I'm actually cursing any known divinity right now

Thank you all :)

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 2:40 pm
by B.Goode
So, GPIO.setup and GPIO.output don't use the GPIO number, as one normally can think, but the PIN number?!?!?!?!?
Not so.

Referring only to the RPi.GPIO library -

All the 'channel'-related functions like GPIO.setup() and GPIO.output() interpret the value you provide as either a 'Broadcom' gpio circuit or as a physical pin on the 40-way header.

Which interpretation to use is chosen by you, the coder, when you specify it with the

Code: Select all

setmode(GPIO.BOARD)
or

Code: Select all

setmode(GPIO.BCM)
function.

The choice of numbering model is yours: there is no default, this function must be called explicitly or an error will result.

You code as posted here used

Code: Select all

setmode(GPIO.BOARD)
so it was indeed the physical pin numbering that was used by the script.

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 2:41 pm
by pcmanbob
There are 2 sets of numbers you can use for the GPIO pins.

Board which are the grey ones in pksato's diagram and you select these with the command "GPIO.setmode(GPIO.BOARD)" ( which you were using in your python code)

and

BCM which are the red,purple,cyan ones in pksato's diagram and you select these with the command "GPIO.setmode(GPIO.BCM)"

So it just down to which you select to use in you python code.

Edit. to make it clear.

Image

Re: Weird problem with GPIO in/out in RASP PI Zero and model B

Posted: Wed Jun 20, 2018 7:41 pm
by asbesto
So if I specift BCM instead of BOARD, it works? :)

EDIT: I think so - i checked that diagram, and it shows the "bcm" pin numbers... every example I saw online was for the BOARD setup :/

TY all, I have learned something new (and now I will engrave in my brain so I can't forget this, hahaha! :) )