Pico 2 W problem with Pimoroni .uf2

Got my Pico 2 Ws today - thanks for quick reaction to order.

Hit a problem trying the run the example programs in chapter 11 of the 2nd Edition of MicroPython on Raspberry Pi Pico.

I’ve installed the Pimoroni version of the .uf2 but the Requests.py program falls over.

MPY: soft reboot
MicroPython feature/psram-and-wifi, pico2_rp2350_wireless v0.0.10 on 2024-11-18; Raspberry Pi Pico 2 (LTE + WiFi) with RP2350

Type "help()" for more information.

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
Connected to Wi-Fi network.
('192.168.0.73', '255.255.255.0', '192.168.0.1', '194.168.4.100')
Traceback (most recent call last):
  File "<stdin>", line 28, in <module>
  File "requests/__init__.py", line 201, in get
  File "requests/__init__.py", line 79, in request
OSError: -2
>>> 

Here is the code from the book:

import time
import network
import rp2
import requests
rp2.country("GB")

ssid = "ssid"
psk = "P word"

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, psk)

max_wait = 30
while max_wait > 0:
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print("Waiting for Wi-Fi connection...")
    time.sleep(1)

if wlan.status() != 3:
    raise RuntimeError("Network connection failed")
else:
    print("Connected to Wi-Fi network.")
    print(wlan.ifconfig())

response = requests.get("https://text.npr.org/")
[print(x) for x in response.content.splitlines()]
response.close()

LED_server also falls over like this:

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'connect'
>>> 

Is anyone else hitting the same problem?

Am I using the correct uf2?

I want to output to my new Pico Display 2.8" so need the Pimoroni PicoGraphics version.

I’ve pinged @gadgetoid about this. Initially I was going to say you may be using the wrong .UF2, but from the text output it looks to be the correct one, aka pico2_rp2350_wireless.

Is there even an official Micropython build for the Pico 2 W yet?

Depends what you mean by official, but the Pico 2 W changes PR hasn’t been merged so I’d guess not. RP2350 support in general is still rocky… I mean I wrote a bunch of it, and that can’t be good!

Edit: Should note that I had a release Pico 2 W delivered today so I’ll prod this firmware and see how it goes. In any case I’ve just done a bunch of rebasing and cherry picking and other such sundry - ARGH it’s all still experimental branches on top of other experimental branches - busywork, so I should be cutting a new build anyway.

Okay I’m not totally sure there was anything wrong with our builds, but I’ve cut new ones anyway since they could use a tidyup. The firmware(s) are currently building now and should be available at Release v0.0.11 - Pico 2 W Is Officially A Thing Now · pimoroni/pimoroni-pico-rp2350 · GitHub (which I’ll fix up and officially release in the morning)

For LED_server you need to copy the connect.py to your board, from here: gsw-micropython-on-raspberry-pi-pico-2e/eg/ch11/connect.py at main · raspberrypipress/gsw-micropython-on-raspberry-pi-pico-2e · GitHub

Worth trying the official unofficial Pico 2 W firmware to see if you fare any better, you can find that here: https://downloads.raspberrypi.com/micropython/mp_firmware_unofficial_latest.uf2

… that filename tho, misery loves company!

gadgetoidPimoroni Crew,
Thank you the Requests program is now working. I will work through the other sample programs in the Guide.

Unfortunately, I still get the missing module error when I try LED.server.py

from connect import wlan
import socket
import machine

led_onboard = machine.Pin("LED", machine.Pin.OUT)
led_onboard.value(0)
led_state = "LED is off"

html = """
<!DOCTYPE html>
<html>
    <head> <title>Raspberry Pi Pico W</title> </head>
    <body> <h1>Raspberry Pi Pico W</h1>
        <p>%s</p>
    </body>
</html>
"""

address = socket.getaddrinfo("0.0.0.0", 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(address)
s.listen(1)
print("Listening for connections on", wlan.ifconfig()[0])

while True:
    try:
        client, address = s.accept()
        print("Connection accepted from", address)
        request = client.recv(1024).decode("UTF-8")
        print(request)

        led_on = request.startswith("GET /led/on")
        led_off = request.startswith("GET /led/off")
        print("led_on = " + str(led_on))
        print("led_off = " + str(led_off))

        if led_on:
            print("Client requested to turn the LED on.")
            led_onboard.value(1)
            led_state = "LED is on"

        if led_off:
            print("Client requested to turn the LED off.")
            led_onboard.value(0)
            led_state = "LED is off"

        response = html % led_state

        client.send("HTTP/1.0 200 OK\r\n")
        client.send("Content-type: text/html\r\n\r\n")
        client.send(response)
        client.close()

    except OSError as e:
        client.close()
        print("Error, connection closed.")

`>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'connect'
>>> `

I get the same results using the ‘official’ UF2

@Tonygo2 Did you copy connect.py to your board?

Thanks, that gets it to work. Did not notice the need to copy that to Pico 2W in the book instructions.

I’ve now had all the examples in the Official Guide 2nd Ed chapters 11 and 12 working as expected.

Thank you gadgetoid