🛠 Se connecter à un réseau Wi-Fi (station, WPA2/WPA3)

Raspberry Pi Pico W · debutant · Schéma : IMG-pico-w-debutant-2-picow-connexion-wifi.svg — Pico W sur une table avec des ondes Wi-Fi reliant la puce CYW43439 à une box Internet, terminal série affichant l'adresse IP obtenue, zone keep-out d'antenne annotée

Objectives

The first real networking step with the Pico W: joining a Wi-Fi access point in station mode. The CYW43439 is a Wi-Fi 4 (802.11n) single-band 2.4 GHz only radio — forget about 5 GHz networks — with WPA3 support. You will use MicroPython's network module (the recommended path in the datasheet: MicroPython is "the fastest way to get code running on Pico W"), understand the active → connect → isconnected cycle, and retrieve the IP address.

Hardware

Complete code

# main.py — connexion Wi-Fi station sur Pico W (MicroPython)
# Sauvegardé sous main.py, il se lance à chaque mise sous tension.
import machine, network, time

def do_connect:
    wlan = network.WLAN          # interface station (par défaut)
    wlan.active(True)              # alimente l'interface du CYW43439
    if not wlan.isconnected:
        print('connecting to network...')
        wlan.connect('my_ssid', 'my_password')   # identifiants WPA2/WPA3
        while not wlan.isconnected:
            machine.idle         # dort entre les tentatives (économise)
    print('network config:', wlan.ipconfig('addr4'))

do_connect
# Dépannage : wlan.status donne le code d'échec d'association.
# Après wlan.connect, MicroPython réessaie indéfiniment par défaut.

Expected verification

The console displays network config: ('192.168.x.x', '255.255.255.0', ...): the Pico W has obtained its DHCP lease. You can ping it from your PC (same network). The CYW43 LED may blink during association. Test WPA3 if your router supports it: the cyw43 driver handles it.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials