It turns out MicroPython for the Raspberry Pi Pico-W doesn't support threads. Ask me how I know. :)
I'm adding a straight key to Projec TouCans for SKCC straight key month. Getting the straight key to work on its own was pretty straightforward by tweaking and incorporating code that ChatGPT provided.
The next step, after proving the key worked at all, was to get it to play nicely on the Pico-W with the autokeyer code that's already there. The auto-keyer is accessed over WiFi, (TouCans used to be used solely while embedded in a dipole antenna several feet of f the ground.) I asked ChatGPT to write some code for me that would enable me to easily switch back and forth between the straight key and the auto-keyer. The auto-keyer blocks while waiting on a socket access call, that's kind of a problem if you're not using the auto-keyer. ChatGPT's solution was to place the straight ke code and the auto-keyer codes in separate threads. It sounded good, but like I said, I now know that the solution proposed isn't supported in MicroPython.
While ChatGPT didn't give me the correct answer, it did give me code I could run immediately to determine if a threading solution would work, and then, when I asked the AI what was wrong with the code, immediately admitted that, no, threading isn't supported in MicroPython on the Raspberry Pi Pico-W.
Instead of threading, I added a separate real-world input on GPIO14 off the Pico-W. When that input is shorted to ground, the straight key routine is stopped and the auto-keyer is started back up. There are more details below.
The straight key is now up and running! I'll continue to add videos below of the build process as well as the key in action. I've outlined how the design works below.
The New Design
- The Pico-W will come up in autokeyer mode. It will be running in its usual server loop.
- If the user sends a 'K' command by itself, a flag will be set. When the server loop sees this flag, it will call return which will cause the server loop to exit.
- The code in the main loop will fall into the keyMonitor method call. The keyMonitor will then loop watching and reacting to the straight key closing the circuit between GPIO15 and ground. GPIO15 is attached to the tip of the 3.5 mm stereo plug.
- An additional GPIO line will be used on the Pico-W. It will probably be GPIO14.
- GPIO14 will connected to the ring of the stereo plug. When the user wants to switch back to the autokeyer, they will place a jumper between the ring and ground. When keyMonitor detects this, it will immediately call return, ending its loop and falling back out to the main loop which will once again start the autokeyer.
Comments
Post a Comment
Please leave your comments on this topic: