GPIO control - need some help

Hi there, this is my first post on here, though I did a bit over at RaspBMC.

One of the things I figured out there was having an LED attached to a GPIO pin. To get this to work I had to make a few changes:

apt-get update
apt-get install -y python-dev
apt-get install -y python-pip
easy_install -b /home/osmc -U distribute
pip install rpi.gpio

I’ve tried to do the same on OSMC, but get an error when installing the last item (pip install rpi.gpio)

error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-2hxNQg/rpi.gpio/';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-C0tZLZ-record/install-record.txt --single-version-externally-managed --compile:

Can someone point e in the right direction, or tell me how else I can control the GPIO pins?

Are you running all those commands as root including the pip command ? BTW when I needed to install PIP to use a Python debugger I didn’t install it via APT package, I just did:

sudo python

See the following page:

1 Like

Hi, and thanks for helping.

Yes, I set a root password and use that to set everything up.

PIP installed fine (I did re-install using your instructions, which also worked fine). My knowledge level is very low with linux, most of what I have done I have learnt from other forum posts, so I am not sure I even need all of the things I am doing - I just know that they worked fine is Raspbmc.

Moving to OSMC has meant changing a lot of my backed up files so that paths point to the right place. I now have everything else working except this. I appreciate this is not something most people would mess around with, but would really like to have everything working as before.

It seems like

pip install rpi.gpio

may be slightly naive on the maintainer’s part as it attempts to invoke a cross compiler. Try running the following commands before that pip install command:

sudo apt-get update
sudo apt-get install build-essential
export ARCH=arm
export CROSS_COMPILE=/usr/bin/

I don’t know if this will work – i have not looked intensively at the rpi.gpio script, but hope this helps.



Thanks Sam, that has done the trick for me, now I can look into my next little project!

update to 09-2016
I installed OSMC build 2016-08
and these instructions not work.

I had to manually download rpi.gpio from the python repository website
browse to RPi.GPIO · PyPI
and download from there

unzip it

sudo apt-get update
sudo apt-get install gcc python-dev

cd rpi.gpio
sudo python install

Install RPi.GPIO via pip
(OSMC 2016.08-1)

$ sudo su
# apt-get update
# apt-get install python-pip python-dev gcc
# pip install rpi.gpio

(may showed some warnings but will successfully installed)

i got it installed, but i always have to run the script with sudo.
is there a way to get access rights?
i’d like to write a kodi addon for rotary encoders.

Is my request to simple or is there no solution to get access?

Does /dev/gpiomem exist ?

What are its permissions ?

I really would like the answer to this as well. Im pulling my hair out trying to write an addon for GPIO pushbuttons.

For me, I have to create another script with sudo command to run the script.


# cannot run sudo by itself

import os
os.system('/usr/bin/sudo /home/osmc/')

Some codes here might be useful: OSMC_GPIO

i got it with the udev.rules. on sunday i can post my solution.

SUBSYSTEM==“bcm2835-gpiomem”, KERNEL==“gpiomem”, GROUP=“gpio”, MODE=“0660”
SUBSYSTEM==“gpio”, KERNEL==“gpiochip*”, ACTION==“add”, PROGRAM="/bin/sh -c ‘chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport’"
SUBSYSTEM==“gpio”, KERNEL==“gpio*”, ACTION==“add”, PROGRAM="/bin/sh -c ‘chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value’"