1

I discovered that I can plug a Raspberry Pi Pico into my Android phone and use the app 'Serial USB Terminal' as a serial monitor. However, if the Pico has a main.py script uploaded to it, then it seems to work as a read only kind of thing where it just displays the output of the running Python program and does not let me stop the script and interact with the Pico using REPL. If I do not have a main.py script on the Pico, then when I use the Serial USB Terminal app I can interact with the Pico REPL.

In Thonny, when the Pico is connected I can hit the "Stop" button and it will terminate the main.py script and let me interact and send Python commands to the Pico. I can't seem to figure out how to achieve this same functionality in the Serial USB Terminal app, or presumably any other serial monitor.

Is there something special about Thonny that allows for using REPL even when the Pico has a script onboard already?

EDIT: To future searchers, thanks to @sburlappp I figured out how to do this. In the Android app "Serial USB Terminal", you can create hotkeys using the "Macro buttons". Long press one of the Macro button slots to set it. There is an option for 'Hex', which can be set to 0x03 (just type 03, leave out the 0x part) and then this will act as a keyboard interrupt and stop the main.py script allowing you to use the REPL. You can use the following command to start running the script again if desired:

exec(open("main.py").read())

Macro setting

Stop and restart main.py example

3
  • Can you please provide the code you used on the pico? Also any info regarding what kind of cables (usb otg, USB-C, etc.) were used would be appreciated. I'm having troubles getting the android phone to recognize the pico as a serial device.
    – topher217
    Jun 14, 2022 at 7:14
  • I was using a USB OTG adapter (basically a USB-A female port to a USB-C male plug) I plugged a micro USB cable (with data capabilities, make sure it's not just a power only cable) into the adapter, and the USB-C end of the adapter into my phone. I can send my code if you'd like but I think it's irrelevant. I think your problem might be in the Serial USB Terminal settings. Can you confirm you are using the app "Serial USB Terminal" on Android? Jun 15, 2022 at 11:47
  • Thanks for the follow up. I figured out my issue. I was attempting to use the pico in host mode (still can't figure out if this is possible or not) but using the example hello_world code in the pico github repo was able to be detected in the Serial USB Terminal App as this puts the pico into the "device" or "accessory" mode. Interested to know if you've gotten the opposite to work though? Seems the Android Open Accessory protocol has fallen off the face of the internet or something.
    – topher217
    Jun 15, 2022 at 12:28

1 Answer 1

0

You need to type Control-C to stop the script. If your terminal app doesn't provide a way to do this, install the Hacker's Keyboard app to get access to a more complete on-screen keyboard.

1
  • Thank you for the tip, your suggestion ultimately led me to finding a solution. It seems that hex 0x03 has the same effect as Ctrl + C. I am able to send hex values in the Serial USB Terminal app, and sure enough this acts as a keyboard interrupt and stops the main.py script. I can then use 'import main.py' to start running the script again if needed. Thank you! Mar 3, 2022 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.