SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP error

Thu Jun 11, 2015 9:00 pm

My Build: Raspberry Pi 2 Model B ( 1 GB RAM )
Installed Ubuntu 14.04 following the instructions here - https://wiki.ubuntu.com/ARM/RaspberryPi - with the exception of the video-fbturbo or xubuntu-desktop, it's a headless machine.

I installed the raspberry-gpio-python module 0.5.11 from - http://sourceforge.net/projects/raspberry-gpio-python/

I am able to import RPi.GPIO as GPIO in python, but when I use the GPIO.setup( 4, GPIO.OUT) command, python dies with no error message.

I use sudo to run my python program, so it should not be a privilege issue. Maybe there is no way to use RPi.GPIO in Ubuntu 14.04 LTS? If not, would (Virtual GPIO) http://virtgpio.blavery.com/vgpio/ work as a replacement for RPi.GPIO?

This guy has the same problem, but no-one has answered it:
http://askubuntu.com/questions/630877/p ... 7-gpio-out

Thanks for your help.


SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 5:22 am

ktb wrote:Check this page: viewtopic.php?f=56&t=100553&start=150
I'm not sure what to take away from that.

To me it looks like they are just talking about uninstalling the Ubuntu 14.04 build I have and installing a user created version?
I have no idea what a device tree trailer is, and they aren't very specific about any steps to fix the issue.

If anyone else has the same issue I do, I found this:
https://github.com/derekstavis/python-sysfs-gpio

It's not an actual fix, but it works nicely, at least on basic on / off / read functionality. :)

Please let me know what I probably missed in that post you linked.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 7:06 am

To being with, that forum thread page I linked is devoted to the same version of Ubuntu you are supposedly using right now. If you need more proof, check the "raspberrypi.org forums thread" link at the bottom of the page which you linked -- https://wiki.ubuntu.com/ARM/RaspberryPi.

RPi.GPIO will not work with a kernel that doesn't have Device Tree support (or doesn't declare that it has Device Tree support by having the Device Tree trailer present) or if Device Tree support has been disabled in config.txt (by having "device_tree="). Last time I checked, the kernel for this version of Ubuntu does not have the Device Tree trailer. However, you can add it to the kernel fairly easily.

If you followed the following instructions from the Ubuntu wiki page, then you have the Raspberry Pi userland files installed which includes a tool called vcdbg.
As with Raspbian, VideoCore packages are available:

$ sudo apt-get install libraspberrypi-bin libraspberrypi-dev

However, since these packages are compiled from source during build, the files are installed in their "proper" locations in /usr. Some third-party scripts may expect e.g. /opt/vc/bin/vcgencmd; if so, this hack should do it:

$ sudo ln -s /usr /opt/vc

(Raspbian packages use precompiled repositories during build, which install in /opt/vc.) vcdbg and edidparser are not part of the open source package and must be installed separately:

$ sudo apt-get install libraspberrypi-bin-nonfree
Use the vcdbg tool to confirm that the Device Tree trailer is present or not.
- First, add dtdebug=on to a line in your config.txt file.
- Second, reboot your Pi2B
- Third, run the command sudo vcdbg log msg from a terminal
- Fourth, post the output here so we can look at it or just tell us whether or not there is a line within the output from that command which includes "Kernel trailer DTOK property says yes."

Here is an excerpt of what the output looks like on Raspbian:

Code: Select all

001118.756: Loading 'kernel7.img' from SD card
001351.164: Kernel trailer DTOK property says yes
001351.294: Loading 'bcm2709-rpi-2-b.dtb' from SD card
001378.061: dtparam: i2c_arm=on
001388.226: Loaded overlay 'lirc-rpi'
001412.347: dtparam: gpio_in_pin=18
001413.388: dtparam: gpio_in_pull=down
001421.747: Loaded overlay 'i2c-rtc'
001449.987: dtparam: ds1307=true
001452.809: dtparam: arm_freq=1000000000

