Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"This channel is already in use" error #1

Open
henrykim1004 opened this issue Jun 22, 2021 · 5 comments
Open

"This channel is already in use" error #1

henrykim1004 opened this issue Jun 22, 2021 · 5 comments

Comments

@henrykim1004
Copy link

henrykim1004 commented Jun 22, 2021

I have tried to use soft PWM for control of dual motor controller for speed changes.
Following code is almost identical to the one that I have used for Orange Pi Zero with no problem.
It is differ only the pin numbers to match with Orange Pi Zero 2.
When I tried to use the pins, error message came out as "Pin# is reserved".
However, if I manually set the pin as output once using "gpio mode wPI# out" for 4 pints, then this code runs without an error.
I guess, it is missing initialization step somewhere.

softPWM_Zero2

#!/usr/bin/env python

-- coding: utf-8 --

Original Base Demo File : pwm_dutycycle.py

import OPi.GPIO as GPIO
from time import sleep

GPIO.setboard(GPIO.H616) # It is for Orange Pi Zero 2 board
GPIO.setmode(GPIO.BOARD) # set up BOARD BCM numbering

GPIO.setup(7, GPIO.OUT) # set Motor A : right wheel forward
GPIO.setup(19, GPIO.OUT) # set Motor A : right wheel backward
GPIO.setup(15, GPIO.OUT) # set Motor B : left wheel forward
GPIO.setup(21, GPIO.OUT) # set Motor B : left wheel backward

rwf = GPIO.PWM(7, 10) # new PWM on 7 freq.=30Hz
rwb = GPIO.PWM(19, 10) # new PWM on 19 freq.=30Hz
lwf = GPIO.PWM(15, 10) # new PWM on 15 freq.=30Hz
lwb = GPIO.PWM(21, 10) # new PWM on 21 freq.=30Hz

def stop_motors() :
rwf.start(0)
rwb.start(0)
lwf.start(0)
lwb.start(0)

try:
stop_motors()
while 1:
for dc in range(0, 101, 5):
rwf.ChangeDutyCycle(dc)
lwf.ChangeDutyCycle(dc)
sleep(0.1)
stop_motors()
sleep(1)
for dc in range(0, 101, 5):
rwb.ChangeDutyCycle(dc)
lwb.ChangeDutyCycle(dc)
sleep(0.1)
stop_motors()
sleep(1)

except KeyboardInterrupt:
pass

rwf.stop()
rwb.stop()
lwf.stop()
lwb.stop()

GPIO.cleanup()

@eutim
Copy link
Owner

eutim commented Jun 22, 2021 via email

@henrykim1004
Copy link
Author

For the school project, you have done a great work! You have made people's life much easier. Thank you for your great work and kind mind to share for everyone.
pin_problem

@henrykim1004
Copy link
Author

henrykim1004 commented Jun 22, 2021

Once manual initialization in shell as
gpio mode 2 out
gpio mode 11 out
gpio mode 8 out
gpio mode 12 out
then, same code runs without error message.

output1.mp4

@eutim
Copy link
Owner

eutim commented Jun 22, 2021

The error comes from a safety check in py_gpio.c on line 220 to 229, you
can either comment this out or delete it.

There is a function in boards.c called gpio_function_name which, as the
name implies, tells which GPIO pin has which function.
you can manually set the pin you want to use to an output pin by saying
that the pin has function "1".
So for example, case 231 : str = 1; break;
Where 231 is GPIO pin 19, and str = 1 is output.

Keep in mind you might have to reinstall the library for these changes to take effect.

Please let me know if this helped :)
I will work out the bug once I have some free time, sorry for the
inconvenience.
image
image
image

@eutim eutim reopened this Jun 22, 2021
@henrykim1004
Copy link
Author

Thank you very much!
Do you know that your library is the ONLY library that provide gpio control with Python for Orange Pi Zero 2 and Lite 2?
You are a great man!

@eutim eutim changed the title When I tried to use the pins, error message came out as "Pin# is reserved". "This channel is already in use" error Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants