I've installed Ubuntu on my Raspberry Pi 2.

I'm trying to run a script (mostly copied)

#!/usr/bin/env python
import RPi.GPIO as GPIO

print("Test 1")


ledPin = 32 # GPIO12
Sensor = 18 # GPIO24

print("Test 1a")

print("Test 1b")

print("Test 2")

while True:
  print("Test 3")


But for some reason it stops after Test 1 (and defining ledPin and Sensor)
It just isn't executing the GPIO.setup() But when I remove the GPIO.setup, it does give a runtimewarning for GPIO.output, sayung the channel isn't defined.

I'm running RPi.GPIO version 0.5.11

EDIT: as requested the output:

ubuntu@ubuntu:~$ ls -l /sys/class/gpio
total 0
--w------- 1 root root 4096 Jan  1  1970 export
lrwxrwxrwx 1 root root    0 Jan  1  1970 gpiochip0 -> ../../device/virtual/gpio/gpiochip0
--w------- 1 root root 4096 Jan  1  1970 unexport

EDIT: The following works from shell:

ubuntu@ubuntu:~$ sudo sh -c "echo out > /sys/class/gpio/gpio20/direction"
ubuntu@ubuntu:~$ sudo sh -c "echo 1 > /sys/class/gpio/gpio20/value"
ubuntu@ubuntu:~$ sudo sh -c "echo 0 > /sys/class/gpio/gpio20/value"

yet only on GPIO20. other GPIO's it says:

sh: 1: cannot create /sys/class/gpio/gpio24/direction: Directory nonexistent
  • 1
    I'm afraid it's likely to be a fault in the Ubuntu set up. It may be something to do with the difference between GPIO permissions on Raspbian and Ubuntu. Could you edit your quaetion and add the output from ls -l /sys/class/gpio ? – joan Sep 21 '15 at 11:34
  • and yes i have changed the time ;-) right now. – TD_Nijboer Sep 21 '15 at 11:44
  • The permissions are different. On the Foundation images (e.g. Raspbian) the GPIOs are root/gpio (i.e. owner root, group gpio) and the standard (pi) user is in group gpio. Your question is really how can I access the Raspberry Pi gpios when using Ubuntu. I'm sure you can, I don't know how though. Perhaps google with that question in mind. – joan Sep 21 '15 at 12:00
  • Thanks @joan for the input / direction. if anyone else has an suggestion please feel free. Couldn't i just reset the permission on that file. – TD_Nijboer Sep 21 '15 at 12:06
  • I'm sure if anyone knows the answer they will respond. I think there is more to it than permissions. Directories under /sys/class/gpio may have been moved. – joan Sep 21 '15 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.