🛠 Se connecter à un réseau Wi-Fi (station, WPA2/WPA3)
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
- 1 × Raspberry Pi Pico W + micro-USB data cable
- MicroPython firmware
raspberry_pi_pico_w(_picowbuild, includes the cyw43 driver) - A 2.4 GHz access point (WPA2 or WPA3) — no 5 GHz
- Serial console (Thonny,
picocom…) at 115200 baud
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
- 5 GHz network: the CYW43439 is 2.4 GHz only — the connection fails silently or times out. Check the 2.4 GHz band SSID on your router.
- Standard MicroPython firmware (not
_picow):network.WLANreturns an error or no interface — re-flash the Pico W build. - Credentials with special characters improperly escaped in the Python string: test with a simple password first.
- Waiting loop without
machine.idle: it works, but you unnecessarily saturate the CPU;idleputs the core in a waiting state between attempts. - Obstructed antenna: the 14 × 9 mm keep-out area at the edge of the board must not be covered by anything, especially not metal (metal case = Faraday cage, degraded gain — documented in the datasheet).
- Using
wlan.statusinstead of blocking onisconnected: this is the diagnostic tool for association failures (wrong password, AP not found…).
Other tutorials for this board
- Faire clignoter la LED embarquée (elle est derrière la puce Wi-Fi !)
- Bouton et potentiomètre sans marcher sur le sans-fil (GPIO libres & ADC)
- Servir une page web depuis la Pico W (socket TCP + HTTP)
- Client HTTP : consommer une API depuis la Pico W
- Heure exacte via NTP : l'horloge temps réel des projets connectés
- Client MQTT : télémétrie IoT légère sur la Pico W
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython