在 Raspberry Pi 上使用 RPi.GPIO 设置时获取 "Segmentation Fault" 2

Getting "Segmentation Fault" when using RPi.GPIO setup on Raspberry Pi 2

我在使用 gpio.setup(pin, GPIO.OUT)

时遇到错误

我目前正在使用 Ubuntu Mate For Raspberry Pi 2 并使用 Python 2.7 和 python-rpi.gpio 0.5.10.1 模块。

当我尝试输入 GPIO.setup(pin, GPIO.OUT) 时抛出 SegmentationFault

编辑:这是我一直在处理的代码

# Program Menampilkan seven segment


import RPi.GPIO as GPIO
import time

# Atur mode GPIO menjadi nomor pin
GPIO.setmode(GPIO.BOARD)
# Atur pin ke segment 7segment
sega = 29
segb = 31
segc = 32
segd = 33
sege = 35
segf = 36
segg = 37
#Atur GPIO
GPIO.setup(sega, GPIO.OUT)
GPIO.setup(segb, GPIO.OUT)
GPIO.setup(segc, GPIO.OUT)
GPIO.setup(segd, GPIO.OUT)
GPIO.setup(sege, GPIO.OUT)
GPIO.setup(segf, GPIO.OUT)
GPIO.setup(segg, GPIO.OUT)

#Definisikan angka 7 segment 0 sampai 9
def nol(): # segment a, b, f, e, c, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(sege, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(sege, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

def satu(): # segment b, c hidup
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    time.sleep(1)
    return

def dua(): # segment a, b, g, e, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(sege, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(sege, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

def tiga(): # segment a, b, g, c, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

def empat(): # segment f, b, g, c hidup
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    time.sleep(1)
    return

def lima(): # segment a, f, g, c, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

def enam(): # segment a, f, g, c, e, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(sege, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(sege, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

def tujuh(): # segment a, b, c hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    time.sleep(1)
    return

def delapan(): # segment a, b, c, d, e, f, g hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    GPIO.output(sege, GPIO.HIGH)
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    GPIO.output(sege, GPIO.LOW)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    time.sleep(1)
    return

def sembilan(): # segment a, b, f, g, c, d hidup
    GPIO.output(sega, GPIO.HIGH)
    GPIO.output(segb, GPIO.HIGH)
    GPIO.output(segf, GPIO.HIGH)
    GPIO.output(segg, GPIO.HIGH)
    GPIO.output(segc, GPIO.HIGH)
    GPIO.output(segd, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(sega, GPIO.LOW)
    GPIO.output(segb, GPIO.LOW)
    GPIO.output(segf, GPIO.LOW)
    GPIO.output(segg, GPIO.LOW)
    GPIO.output(segc, GPIO.LOW)
    GPIO.output(segd, GPIO.LOW)
    time.sleep(1)
    return

for i in range (0, 5): # Tampilkan angka 1 sampai 9 x5
    satu()
    dua()
    tiga()
    empat()
    lima()
    enam()
    tujuh()
    delapan()
    sembilan()

GPIO.cleanup()

我不知道这个问题,我认为这是 python-rpi.gpio 模块相关的,因为我对 Raspbian 和 python 没有任何问题-rpi.gpio 预装。

我有同样的症状,Raspberry Pi 2 与 Ubuntu Mate,0.5.11 模块。我的代码更简单:

import time
import RPi.GPIO as GPIO
print "before GPIO.setmode"
GPIO.setmode(GPIO.BOARD)
print "before GPIO.setup"
GPIO.setup(11, GPIO.IN)
print "after GPIO.setup"

它在 GPIO.setup 期间出现段错误。我会尝试切换回 Raspbian,看看是否可行。如果是这样,也许可以从那里的源代码卸载并重新安装 RPi.GPIO。