2

I'm trying to get a simple LED script running as a first example of how to access and use the gpio pins.

import time
import RPi.GPIO as GPIO

print("Start")
gpioPin = 37

GPIO.setmode(GPIO.BCM)
print("Step 1")
GPIO.setup(gpioPin, GPIO.OUT)  # Script crashes here
print("Step 2")
GPIO.output(gpioPin, GPIO.HIGH)
print("Step 3")
time.sleep(10)
GPIO.output(gpioPin, GPIO.LOW)
print("Step 4")
GPIO.cleanup()
print("End")

But the whole system gets unresponsive after GPIO.setup(gpioPin, GPIO.OUT). The output I get is

Start

Step 1

after that, I can't do anything except pull the power cable and reboot the pi. The system is unresponsive. Access through ssh doesn't work anymore. Even ping responses don't work anymore after GPIO.setup().

I'm running Raspbian Jessie on a RPi 3 Model B with Python 3.4.

The problem is similar to RPi.GPIO mysteriously crashing when setting up pin except that I am not using ubuntu. I'm using the lastest raspberry pi image of rabian.

What can I do to prevent this? What is the problem here? Any idea?

2

You can avoid the problem quite simply. Don't try to manipulate the GPIO reserved by the system.

On the Pis with a 40 pin expansion header only use GPIO 0-27.

Early Pis allowed some access to 28-31.

I guess you meant to use the GPIO attached to expansion header pin 37 (GPIO26). To do so use BOARD numbering not BCM numbering. Use GPIO.setmode(GPIO.BOARD).

See https://pinout.xyz/

  • Thanks! That totally solved the problem, the script now runs fine. But isn't the setmode(GPIO.BCM) exactly for that purpose to use the physical numbering? I'm confused now when to use BOARD or BCM.. – Jack O'neill Mar 7 '17 at 12:21
  • It's down to personal choice. GPIO.BCM says you will reference GPIO by their Broadcom mumber. So 26 means GPIO26 (connected to pin 37). GPIO.BOARD says you will reference GPIO by the number of the pin they are attached to on the expansion header so 26 means pin 26 which happens to be connected to GPIO7. It is a common error to use the wrong numbering system. You need to be careful. Personally I exclusively use the GPIO (Broadcom) numbers in my code. – joan Mar 7 '17 at 12:31
  • Thank you. I mixed it up completely. I had 3 LEDs connected to pins 37,38, 40 (those on the bottom of your pinout guide) and used the bcm mode. They are working now with BCM when I use 20, 21 and 26. – Jack O'neill Mar 7 '17 at 12:51

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.