6

I was trying to run a motor using the Pi. It was working fine before when I was executing using a Python script.

Later I installed WiringPi and tried to execute the GPIO using shell script and it worked once.

After that nothing was working, neither the python scripts nor the shell scripts.

In the Python scripts I had added GPIO.cleanup() but still no use. But when I am executing the python script, I am getting the following warning message:

RuntimeWarning: This channel already in use, continuing anyway

Is there any way to reset the GPIO to its normal state again?

Also I had tried adding try and final statements in my Python script but still no use.

user1133275
  • 2,216
  • 16
  • 32
Rocky
  • 61
  • 1
  • 1
  • 2

2 Answers2

4

I found the completed solution for your issue: RPi.GPIO basics 3 – How to Exit GPIO programs cleanly, avoid warnings and protect your Pi

I see this is the best way to other answers.

Basically you have to call cleanup.

import RPi.GPIO as GPIO 
# do stuff …
# … left blank for the reader to fill in …
# … then perform a clean exit:
GPIO.cleanup()
flowtron
  • 101
  • 4
Thinh Phan
  • 101
  • 3
3

It is a warning only and may safely be ignored.

The warning is telling you that another program told Linux it wanted to use that gpio. It's all to do with Linux "exporting" the gpio to be visible to a user, so an ordinary user can read and write the gpio. The external program should have "unexported" the gpio when it was finished.

The warning should not prevent you from reading and writing to gpios.

joan
  • 71,852
  • 5
  • 76
  • 108