RM2 Wireless Breakout will not connect to anything?

Hi, I have been trying to get the RM2 wireless breakout to connect to Wifi networks with the Pico Lipo2 but have had no success, using this example code:
“”"
This example will scan for wireless networks and attempt to connect
to the one specified in secrets.py.

If you’re using a Pico LiPo 2 you’ll need an RM2 breakout and an 8-pin JST-SH cable.
Grab them here: RM2 Wireless & Bluetooth Breakout (SP/CE)

Don’t forget to edit secrets.py and add your SSID and PASSWORD.

import network
import time
import binascii
from secrets import WIFI_SSID, WIFI_PASSWORD

Create a table of names for connection states

CONNECTION_STATES = {v : k[5:] for k, v in network.dict.items() if k.startswith(“STAT_”)}
CONNECTION_TIMEOUT = 10

net = network.WLAN(network.STA_IF)
net.active(False)
net.active(True)

print(“\nScanning for WiFi networks.”)

results = 

while not results:
print(“Scanning…”)
results = net.scan()

padding = max(len(r[0]) for r in results) + 1

print(“\nFound WiFi networks:”)
print(f"{‘SSID’:{padding}s} {‘BSSID’:17s}  CH dB Auth")
for (ssid, bssid, channel, rssi, auth_mode, _) in results:

Auth mode is a bitfield,

see 


auth_modes = [mode for b, mode in ((1, “WEP”), (2, “WPA”), (4, “WPA2”)) if auth_mode & b] or [“open”]

bssid = binascii.hexlify(bssid, ":").decode()

print(f"{ssid:{padding}s} {bssid} {channel:2d} {rssi: 2d} {'/'.join(auth_modes)}")

print(f"\nConnecting to {WIFI_SSID}.")

net.connect(WIFI_SSID, WIFI_PASSWORD)

t_start = time.time()

while True:
status = net.status()
print(f"Status: {CONNECTION_STATES.get(status, status)}")

if status in (network.STAT_GOT_IP, network.STAT_CONNECT_FAIL):
break

if time.time() - t_start > CONNECTION_TIMEOUT:
print(f"Timed out after {CONNECTION_TIMEOUT} seconds…")
break

time.sleep(1.0)

and updating the details in secrets will result in the board scanning successfully but failing to connect to any networks. I have tried on two separate networks and have even made one network have no authentication but it still fails to connect. What am I doing wrong?

Your code as posted is giving me syntax errors.
This is the one I use.

"""
This example will scan for wireless networks and attempt to connect
to the one specified in secrets.py.

If you're using a Pico LiPo 2 you'll need an RM2 breakout and an 8-pin JST-SH cable.
Grab them here: https://shop.pimoroni.com/products/rm2-breakout

Don't forget to edit secrets.py and add your SSID and PASSWORD.
"""

import network
import time
import binascii
from secrets import WIFI_SSID, WIFI_PASSWORD

# Create a table of names for connection states
CONNECTION_STATES = {v : k[5:] for k, v in network.__dict__.items() if k.startswith("STAT_")}
CONNECTION_TIMEOUT = 10

net = network.WLAN(network.STA_IF)
net.active(False)
net.active(True)

print("\nScanning for WiFi networks.")

results = []
while not results:
    print("Scanning...")
    results = net.scan()

padding = max(len(r[0]) for r in results) + 1

print("\nFound WiFi networks:")
print(f"{'SSID':{padding}s} {'BSSID':17s}  CH dB Auth")
for (ssid, bssid, channel, rssi, auth_mode, _) in results:
    # Auth mode is a bitfield,
    # see https://github.com/georgerobotics/cyw43-driver/blob/v1.1.0/src/cyw43_ll.c#L573-L584
    auth_modes = [mode for b, mode in ((1, "WEP"), (2, "WPA"), (4, "WPA2")) if auth_mode & b] or ["open"]

    bssid = binascii.hexlify(bssid, ":").decode()

    print(f"{ssid:{padding}s} {bssid} {channel:2d} {rssi: 2d} {'/'.join(auth_modes)}")


print(f"\nConnecting to {WIFI_SSID}.")

net.connect(WIFI_SSID, WIFI_PASSWORD)

t_start = time.time()

while True:
    status = net.status()
    print(f"Status: {CONNECTION_STATES.get(status, status)}")

    if status in (network.STAT_GOT_IP, network.STAT_CONNECT_FAIL):
        break

    if time.time() - t_start > CONNECTION_TIMEOUT:
        print(f"Timed out after {CONNECTION_TIMEOUT} seconds...")
        break

    time.sleep(1.0)


At the moment, it’s scanning OK but not connecting? I have edited my secrets.py file, and my current main.py connects OK? So for me anyway, I know my hardware is OK. I could have sworn my wireless_test.py worked previously?

Looking at my main.py file, it looks like my connect code was based on this example.
pimoroni-pico-rp2350/examples/pico_plus_2/breakouts/rm2-breakout-catfacts.py at main · pimoroni/pimoroni-pico-rp2350 · GitHub

Here is a snippet of my code.