If the Device Tree trailer is not present, then we can move on to adding it to the current kernel you have:

I don't have Ubuntu installed on any microSD cards at the moment, so my advice might not be perfect. I'm not actually sure which kernel and initramfs is being used, there appears to be a vmlinuz-3.18.0-20-rpi2 (kernel) and initrd.img-3.18.0-20-rpi2 (initramfs) in the /boot directory of the root file system (partition 2). However, the FAT32 boot partition which gets mounted at /boot/firmware also seems to contain a kernel7.img (kernel) and initrd7.img (initramfs).

Let's say that the kernel file being used is /boot/firmware/kernel7.img. Here is how you could add the Device Tree trailer:

Code: Select all

cd ~
mkdir -p software/build && cd software/build
sudo apt-get install git
git clone git://github.com/raspberrypi/tools.git
sudo ~/software/build/tools/mkimage/mkknlimg /boot/firmware/kernel7.img /boot/firmware/kernel7_dt.img
Then you could add something like the following to config.txt:

Code: Select all

kernel=kernel7_dt.img
Try rebooting your Pi2B and run the sudo vcdbg log msg from a terminal again. That should say which kernel file is being loaded as well as whether the Device Tree trailer is present or not.

User avatar
croston
Posts: 703
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 7:15 am

Or you can simply try the development version of RPi.GPIO where it should be fixed: https://sourceforge.net/p/raspberry-gpi ... i/install/
The Wheezy instructions will probably work for Ubuntu.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 7:32 am

croston wrote:Or you can simply try the development version of RPi.GPIO where it should be fixed: https://sourceforge.net/p/raspberry-gpi ... i/install/
The Wheezy instructions will probably work for Ubuntu.
Cool. Thanks, croston.

Perhaps you can shed some light on a change I seemed to need to make to get RPi.GPIO to build on Alpine Linux -- viewtopic.php?p=764210#p764210
- sudo pip install RPi.GPIO fails with errors related to caddr_t. Update: I was able to install this by downloading and modifying the source for RPi.GPIO 0.5.11 from sourceforge -- http://softlayer-dal.dl.sourceforge.net ... .11.tar.gz:

Code: Select all

--- source_old/c_gpio.c
+++ source/c_gpio.c
@@ -85,7 +85,7 @@
     if ((uint32_t)gpio_mem % PAGE_SIZE)
         gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
 
-    gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, gpio_base);
+    gpio_map = (uint32_t *)mmap( (void *)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, gpio_base);
 
     if ((uint32_t)gpio_map < 0)
         return SETUP_MMAP_FAIL;
@@ -233,5 +233,5 @@
 
 void cleanup(void)
 {
-    munmap((caddr_t)gpio_map, BLOCK_SIZE);
+    munmap((void *)gpio_map, BLOCK_SIZE);
 }
Last edited by ktb on Tue Jun 16, 2015 10:14 am, edited 1 time in total.

User avatar
croston
Posts: 703
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 8:15 am

@ktb - caddr_t compilation problems have never been reported before! Basically caddr_t is deprecated on modern systems. I will include your patch in the next dev release. Watch https://sourceforge.net/p/raspberry-gpi ... ckets/109/ for more updates.

SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Fri Jun 12, 2015 11:46 pm

croston wrote:Or you can simply try the development version of RPi.GPIO where it should be fixed: https://sourceforge.net/p/raspberry-gpi ... i/install/
The Wheezy instructions will probably work for Ubuntu.
This Wheezy instructions on that link didn't work, It couldn't find the packages. I did go here :
http://sourceforge.net/projects/raspber ... an-wheezy/

I downloaded the files directly and installed them, the python one installed, but the python3 one wouldn't work because I have python3.4 and it only works with python3.3 or less. But that's fine, I'd be happy working with the python version, but it still fails at GPIO.SETUP(.

