CaptainThrills
Posts: 4
Joined: Fri Feb 05, 2016 2:38 am

GPIO Pins just will not work

Fri Feb 05, 2016 2:53 am

I have tried quite a bit over these past few hours trying to get a simple LED to light up to no avail.

Plugging into the 3.3v worked, but GPIO pins just will not work for whatever reason. WiringPi & Python just won't work.

pin I'm using

Code: Select all

| 18 | 1 | OUT  | GPIO. 5 | 5   | 24  |
commands I've tried:

Code: Select all

gpio write 5 1
gpio write 5 0
which updates the readall, but it doesnt seem to be working.

Python Code I've tried

Code: Select all

import RPi.GPIO as GPIO
import time

pin = 18
delay = 1

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

def doLED(delayit):
        print("on")
        GPIO.output(pin, GPIO.HIGH)
        time.sleep(delayit)
        print("off")
        GPIO.output(pin, GPIO.LOW)
        return;
doLED(delay)

GPIO.cleanup()
Pi:

Code: Select all

Raspberry Pi Details:
  Type: Pi 2, Revision: 01, Memory: 1024MB, Maker: Embest 
Someone save me from this madness

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 4:22 am

Have you tried setting the pin from the command prompt?

# gpio mode 5 out


# gpio write 5 1
# gpio write 5 0

See if that flips your LED.

gordon77
Posts: 5077
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 4:27 am

Do you get any errors from the Python script?

You aren't passing pin to the def.

Return doesn't need the ;, try return or return()

CaptainThrills
Posts: 4
Joined: Fri Feb 05, 2016 2:38 am

Re: GPIO Pins just will not work

Fri Feb 05, 2016 5:07 am

rzusman wrote:Have you tried setting the pin from the command prompt?

# gpio mode 5 out


# gpio write 5 1
# gpio write 5 0

See if that flips your LED.
Forgot to say that yes, I tried setting gpio mode to out.
gordon77 wrote:Do you get any errors from the Python script?

You aren't passing pin to the def.

Return doesn't need the ;, try return or return()
Heres new code, still not working (running as sudo python as well):

Code: Select all

import RPi.GPIO as GPIO
import time

pin = 18
delay = 1

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

def doLED(pin, delayit):
        print("on")
        GPIO.output(pin, GPIO.HIGH)
        time.sleep(delayit)
        print("off")
        GPIO.output(pin, GPIO.LOW)
        return
doLED(pin, delay)

GPIO.cleanup()
Appears that a simple bash script has no issue accessing GPIO:

Code: Select all

#!/bin/sh
x=0
while true; do
	if [ $x -ge 10 ]; then
		break;
	fi
	x=$((x + 1))
	echo "on"
	echo 1 > /sys/class/gpio/gpio18/value
	sleep 1
	echo "off"
	echo 0 > /sys/class/gpio/gpio18/value
	sleep 1
done

mattmiller
Posts: 2245
Joined: Thu Feb 05, 2015 11:25 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 6:44 am

unfortunately gpio18 is not the same as physical pin 18


https://superpiboy.files.wordpress.com/ ... pinout.jpg

If you want to use the gpio numbering scheme - change

GPIO.setmode(GPIO.BOARD)

to

GPIO.setmode(GPIO.BCM)

gordon77
Posts: 5077
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 7:34 am

Nothing wrong with your new python code, lights a led on pin 18 (not GPIO18) on my pi.

Can you upload a photo of your wiring ?

CaptainThrills
Posts: 4
Joined: Fri Feb 05, 2016 2:38 am

Re: GPIO Pins just will not work

Fri Feb 05, 2016 3:46 pm

Heres the circuit wiring
Image
Image

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

Re: GPIO Pins just will not work

Fri Feb 05, 2016 3:49 pm

A common problem with cobblers is to fit the ribbon cable reversed so pin 1 becomes pin 40.

Do you have a meter? If so check that the cobbler pin marked 3V3 supplies 3V3 and the cobbler pin marked 5V supplies 5V.

gordon77
Posts: 5077
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 3:59 pm

I'd say that's GPIO #18 (pin 12) NOT PIN 18 (GPIO #24)

Change your python to pin = 12, or GPIO.BCM

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: GPIO Pins just will not work

Fri Feb 05, 2016 4:26 pm

I have 2 cobblers and on both the numbers printed on the cobbler are BCM numbers, not BOARD numbers.

With bash you were changing "gpio 18", which is a BCM number and matches #18 on the cobbler, which is also a BCM number. So it works.

The Python script is setting the mode to BOARD so it doesn't work, since #18 on the cobbler is a BCM number. If you're going to use BOARD number 18 in Python then you'll need to plug into #24 on the cobbler, since BOARD #18 is BCM #24.

The simplest way is to set the mode to BCM in Python, then you can use the numbers printed right on the cobbler without having to convert BOARD numbers to BCM numbers.

CaptainThrills
Posts: 4
Joined: Fri Feb 05, 2016 2:38 am

Re: GPIO Pins just will not work

Fri Feb 05, 2016 4:47 pm

Thanks all, this makes everything a bit more clear now. Changing it to GPIO.BCM did the trick for the python script.

gordon77
Posts: 5077
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO Pins just will not work

Fri Feb 05, 2016 5:34 pm

It's easy to get confused and mix-up the 2 numbering schemes.

Return to “Troubleshooting”