🛠 Se connecter au Wi-Fi 2,4 GHz avec le CYW43

Raspberry Pi Pico 2 W · intermediaire · Schéma : IMG-pico-2-w-intermediaire-4-pico2w-connexion-wifi.svg — Pico 2 W associée à une borne Wi-Fi 2,4 GHz, routeur 5 GHz barré, LED de la radio et adresse IP affichée en console.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials