Josiah
Posts: 2
Joined: Tue Oct 08, 2013 1:06 am

My GPIO port is not responding

Tue Oct 08, 2013 2:14 am

Hi Everybody,

I am new to the Raspberry Pi, and when I wrote a Python script to blink an LED, here, is the code I used:

import RPi.GPIO as GPIO
import time
GPIO.setup(11, GPIO.OUT)
while True:
GPIO.output(11, True)
time.sleep(2)
GPIO.output(11, False)
time.sleep(2)

It gave me an error message that said, "RPi.GPIO.ModeNotSetException."
What is wrong here? I would be glad for any advice you could give me!

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: My GPIO port is not responding

Tue Oct 08, 2013 6:49 am

"What is wrong here?"

You have not included a setmode statement, which is mandatory. See here for the documentation for RPi.GPIO which explains this.

"I would be glad for any advice you could give me!"

Sadly, the advice has to be - some online tutorials are outdated and misleading and cannot be trusted! Other advice would be to post your question only once, and to enclose python code in 'code' markers (created with the [

Code: Select all

] button at the top of the message screen) to maintain indentation because that is critical with python scripts.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: My GPIO port is not responding

Tue Oct 08, 2013 7:24 pm

If you are looking for a great tutorial on the GPIO I would suggest you look at

http://raspi.tv/rpi-gpio

It really is a great tutorial and will have you up and running in no time.

Good luck!
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

Josiah
Posts: 2
Joined: Tue Oct 08, 2013 1:06 am

GPIO still won`t work

Sat Oct 12, 2013 11:52 pm

My GPIO won`t work: I wrote code to make an LED flash, but nothing seems to work. I`ve made sure that the code is updated, the LED is correctly inserted, and it still does not work. What now?

Thank you for your ideas!

gmc
Posts: 123
Joined: Fri Mar 09, 2012 11:31 am
Location: Cheshire, UK
Contact: Website

Re: GPIO still won`t work

Sun Oct 13, 2013 5:54 am

We are not mind readers, post your code.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: GPIO still won`t work

Sun Oct 13, 2013 6:27 am

...and photos of your hardware showing clearly the wires going from GPIO pins to LEDs.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: GPIO still won`t work

Sun Oct 13, 2013 8:29 am

So have you fixed the 'setmode' problem?

'Divide and conquer' - debug by separating the physical from the 'logical' : very carefully, so you don't short anything, move the connecting lead that is NOT the ground connection for the LED from where it is now to Pin 1 (the 3.3v supply) on the gpio header. The LED should light up when the RPi is running even when you don't have a test program running.

If it does not light up you have a wiring problem and you need to correct this before doing anything else.

If it lights up you know the wiring is correct. Move the connection back to Pin 11 (or Pin 23, depending on the numbering scheme you are using) and try again. Now you can concentrate on getting the code right and matching it to your wiring scheme.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: GPIO still won`t work

Wed Oct 16, 2013 12:12 pm

Josiah wrote:My GPIO won`t work: I wrote code to make an LED flash, but nothing seems to work. I`ve made sure that the code is updated, the LED is correctly inserted, and it still does not work. What now?

Thank you for your ideas!
I've merged your 2 threads as they are of the same subject matter.
It's also polite to say thank you to the people who have offered advice, rather than just move on and ask the same question again ;)

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

WebPi
Posts: 262
Joined: Wed Apr 10, 2013 6:47 pm
Location: Birmingham, UK
Contact: Website

Re: My GPIO port is not responding

Wed Oct 16, 2013 1:48 pm

You need a line either like this:

Code: Select all

GPIO.setmode(GPIO.BCM)
or this:

Code: Select all

GPIO.setmode(GPIO.BOARD)
depending on which pin numbering scheme you're using. You should add this line just after the line that imports time.
raspberrywebserver.com - Raspberry Pi tutorials
LinuxWebServers.net - Linux Web Server tutorials and examples
pyplate.com - Python web publishing tool

ErickIR
Posts: 8
Joined: Sat Jul 20, 2013 3:29 am

Re: My GPIO port is not responding

Wed Oct 16, 2013 6:05 pm

Here is a simple YouTube video made by someone, he shows you how to set up the breadboard and gives you the code for the blinking led to work.

http://www.youtube.com/watch?v=PgiNmQrMxBc

Good Luck!

Return to “Python”