I'm getting an error when I use gpio.setup(pin, GPIO.OUT)

I'm currently using Ubuntu Mate For Raspberry Pi 2 and using Python 2.7 with python-rpi.gpio 0.5.10.1 module.

It throws SegmentationFault when I try to input GPIO.setup(pin, GPIO.OUT).

EDIT: this is my code that i've been working on

# 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()

I don't know the problem, i thought it was python-rpi.gpio module related as i don't have any problem with Raspbian with python-rpi.gpio pre installed.

share|improve this question
up vote -1 down vote accepted

I am having the same symptom, Raspberry Pi 2 with Ubuntu Mate, 0.5.11 module. My code is much simpler:

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"

It segfaults during GPIO.setup. I'll try switching back to Raspbian and see if that works. And if so, maybe uninstall and reinstall RPi.GPIO from source there.

share|improve this answer
    
Yes, it was python-rpi.gpio related problem as i dont have any problem with raspbian. I recommend switch to raspbian if you want coding gpio. – xdhe Jun 1 '15 at 5:10
2  
It worked with raspbian. The reason for the segfault is that the Ubuntu kernel was built with CONFIG_STRICT_DEVMEM set true. It was unset in the raspbian kernel. (It is a setting under Kernel Hacking) No problem, I thought. I'll just build a new kernel with it unset. That turned out to be more of a task than expected. 3.19 kernel builds didn't boot. I finally found the source for the Ubuntu kernel at launchpad.net/~fo0bar/+archive/ubuntu/rpi2/+sourcepub/509356‌​9/… and, after much tinkering got a new build with CONFIG_STRICT_DEVMEM unset. It works now. – jwaugh Jun 7 '15 at 14:55
    
i'm gonna check if the problem solve now. You might edit your answer tho, so if i found the problem gone, i will choose your answer :) – xdhe Jun 7 '15 at 16:01
1  
The segfault went away and my C program worked. RPi.GPIO defines BCM2708_PERI_BASE_DEFAULT to 0x20000000 (Pi 1) instead of 0x3f000000 (Pi 2). It tries to adjust it reading /proc/device-tree/soc/ranges but this kernel didn't have device tree enabled. A raspbian kernel that I had built had mkknlimg in the scripts directory, which I borrowed and used to add a 'magic number' the end of the kernel image and that solved that problem. Like I said earlier, a lot of tinkering. Probably not worth the trouble as it will all vanish if 'apt-get update' fetches me a new kernel. ;-( – jwaugh Jun 10 '15 at 23:13
    
So you just think its possible to fix that and its not worth as the Ubuntu will be updating kernel when triggering by apt-get upgrade? Well i see, so lets just say that Ubuntu mate not worth to be used for GPIO programming then? Then i just stick with another micro sd card and make it to raspbian :-) Anyway thanks for letting me know! – xdhe Jun 13 '15 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.