nakvic
Posts: 7
Joined: Tue Feb 24, 2015 9:49 pm

Can't get Python RPi.GPIO to work on Pi 2

Wed Feb 25, 2015 8:42 am

It seems Pythot GPIO lib does not do anything with gpio on Raspberry Pi 2.
I cannot even switch a led on no matter which gpio I connect it.
I tried following with gpio 17, 27, 22, 23, 24, 25 to switch a led on without success:

~ $ sudo python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.VERSION
'0.5.11'
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(17, GPIO.OUT)
>>> GPIO.output(17, GPIO.HIGH)
>>> GPIO.output(17.GPIO.LOW)

Python version 2.7.2, RPi.GPIO version 0.5.11.
However, WiringPi works fine with gpio utility from terminal like this:

$ gpio -g mode 17 out
$ gpio -g write 17 1
$ gpio -g write 17 0

Please, help!
What might be wrong with Python and RPi.GPIO on Pi 2 model B (the newest one)...

Regards,
Victor

User avatar
slmaws
Posts: 32
Joined: Wed Nov 13, 2013 6:41 pm
Location: Poland

Re: Can't get Python RPi.GPIO to work on Pi 2

Wed Feb 25, 2015 8:54 am

See this thread: http://www.raspberrypi.org/forums/viewt ... 8&t=101464

You have two solutions. Choose ONE:
- In RPi.GPIO change pin to 11
- instead of 'BCM', use 'BOARD':

Code: Select all

GPIO.setmode(GPIO.BOARD)
See my Raspberry Pi tips on http://rpitips.com

DirkS
Posts: 10748
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Can't get Python RPi.GPIO to work on Pi 2

Wed Feb 25, 2015 11:15 am

slmaws wrote:See this thread: http://www.raspberrypi.org/forums/viewt ... 8&t=101464

You have two solutions. Choose ONE:
- In RPi.GPIO change pin to 11
- instead of 'BCM', use 'BOARD':

Code: Select all

GPIO.setmode(GPIO.BOARD)
Don't think this is correct...
In the topic you link to the user used different numbering schemes for wiringpi and python.
Here the OP uses the same schemes: 'gpio -g' and 'GPIO.setmode(GPIO.BCM)' both refer to BCM numbering scheme.

DirkS
Posts: 10748
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Can't get Python RPi.GPIO to work on Pi 2

Wed Feb 25, 2015 11:19 am

nakvic wrote:What might be wrong with Python and RPi.GPIO on Pi 2 model B (the newest one)...
Tested your code on my Pi2B and it seems to work OK.

I used the 'gpio readall' (from a second console / terminal window) to check the GPIO status after every command entered in the python interpreter.
Maybe you could do the same.

User avatar
slmaws
Posts: 32
Joined: Wed Nov 13, 2013 6:41 pm
Location: Poland

Re: Can't get Python RPi.GPIO to work on Pi 2

Wed Feb 25, 2015 4:34 pm

DirkS wrote: Don't think this is correct...
In the topic you link to the user used different numbering schemes for wiringpi and python.
Here the OP uses the same schemes: 'gpio -g' and 'GPIO.setmode(GPIO.BCM)' both refer to BCM numbering scheme.
Yeah, you are right. I didn't notice that he uses the same scheme. I don't see any other reason why it doesn't work :/
See my Raspberry Pi tips on http://rpitips.com

nakvic
Posts: 7
Joined: Tue Feb 24, 2015 9:49 pm

Re: Can't get Python RPi.GPIO to work on Pi 2

Thu Feb 26, 2015 9:17 am

DirkS wrote:
nakvic wrote:What might be wrong with Python and RPi.GPIO on Pi 2 model B (the newest one)...
Tested your code on my Pi2B and it seems to work OK.

I used the 'gpio readall' (from a second console / terminal window) to check the GPIO status after every command entered in the python interpreter.
Maybe you could do the same.
That is the point! I used gpio readall on a second terminal after each python command. RPi.GPIO does not change mode!
The worst thing is that it does not say anything. No error, no warning. Just don't change mode and dont power GPIOs.

I cannot identify a cause so far...

nakvic
Posts: 7
Joined: Tue Feb 24, 2015 9:49 pm

Re: Can't get Python RPi.GPIO to work on Pi 2

Sat Feb 28, 2015 3:45 pm

I installed today fresh and clean respbian with the same results. I cannot switch on a simple LED with the latest versions of RPi.GPIO and Python on Raspberry Pi 2 Model B.

I would appreciate any ideas how to get it working...

Victor

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

Re: Can't get Python RPi.GPIO to work on Pi 2

Sat Feb 28, 2015 3:53 pm

See if you get the same problem with the pigpio Python module. Also have a look at piscope to confirm that you are toggling the gpios you think you are.

spm
Posts: 5
Joined: Thu Sep 18, 2014 8:05 am

Re: Can't get Python RPi.GPIO to work on Pi 2

Mon Mar 09, 2015 4:58 pm

I have same problem. I have python application using several GPIO outputs. Raspbian, upgraded with apt-get update. If I boot system on Pi 1 B+, application is working correctly. If I change same SD card and boot on Pi 2 B I GPIO outputs aren't working. No error from python, just output won't turn on. Turning outputs through bash and /sys/class/gpio is working fine.

nakvic
Posts: 7
Joined: Tue Feb 24, 2015 9:49 pm

Re: Can't get Python RPi.GPIO to work on Pi 2

Mon Mar 09, 2015 5:09 pm

I actually fixed it couple of days ago. However, I have no idea, what was wrong. I reinstalled latest raspbian from February 2015 instead of using NOOBS. Python and gpio started to work as expected right out of the box. Finally, I got char LCD 16x2 display working as it is described at adafruit site.

sacherjj
Posts: 2
Joined: Tue Mar 24, 2015 12:53 pm

Re: Can't get Python RPi.GPIO to work on Pi 2

Wed May 06, 2015 3:09 pm

Posting in here, since this is one of the first threads I found, but it did not help me solve my problem.

When doing initial setup using raspi-config, many tutorials show Disabling Device Tree. There is a bug in PRi.GPIO with Pi 2 when device tree is disabled. Once I enables device tree, my PRi.GPIO worked again.

cheesum.kong
Posts: 1
Joined: Tue Dec 29, 2015 3:49 pm

Re: Can't get Python RPi.GPIO to work on Pi 2

Tue Dec 29, 2015 3:50 pm

i get the opposite solution . only disable the device tree the GPIO is working . both BCM mode and BOARD mode

Return to “Troubleshooting”