I have tried 100 things, so it's possible by now I have done something that negates this suggestion from working.

ktb, I will try your suggestion later, thanks to both. :)

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:03 am

Did you follow the instructions for installing the development version?
To install the latest development version from the project source code library:

$ sudo apt-get install python-dev python3-dev
$ sudo apt-get install mercurial
$ sudo apt-get install python-pip python3-pip
$ sudo apt-get remove python-rpi.gpio python3-rpi.gpio
$ sudo pip install hg+http://hg.code.sf.net/p/raspberry-gpio- ... g=RPi.GPIO
$ sudo pip-3.2 install hg+http://hg.code.sf.net/p/raspberry-gpio- ... g=RPi.GPIO
The files here -- http://sourceforge.net/projects/raspber ... an-wheezy/ -- are not the development version

http://sourceforge.net/p/raspberry-gpio ... it_browser shows that the version with the fix ([f12260] Correct base address on Pi 2 when devicetree is disabled) is version 0.5.12a1:
http://sourceforge.net/p/raspberry-gpio ... a4d6b2a488

You may need to use some slightly modified steps for the development version install instructions:
- $ sudo apt-get remove python-rpi.gpio python3-rpi.gpio -- may not work if you don't have "python3-rpi.gpio" installed. I'm using Raspbian Jessie and "python3-rpi.gpio" isn't an available package. So try removing the packages one at a time:
$ sudo apt-get remove python-rpi.gpio
$ sudo apt-get remove python3-rpi.gpio

After that, you should be able to confirm whether they are installed or not by using something like these commands:

Code: Select all

[email protected] ~ $ pip search RPi.GPIO
raspi                     - This module provides some helper functions to use with the Raspberry Pi and the RPi.GPIO.
RPIO                      - Advanced GPIO for the Raspberry Pi. Extends RPi.GPIO with PWM, GPIO interrups, TCP socket interrupts, command line tools and more
RPi.GPIO                  - A module to control Raspberry Pi GPIO channels
gpiocrust                 - A pythonic wrapper around RPi.GPIO

Code: Select all

[email protected] ~ $ pip3 search RPi.GPIO
RPi.GPIO                  - A module to control Raspberry Pi GPIO channels
RPIO                      - Advanced GPIO for the Raspberry Pi. Extends RPi.GPIO with PWM, GPIO interrups, TCP socket interrupts, command line tools and more
raspi                     - This module provides some helper functions to use with the Raspberry Pi and the RPi.GPIO.
gpiocrust                 - A pythonic wrapper around RPi.GPIO

If either of those are installed, the output of those commands should mention which version is installed below the listing for the package RPi.GPIO. If there isn't a version number listed in the output for both of those search commands (as in the examples above), then you can mostly be sure that both have been removed or are not currently installed.

Also. you may need to modify the second install command from:
$ sudo pip-3.2 install hg+http://hg.code.sf.net/p/raspberry-gpio- ... g=RPi.GPIO
to:
$ sudo pip3 install hg+http://hg.code.sf.net/p/raspberry-gpio- ... g=RPi.GPIO
Last edited by ktb on Sat Jun 13, 2015 1:30 am, edited 1 time in total.

SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:27 am

Hi, ktb. Yes I followed the instructions, but I couldn't get it to work. I re-ran the instructions and copied the results for each below. Maybe it will help to figure out what I did wrong. I also tried apt-get -f install, but it didn't do anything different.

Code: Select all

$ sudo apt-get install python-dev python3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version.
python3-dev is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 python3-rpi.gpio : Depends: python3 (< 3.3) but 3.4.0-0ubuntu2 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Code: Select all

$ sudo apt-get install mercurial
Reading package lists... Done
Building dependency tree
Reading state information... Done
mercurial is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 python3-rpi.gpio : Depends: python3 (< 3.3) but 3.4.0-0ubuntu2 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Code: Select all

