Iggster
Posts: 7
Joined: Thu Aug 01, 2013 5:41 am
Location: New Zealand

GPIO error, channel in use.

Thu Aug 01, 2013 5:55 am

Hello.

I am trying to do this project:
http://learn.adafruit.com/adafruits-ras ... s/overview

The project uses a breadboard, pi cobbler, L293D chip which all power a 5v 512 step stepper motor.

It uses the following code to control it:
  • import RPi.GPIO as GPIO
    import time

    GPIO.setmode(GPIO.BCM)

    enable_pin = 18
    coil_A_1_pin = 4
    coil_A_2_pin = 17
    coil_B_1_pin = 23
    coil_B_2_pin = 24

    GPIO.setup(enable_pin, GPIO.OUT)
    GPIO.setup(coil_A_1_pin, GPIO.OUT)
    GPIO.setup(coil_A_2_pin, GPIO.OUT)
    GPIO.setup(coil_B_1_pin, GPIO.OUT)
    GPIO.setup(coil_B_2_pin, GPIO.OUT)

    GPIO.output(enable_pin, 1)

    def forward(delay, steps):
    for i in range(0, steps):
    setStep(1, 0, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(1, 0, 0, 1)
    time.sleep(delay)

    def backwards(delay, steps):
    for i in range(0, steps):
    setStep(1, 0, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(1, 0, 1, 0)
    time.sleep(delay)


    def setStep(w1, w2, w3, w4):
    GPIO.output(coil_A_1_pin, w1)
    GPIO.output(coil_A_2_pin, w2)
    GPIO.output(coil_B_1_pin, w3)
    GPIO.output(coil_B_2_pin, w4)

    while True:
    delay = raw_input("Delay between steps (milliseconds)?")
    steps = raw_input("How many steps forward? ")
    forward(int(delay) / 1000.0, int(steps))
    steps = raw_input("How many steps backwards? ")
    backwards(int(delay) / 1000.0, int(steps))
When I try to run it in terminal using 'sudo python stepper.py' the following error occurs and then the actual words that should appear do appear, but just don't do anything.
"stepper.py:12: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(coil_A_1_pin, GPIO.OUT)"
And then repeats the same warning just changing the 12 at the beginning to 13, 14, 15 and 16, then the stuff that should appear does appear.

Help!

Also if the ribbon cable isn't properly on the GPIO pins it runs without the errors. Once plugged in all the errors occur.

Thank you,

Iggy.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: GPIO error, channel in use.

Thu Aug 01, 2013 7:08 am

It's not an error, it's a warning, and the text of the message tells you what to do if you don't want to see these warnings.
Use GPIO.setwarnings(False) to disable warnings.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

keybeeper
Posts: 26
Joined: Wed Aug 08, 2012 10:15 am

Re: GPIO error, channel in use.

Thu Aug 01, 2013 8:05 am

From

http://code.google.com/p/raspberry-gpio ... BasicUsage

At the end any program, it is good practice to clean up any resources you might have used. This is no different with RPi.GPIO. By returning all channels you have used back to inputs, you can avoid accidental damage to your RPi by shorting out the pins. Note that this will only clean up GPIO channels that your script has used.

To clean up at the end of your script:

GPIO.cleanup()
No Microsoft products were used in the creation of this message

Iggster
Posts: 7
Joined: Thu Aug 01, 2013 5:41 am
Location: New Zealand

Re: GPIO error, channel in use.

Thu Aug 01, 2013 8:03 pm

DeeJay wrote:It's not an error, it's a warning, and the text of the message tells you what to do if you don't want to see these warnings.
Use GPIO.setwarnings(False) to disable warnings.
Ok. Still the stepper motor isn't working, and that is what the code is supposed to do. Also, what does the warning mean?

Iggster
Posts: 7
Joined: Thu Aug 01, 2013 5:41 am
Location: New Zealand

Re: GPIO error, channel in use.

Thu Aug 01, 2013 8:07 pm

keybeeper wrote:From

http://code.google.com/p/raspberry-gpio ... BasicUsage

At the end any program, it is good practice to clean up any resources you might have used. This is no different with RPi.GPIO. By returning all channels you have used back to inputs, you can avoid accidental damage to your RPi by shorting out the pins. Note that this will only clean up GPIO channels that your script has used.

To clean up at the end of your script:

GPIO.cleanup()
Thanks for that page. I found it quite helpful considering I'm no genius. I will try that at the end of the script.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: GPIO error, channel in use.

Thu Aug 01, 2013 8:38 pm

Iggster wrote:Still the stepper motor isn't working, and that is what the code is supposed to do.
I'd suggest 3 things to look at.

1. put some 'print' statements in the code to trace it as it executes, so you have an idea what it is doing;

2. check, and re-check, the wiring between the RPi and the breadboard, on the breadboard, and the connections to the motor;

3. if you are powering this directly from the RPi, have you noted the warning about needing a beefy enough power supply?

If none of that works, my 4th step would be to add some LEDs to the breadboard as electronic 'print statements' to monitor whether the GPIOs are turning on and off as you expect.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Return to “Beginners”