Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3436

Troubleshooting • Pi Pico W: Another 'bricked' post (but I'm fairly convinced)

$
0
0
My pico w was running fine until I assigned the script below as main.py. Running Windows 11.

Issue: Board is no longer recognised by Thonny, and it is showing in Device Manager as an unrecognised USB device. Disabling it and uninstalling it doesn't change anything. Pressing and holding the bootsel button doesn't make anything appear in explorer. Trying to manually install drivers via device manager also doesn't work. Thonny shows 'Unable to connect to com4: port not found. Process ended with exit code 1'. If I go into Run=>configure interpreter and try to reinstall the firmware, nothing available appears (regardless of bootsel button being pressed before connecting to usb). I tried installing libusb-win32 and also winusb (libusb) via zadig with no joy (zadig said 'installation failed'). Tried changing laptop; same symptoms. Same for changing usb cable. My other pi pico w works absolutely fine.

Interestingly, the script itself seems to be running perfectly on the board. I can use my phone as an access point to remotely control the onboard LED. So perhaps main.py is preventing the USB dependent scripts from running somehow?

Anyhow, could the script below have somehow damaged the USB? Could there be a hardware fault somehow? Is there any way I can prevent this in the future? Apologies, I'm a dev newbie so any advice is appreciated - thanks.

Code:

  import timeimport networkimport machineimport socket# Define the onboard LED pinled2 = machine.Pin("LED", machine.Pin.OUT)led = machine.Pin(16, machine.Pin.OUT)def connect_to_network(ssid, password):  wlan = network.WLAN(network.STA_IF)  wlan.active(True)  wlan.connect(ssid, password)  # Wait for connection  max_wait = 150  while max_wait > 0:    if wlan.status() < 0 or wlan.status() >= 3:      break    max_wait -= 1    print('waiting for connection...')    led.value(1)    led2.value(1)  # Turn LED on using value() method    time.sleep(0.25)    led.value(0)    led2.value(0)  # Turn LED off using value() method    time.sleep(0.25)  # Handle connection error  if wlan.status() != 3:    counter = 0    while counter < 150:      led2.value(1)      time.sleep(1)      led2.value(0)      time.sleep(1)      counter += 1    raise RuntimeError('network connection failed')  else:    print('connected')    led2.value(1)    status = wlan.ifconfig()    print('ip = ' + status[0])    return status[0]  # Return the IP address of the Picodef start_socket_server(ip):  addr = socket.getaddrinfo(ip, 80)[0][-1]  s = socket.socket()  s.bind(addr)  s.listen(1)  print('listening on', addr)  while True:    cl, addr = s.accept()    print('client connected from', addr)    request = cl.recv(1024)    request = str(request)    print('Request:', request)    if 'GET /ledon' in request:      led2.value(1)    elif 'GET /ledoff' in request:      led2.value(0)    response = """HTTP/1.1 200 OKContent-Type: text/html<html><head>  <title>LED Control</title></head><body>  <h1>LED Control</h1>  <p>LED is now {}</p>  <p><a href="/ledon">Turn LED ON</a></p>  <br>  <br>  <p><a href="/ledoff">Turn LED OFF</a></p></body></html>""".format('ON' if led2.value() else 'OFF')    cl.send(response)    cl.close()# Connect to the laptop's Wi-Fi network (replace with your actual credentials)# Connect to the laptop's Wi-Fi networkip_address = connect_to_network('network_name', 'password')# Start the socket serverstart_socket_server(ip_address)#remember, ip address for control is http://192.168.4.1 

Statistics: Posted by yamax87 — Mon Jun 17, 2024 11:31 pm — Replies 0 — Views 18



Viewing all articles
Browse latest Browse all 3436

Trending Articles