import network
from secrets import WIFI_SSID, WIFI_PASSWORD


    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(WIFI_SSID, WIFI_PASSWORD)
    while wlan.isconnected() is False:
        print('Waiting for connection...')
        display.text("RP2350B", 30, 0, scale=2)
        display.text("RM2 WIFI", 25, 18, scale=2)
        display.text("PIFI24", 35, 36, scale=2)
        display.text("Connecting", 15, 54, scale=2)
        display.update()
        led.value(0)
        time.sleep(1)

    if wlan.isconnected() is True:
        display.set_pen(0)
        display.clear()
        display.set_pen(15)
        display.text("RP2350B", 30, 0, scale=2)
        display.text("RM2 WIFI", 25, 18, scale=2)
        display.text("PIFI24", 35, 36, scale=2)
        display.text("Connected", 18, 54, scale=2)
        display.text("WIFI OK", 30, 72, scale=2)
        display.update()
        led.value(1)
        time.sleep(5)
    
    else:
        display.set.pen(0)
        display.clear()
        display.set.pen(15)
        display.text("RP2350B", 30, 0, scale=2)
        display.text("RM2 WIFI", 25, 18, scale=2)
        display.text("PIFI24", 35, 36, scale=2)
        display.text("WIFI ??", 25, 54, scale=2)
        display.update()
        led.value(0)
        time.sleep(5)

EDIT: And it looks like the example you posted is now MIA, the link on the shop page is 404 error.

Oops, I’ve fixed that link!

The code you posted seems to be missing indents, but I I just gave the RM2 example in the pico-lipo repo a try with a Pico LiPo 2 and a RM2 (connected via SP/CE) and everything seems to be working as expected for me. Catfacts also works, though it looks like you no longer have to specify the pins for the Wi-Fi module:

"""
Get a cat fact from t'internet!
You will need to add your wireless SSID and password to secrets.py (and save this file to your Pico)
"""

import network
import requests
from secrets import WIFI_SSID, WIFI_PASSWORD
from time import sleep

wlan = network.WLAN(network.STA_IF)

# connect to wifi
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while wlan.isconnected() is False:
    print('Waiting for connection...')
    sleep(1)

request = requests.get('http://catfact.ninja/fact').json()
fact = request['fact']
print('Cat fact!')
print(fact)

What firmware are you using on the board?

If you’ve been trying a bunch of different stuff it’s probably worth hard resetting the board (toggling the power button on and off) in case the wi-fi module’s got itself into a weird state.

If I run the linked too cat facts.py file I get

wlan = network.WLAN(network.STA_IF, pin_on=32, pin_out=35, pin_in=35, pin_wake=35, pin_clock=34, pin_cs=33)

gives me
TypeError: extra keyword arguments given

This test file is working for me.

import network
import time
import binascii
from secrets import WIFI_SSID, WIFI_PASSWORD

# Create a table of names for connection states
CONNECTION_STATES = {v : k[5:] for k, v in network.__dict__.items() if k.startswith("STAT_")}
CONNECTION_TIMEOUT = 10

#wlan = network.WLAN(network.STA_IF, pin_on=32, pin_out=35, pin_in=35, pin_wake=35, pin_clock=34, pin_cs=33)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

print("\nScanning for WiFi networks.")

results = []
while not results:
    print("Scanning...")
    results = wlan.scan()

padding = max(len(r[0]) for r in results) + 1

print("\nFound WiFi networks:")
print(f"{'SSID':{padding}s} {'BSSID':17s}  CH dB Auth")
for (ssid, bssid, channel, rssi, auth_mode, _) in results:
    # Auth mode is a bitfield,
    # see https://github.com/georgerobotics/cyw43-driver/blob/v1.1.0/src/cyw43_ll.c#L573-L584
    auth_modes = [mode for b, mode in ((1, "WEP"), (2, "WPA"), (4, "WPA2")) if auth_mode & b] or ["open"]

    bssid = binascii.hexlify(bssid, ":").decode()

    print(f"{ssid:{padding}s} {bssid} {channel:2d} {rssi: 2d} {'/'.join(auth_modes)}")


print(f"\nConnecting to {WIFI_SSID}.")

wlan.connect(WIFI_SSID, WIFI_PASSWORD)

t_start = time.time()

while True:
    status = wlan.status()
    print(f"Status: {CONNECTION_STATES.get(status, status)}")

    if status in (network.STAT_GOT_IP, network.STAT_CONNECT_FAIL):
        break

    if time.time() - t_start > CONNECTION_TIMEOUT:
        print(f"Timed out after {CONNECTION_TIMEOUT} seconds...")
        break

    time.sleep(1.0)

MPY: soft reboot

Scanning for WiFi networks.
Scanning...
Scanning...

Found WiFi networks:
SSID     BSSID              CH dB Auth
PIFI24   ac:22:0b:85:97:78  6 -33 WEP/WPA2
BELL675  64:66:24:f1:e7:3e  1 -86 WEP/WPA2
BELL279  0c:ac:8a:89:3f:9d  1 -59 WEP/WPA2

Connecting to PIFI24.
Status: GOT_IP

Should work if you do

wlan = network.WLAN(network.STA_IF)

Catfacts is a Pico Plus 2 example and you still need to supply the pins on the most recent Pico Plus 2 firmware - I think being able to bake the default wi-fi pins into the build was a recent MicroPython development.

I’ve attempted to make the links on the shop page a bit more helpful for folks using Pico LiPo 2 :)

wlan = network.WLAN(network.STA_IF)
MPY: soft reboot
Traceback (most recent call last):
  File "<stdin>", line 22, in <module>
  File "requests/__init__.py", line 205, in get
  File "requests/__init__.py", line 81, in request
OSError: -2

Do you still get that after a hard reset?

Those two examples do slightly different things with wi-fi, so you might need to power the board on and off for things to work properly if you’re swapping between the two.

Ok, apologies. Running it first thing after powering up gets me this.

MPY: soft reboot
Waiting for connection...
Waiting for connection...
Waiting for connection...
Waiting for connection...
Waiting for connection...
Waiting for connection...
Cat fact!
There are more than 500 million domestic cats in the world, with approximately 40 recognized breeds.