#๐ Problem With Pi Pico (Using Thonny)
15 messages ยท Page 1 of 1 (latest)
@worldly nymph
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
that input() function waits for user input so im not sure if thats the "automatic" you are looking for
otherwise its not clear to me what youre doing here like what do you expect to happen vs what is actually happening
does the pico turn on the pc when you input "on" into that shell?
maybe you just want to move the input() to before the while loop so it only asks for the input once and then loops forever? cuz when its inside the loop is is asking for it over and over again so it wont be automatic if you have to answer it every time
this is my code
from machine import Pin
import time
Define the GPIO pin where the base of the transistor is connected
transistor_base = Pin(1, Pin.OUT)
Function to momentarily turn on the transistor
def momentary_on(duration=1):
transistor_base.value(1)
time.sleep(duration)
transistor_base.value(0)
Main loop to listen for serial commands
print("Ready to receive commands...")
try:
while True:
command = input().strip()
if command == "on":
momentary_on(1)
print("Device ON for 1 second")
elif command == "off":
print("Momentary switch does not support 'off' command")
except KeyboardInterrupt:
# Clean up if the script is interrupted
transistor_base.value(0)
print("Program interrupted and terminated.")
You are running it in the thonny shell, when you run it manually.
When it powers on, it's probably running your code, but there isn't a shell for you to input something as it's expecting.
If it's a pico W you can connect it to your wifi and control it in a few different ways.
If it's not a pico W you could use something as a button to turn it on/off
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.