$ sudo apt-get install python-pip python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-pip is already the newest version.
python3-pip is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 python3-rpi.gpio : Depends: python3 (< 3.3) but 3.4.0-0ubuntu2 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Code: Select all

$ sudo apt-get remove python-rpi.gpio python3-rpi.gpio
sudo apt-get remove python-rpi.gpio python3-rpi.gpio
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  python-rpi.gpio python3-rpi.gpio
0 upgraded, 0 newly installed, 2 to remove and 35 not upgraded.
1 not fully installed or removed.
After this operation, 275 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 77113 files and directories currently installed.)
Removing python3-rpi.gpio (0.5.11-1) ...
Removing python-rpi.gpio (0.5.11-1) ...

Code: Select all

$ sudo pip install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
Requirement already satisfied (use --upgrade to upgrade): RPi.GPIO from hg+http://hg.code.sf.net/p/raspberry-gpio-python/code in /usr/local/lib/python2.7/dist-packages

Code: Select all

sudo pip-3.2 install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
sudo: pip-3.2: command not found

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:42 am

Please post the output of the following command:

Code: Select all

ls -la /usr/bin | grep pip
Please post the output of the following commands:

Code: Select all

pip search RPi.GPIO

Code: Select all

apt-cache search gpio
Let's forget about python3-rpi.gpio for now.

SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:47 am

Output of requested commands:

Code: Select all

$ls -la /usr/bin | grep pip
-rwxr-xr-x  1 root root       5564 May 11 19:01 containers_uri_pipe
lrwxrwxrwx  1 root root         13 Jun 10  2013 lessfile -> /bin/lesspipe
lrwxrwxrwx  1 root root         13 Jun 10  2013 lesspipe -> /bin/lesspipe
-rwxr-xr-x  1 root root        281 Mar 26 22:03 pip
-rwxr-xr-x  1 root root        283 Mar 26 22:03 pip2
-rwxr-xr-x  1 root root        284 Mar 26 22:03 pip3

Code: Select all

$ pip search RPI.GPIO
raspi                     - This module provides some helper functions to use with the Raspberry Pi and the RPi.GPIO.
RPIO                      - Advanced GPIO for the Raspberry Pi. Extends RPi.GPIO with PWM, GPIO interrups, TCP socket
                            interrupts, command line tools and more
RPi.GPIO                  - A module to control Raspberry Pi GPIO channels
  INSTALLED: 0.5.11 (latest)
gpiocrust                 - A pythonic wrapper around RPi.GPIO

Code: Select all

$ apt-cache search gpio
ledmon - Enclosure LED Utilities

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:54 am

Alright...

First uninstall RPi.GPIO using pip:

Code: Select all

sudo pip uninstall RPi.GPIO
Then try to install the development version of RPi.GPIO

Code: Select all

sudo pip install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
Then check the version of RPi.GPIO

Code: Select all

pip search RPi.GPIO

SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 1:59 am

kbd,

It works !!! I don't know what I was doing wrong, but now i have 0.5.12a2 installed and it's working great in python.

Thanks so much, cool.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 2:03 am

Next, you can try to do the same thing using pip3 instead of pip:

Check if it's installed first, and if it is remove it:

Code: Select all

pip3 search RPi.GPIO
sudo pip3 uninstall RPi.GPIO
Install the development version using pip3:

Code: Select all

sudo pip3 install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
Check which version is installed using pip3:

Code: Select all

pip3 search RPi.GPIO

SirChuck
Posts: 49
Joined: Thu Jun 11, 2015 8:32 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 2:13 am

Yes the python3 version also works now.

pip3 search shows
RPi.GPIO Installed version 0.5.12.a2

Thanks for making the instructions so clear and easy to follow.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: GPIO with Ubuntu 14.04 LTS on Raspberry Pi GPIO.SETUP er

Sat Jun 13, 2015 2:16 am

You're welcome. Good job.

Return to “Python”