Thanks. you are right on, I am writing my own code and I want to terminate program based on a voice command through vosk.
When the terminate command is detected I exit the while loop in Voice_Command()
if name == “main”:
try:
Voice_Command()
except KeyboardInterrupt:
This block is executed when Ctrl-C is pressed
print(“Script Ctrl-C terminated by user.”)
except Exception as e:
Catches any other potential exceptions
print(f"\033[31mERROR: {e}\033[m")
finally:
This block “always” runs before program terminated
print(“PiDog hardware released.”)
my_dog.close()
When I say the terminate command I get:
Terminate Command Received
PiDog hardware released.
Stopping and returning to the initial position …
Quit
pidog4a@raspberrypi:~/pidog/Bill $
Then I run the program again and it blows up!
pidog4a@raspberrypi:~/pidog/Bill $ sudo python3 PiDog_251207C.py
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({5, 'BCM5', '5', 'WPI21', 'J8:29', 'BOARD29', 'GPIO5'}), pull='', row=15, col=1, interfaces=frozenset({'', 'uart', 'spi', 'i2c', 'gpio', 'dpi'}))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pidog4a/pidog/Bill/PiDog_251207C.py", line 15, in <module>
my_dog = Pidog()
^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pidog/pidog.py", line 131, in __init__
utils.reset_mcu()
File "/usr/local/lib/python3.11/dist-packages/robot_hat/utils.py", line 155, in reset_mcu
pin = Pin("MCURST")
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/robot_hat/pin.py", line 96, in __init__
self.setup(mode, pull, active_state)
File "/usr/local/lib/python3.11/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(
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'