Built-in project · Raspberry Pi Pico W

MicroPython WiFi AP and station at once on a Pico W

MicroPython on a Raspberry Pi Pico W: the board starts its own access point and joins Mokxi’s simulated network at the same time, printing both. The whole build, a Raspberry Pi Pico W, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $6. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Running access point and station modes together
  • Joining a network with network.WLAN in STA_IF
  • Making your own network with AP_IF
  • Telling the two interfaces apart by name
  • Difficulty: Intermediate
  • Time: About 15 minutes
  • Board: Raspberry Pi Pico W
  • Parts: 1

How it works

The Pico W can do two WiFi jobs at once. First it starts its own access point called Pico-W-AP with the password 12345678, and prints its name and address.

Then it also turns on station mode and joins Mokxi's simulated network, Mokxi-Lab, with the password breadboard. It waits until connected, prints the IP address it was given, and every 10 seconds reports whether the connection is still up.

Parts list

1 part, plus the jumper wires. They retail for about $6; on Mokxi they're free.

Kits that can build it

These 2 starter kits have every part in the circuit. Each kit's page lists what else it can build.

The code

The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.

main.py · Raspberry Pi Pico W
# Both at once on a Pico W: the board's own access point, and a station
# joined to Mokxi's simulated network (the board's WiFi properties).
import network
import time

ap = network.WLAN(network.AP_IF)
ap.config(ssid="Pico-W-AP", password="12345678")
ap.active(True)
print("Access point:", ap.config("ssid"), ap.ifconfig()[0])

sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.connect("Mokxi-Lab", "breadboard")
while not sta.isconnected():
    time.sleep_ms(250)
print("Station connected: IP", sta.ifconfig()[0])

while True:
    time.sleep(10)
    print("station", "still connected" if sta.isconnected() else "connection lost")

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • It waits forever after Access point This project
    The station part cannot connect. Check that the name and password in sta.connect match the network, which in Mokxi are the board's WiFi properties.
  • Pins are powered from 5 V, or a 5 V signal goes into a GPIO. The RP2040 pins are 3.3 V only and are not 5 V tolerant. Raspberry Pi Pico W
    Power the board from VBUS or VSYS at 5 V, but keep GPIO signals at 3.3 V. Use a level shifter or a divider for 5 V parts.
  • WiFi code fails to connect, or the on-board LED code does nothing. The LED on the Pico W is not on GP25 like on the plain Pico. Raspberry Pi Pico W
    Use the board's LED_BUILTIN name so the library drives it through the WiFi chip. Join a 2.4 GHz network only, with the right SSID and password, and wait for the link before sending.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.