我在使用gpio.setup(pin, GPIO.OUT)
我目前正在使用Ubuntu Mate For Raspberry Pi 2并使用带有python-rpi.gpio 0.5.10.1
模块的Python 2.7。
当我尝试输入SegmentationFault
时,它会抛出GPIO.setup(pin, GPIO.OUT)
。
编辑:这是我一直在努力的代码
# 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模块相关的,因为我没有预先安装python-rpi.gpio的Raspbian有任何问题。
答案 0 :(得分:-1)
我有相同的症状,Raspberry Pi 2和Ubuntu Mate,0.5.11模块。我的代码更简单:
char[]
在GPIO.setup期间出现段错误。我会尝试切换回Raspbian,看看是否有效。如果是这样,也许可以从源代码卸载并重新安装RPi.GPIO。