clintschaefer
Posts: 3
Joined: Tue Jul 09, 2013 11:27 pm

IOError: [Errno16] Device or resource busy

Tue Jul 09, 2013 11:57 pm

Probably a supernoob question, but then I am a supernoob to the Pi and Python.

I'm testing out some code from the Raspberry Pi User Guide from page 195, modified so the user can end the script a bit more gracefully.

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

LED_PIN = 18

GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)

loopcontrol = 1

while loopcontrol == 1:
        GPIO.output (LED_PIN, True)
        time.sleep(2)
        GPIO.output (LED_PIN, False)
        loopcontrol = int(raw_input("Press 1 to loop again: "))
And getting the following error:
pi@raspberrypi ~ $ sudo python gpiooutput.py
Traceback (most recent call last):
File "gpiooutput.py", line 9, in <module>
GPIO.setup(LED_PIN, GPIO.OUT)
File "/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.2.0-py2.7.egg/RPi/GPIO/__init__.py", line 103, in setup
f.write(id)
IOError: [Errno 16] Device or resource busy
pi@raspberrypi ~ $

If I change LED_PIN to another number, say 23, and move my circuit appropriately, it runs fine. Any thoughts?

Thanks for the help!

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

Re: IOError: [Errno16] Device or resource busy

Wed Jul 10, 2013 6:13 am

This doesn't answer your question but may solve problems down the line:
Why are you running RPi.GPIO 0.2.0 and not the much more up to date RPi.GPIO 0.5 3a that comes pre-installed in Raspbian? Almost nobody will have the old version and be able to reproduce your problem now. You never know - it might just work with the latest version!

By the way, Eben's book was out-of-date with respect to RPi.GPIO before it was even printed - such is the speed of development of new software.

More up to date information about the RPi.GPIO module can be found here:
http://code.google.com/p/raspberry-gpio ... i/Examples

clintschaefer
Posts: 3
Joined: Tue Jul 09, 2013 11:27 pm

Re: IOError: [Errno16] Device or resource busy

Wed Jul 10, 2013 1:42 pm

Thank you for the help! I will test again tonight. I removed 0.2.0 last night after I posted but not been able to retest. I am hoping gpio.cleanup might solve my issue.

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

Re: IOError: [Errno16] Device or resource busy

Wed Jul 10, 2013 8:05 pm

I don't think that GPIO.cleanup() will make any difference to your problem. Note that it should be put at the end of your script, not the beginning. Lots of examples you will find get this wrong. I don't know who started it but it has been copied and pasted all over the place. Monkey see, monkey do!

clintschaefer
Posts: 3
Joined: Tue Jul 09, 2013 11:27 pm

Re: IOError: [Errno16] Device or resource busy

Wed Jul 10, 2013 11:54 pm

Croston thank you for your replies and help! Removing 0.2.0 was key. I now get runtime warnings that the channel is already in use, but I can work through that.

Return to “Python”