🛠 Se connecter au Wi-Fi 2,4 GHz avec le CYW43
Objectives
First wireless steps with the Pico 2 W: initialize the Infineon CYW43439 chip (Wi-Fi 4, 2.4 GHz only, WPA3 supported), join a network in station mode, obtain the IP address via DHCP, and read it from the program. This is the common foundation for all network tutorials on this board.
Hardware
- Pico 2 W (clear antenna area, no metal case)
- 2.4 GHz access point (5 GHz is not supported by the CYW43)
- pico-sdk with pico_cyw43_arch_lwip_threadbackground, or MicroPython >= v1.25.0
Complete code
// main.c - lien : pico_stdlib pico_cyw43_arch_lwip_threadbackground
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include "lwip/ip4_addr.h"
#include "lwip/netif.h"
#define WIFI_SSID "mon_ssid"
#define WIFI_PASS "mon_mot_de_passe"
int main(void) {
stdio_init_all;
if (cyw43_arch_init) { printf("cyw43 init failed\n"); return 1; }
cyw43_arch_enable_sta_mode;
if (cyw43_arch_wifi_connect_timeout_ms(
WIFI_SSID, WIFI_PASS, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
printf("connexion Wi-Fi echouee\n");
return 1;
}
printf("IP : %s\n", ip4addr_ntoa(netif_ip4_addr(netif_default)));
while (true) { sleep_ms(1000); } // lwIP tourne dans le thread cyw43
}
MicroPython equivalent: import network; wlan = network.WLAN; wlan.active(True); wlan.connect('ssid', 'pass') then wlan.ipconfig('addr4').
Expected verification
The console displays the obtained IP address (typically 192.168.x.x) after a few seconds; the board is pingable from the local network. In MicroPython, wlan.isconnected returns True.
Common errors
- 5 GHz network or enterprise WPA3: the CYW43439 only sees 2.4 GHz (802.11n); WPA2/WPA3 personal is supported since MicroPython 1.25.
- Forgetting cyw43_arch_enable_sta_mode after cyw43_arch_init: the connection fails systematically.
- Calling lwIP outside the thread without cyw43_arch_lwip_begin/end (or without cyw43_arch_poll in poll mode).
- Antenna buried in a metal case: the 14 x 9 mm keep-out area must remain completely clear.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython