#๐Ÿ”’ Problem With Pi Pico (Using Thonny)

15 messages ยท Page 1 of 1 (latest)

worldly nymph
#

Hi!, im trying to make my pi pico work as a switch to turn on a pc, the code works and i named the file main.py to the root of the pi but it does not start automatically after losing power.

prisma bridgeBOT
#

@worldly nymph

Python help channel opened

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.

worldly nymph
#

if i do
import main
the code starts, but it dosn't do it automatically

celest cobalt
#

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?

celest cobalt
worldly nymph
#

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.")

sour pulsar
#

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

prisma bridgeBOT
#
Python help channel closed

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.