If I try to run this or any other script they fail with the GPIO busy error. I can kill the task manually and then tasks will run again. However I assume this is not the correct behaviour.
The scripts make a call to my_dog(close) at the end could this be failing in some way?
The script terminates cleanly and returns to the prompt. However, if I abort the task before it completes then the process is removed from memory!!
Thank you in advance.
(P.S. This is running remotely from ssh or a shell prompt on the RPI. RPI V4.
That’s the normal behaviour, albeit probably unexpected!
You’re running into a hard boundary between OS-managed resources and external hardware state. A ctrl-c, such as early program termination or interrupting an Infinite loop frees the mcu resources from the linux core, whereas other exit methods do not.
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 code and it was never meant to return.
So, in summary, what you see is normal. The other examples that run infinitely, will need ctrl-c to terminate anyway and this then automatically frees resources. They are absolutely fine.
I tried to explain the options a bit better here via 3 different worked example scenarios
Please note the above is my own interpretation and probably over simplified version of the process via a bit of reverse engineering, not confirmed in any way by Sunfounder, please feel free to ignore! I could be totally wrong.
Thank you for your reply. To explain, I have only just finished construction so currentlly don’t know what is normal and what isn’t.
What you say is certainly the same as I am experiencing.
At least two of the test scripts do not exhibit this behaviour - rgb_strip_test.py and imu_test.py These do not leave a process running and in fact run even if another task has been left running. I had assumed that these also involved the GPIO but they daisy chain off the I2C which must be independent of GPIO.
I had also assumed that even though this kit is probably not aimed at a complete beginner that the instructions would cover how to deal with the GPIO error when running scripts in the instructions. I have experience of electronics and Linux, so was able as you were to work out what to do but many people may not. Early days yet but I’m guessing it isn’t in the Sunfounder instructions and I have to admit to not fully watching/reading every bit of the insructions.