If I close a program as examples of PiDog [ eg: Pidog.close() ] I have PiDog blocked and I cannot run another script.
I must turn off my Dog and then I can start again.
Some suggestion? Thank you!
If I close a program as examples of PiDog [ eg: Pidog.close() ] I have PiDog blocked and I cannot run another script.
I must turn off my Dog and then I can start again.
Some suggestion? Thank you!
I had the same problem with some of the provided examples. I believe the gpio pins are not being released properly. GPIO.cleanup() should be run at the end of the script.
I tried to explain this to my best understanding here, and gave 3 alternatives. Hopefully its clear!
As far as I could ever determine, dog.close() is not a cleanup method, it is a terminal control-flow primitive, it assumes it is called from top-level (parent) code and it was never meant to return.
Some users encountered the same issue and resolved it by reinstalling the system, then following the tutorial steps to install all code again.
An important prerequisite is not to run the command
sudo apt install git python3-pip python3-setuptools python3-smbus,
as this instruction is specifically intended for the Lite system and is not needed for the desktop operating system.
You may try the following to see if it resolves the issue:
Please proceed to install the source code by following the steps in our online tutorial:
https://docs.sunfounder.com/projects/pidog/en/latest/python/python_start/install_all_modules.html#install-all-the-modules-important
Remember not to execute the following command:
sudo apt install git python3-pip python3-setuptools python3-smbus
Instead, directly install the robot-hat, vilib, and pidog library code.
If any errors occur during installation, please provide us with the complete error messages so we can help analyze and resolve the issue.
Once all library codes are successfully installed, try running the example scripts again to see how it works.
Thank you. I’ll try and I tell you.
Best regards.
Luigi
Good afternoon.
I have tried, but per issue remains.
I attach the program, copied from your page, and the error that I find when I execute the program for the second time.
I must turn off Pidog and then it works, for once!
Thanks for your suggestions.
Best regards.
Luigi Federici
(Attachment programma.pdf is missing)
(Attachment Errore.pdf is missing)
Good afternoon.
I have tried, but per issue remains.
I attach the program, copied from your page, and the error that I find when I execute the program for the second time.
I must turn off Pidog and then it works, for once!
Thanks for your suggestions.
Best regards.
Luigi Federici
P.S. I cannot attach my pdf or jpg file, so I copy them:
Program:
‘’’ play sound effecfs
Note that you need to run with “sudo”
API:
Pidog.speak(name, volume=100)
play sound effecf in the file “../sounds”
name str, file name of sound effect, no suffix required, eg: “angry”
volume int, volume 0-100, default 100
‘’’
from pidog import Pidog
import os
import time
abspath = os.path.abspath(os.path.dirname(file))
os.chdir(abspath)
my_dog = Pidog()
print(“\033[033mNote that you need to run with "sudo", otherwise there may be no sound.\033[m”)
for name in os.listdir(‘../sounds’):
name = name.split(‘.’)[0] # rimuovi il suffisso
print(name)
my_dog.speak(name)
time.sleep(3) # Nota: la durata di ogni effetto sonoro è diversa
print(“closing …”)
my_dog.close()
Error:
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 411, in pin
pin = self.pins**[info]**
**KeyError**: PinInfo(number=29, name='GPIO5', names=frozenset({'J8:29', 'GPIO5', 'BOARD29', 'BCM5', 'WPI21', '5', 5}), pull='', row=15, col=1, interfaces=frozenset({'', 'gpio', 'dpi', 'uart', 'i2c', 'spi'}))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/luigi_fe/prog/prova_9.py", line 10, in <module>
my_dog = Pidog()
File "/usr/local/lib/python3.13/dist-packages/pidog/pidog.py", line 131, in __init__
utils.reset_mcu**()**
~~~~~~~~~~~~~~~**^^**
File "/usr/local/lib/python3.13/dist-packages/robot_hat/utils.py", line 155, in reset_mcu
pin = Pin("MCURST")
File "/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py", line 96, in __init__
self.setup**(mode, pull, active_state)**
~~~~~~~~~~**^^^^^^^^^^^^^^^^^^^^^^^^^^**
File "/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py", line 134, in setup
self.gpio = OutputDevice**(self._pin_num)**
~~~~~~~~~~~~**^^^^^^^^^^^^^^^**
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 108, in __call__
self = super().__call__(*args, **kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", line 74, in __init__
super().__init__**(pin, pin_factory=pin_factory)**
~~~~~~~~~~~~~~~~**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^**
File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 75, in __init__
super().__init____(*args, **kwargs)__
~~~~~~~~~~~~~~~~**^^^^^^^^^^^^^^^^^**
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 553, in __init__
pin = self.pin_factory.pin(pin)
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 413, in pin
pin = self.pin_class(self, info)
File "/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py", line 126, in __init__
lgpio.gpio_claim_input**(**
~~~~~~~~~~~~~~~~~~~~~~**^**
**self.factory._handle, self._number, lgpio.SET_PULL_NONE)**
**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^**
File "/usr/lib/python3/dist-packages/lgpio.py", line 755, in gpio_claim_input
return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))
File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i
raise error(error_text(v))
**lgpio.error**: 'GPIO busy'
Please contact our official email at service@sunfounder.com and provide us with the code you are running along with the complete error message. This will help us analyze and resolve the issue for you.
Please note: Do not run two or more code scripts simultaneously, as this will cause GPIO pin conflicts.
The code you are running is your own, correct?
When you run our project code script, can you stop it normally by pressing Ctrl+C, without having to execute the script a second or multiple times?
If you are running your own code, we suspect there may be an issue with the code itself.