Pico W: the LED on the radio, and a Wi-Fi status light
A Raspberry Pi Pico W blinks its LED, which hangs off the Wi-Fi chip rather than the RP2040, joins a WPA2 network and shows on a red LED when it could not.
Communication · Beginner
In a real product: Smart plug status light (Consumer electronics): A connected device shows at a glance whether it reached the home network.
The Pico W is a Pico with an Infineon CYW43439 Wi-Fi and Bluetooth chip added. To make room, the board's green LED moved: it is no longer on GP25 of the RP2040 but on the radio chip's own GPIO 0. LED_BUILTIN still works, but every digitalWrite to it is now a message over the bus between the two chips. This sketch blinks that LED, looks for Wi-Fi networks, joins one and lights a red LED on GP15 when it can't.
What you'll learn
- Why
LED_BUILTINon a Pico W is pin 64, not a GPIO, and what the radio's driver does to switch it - That GP23, GP24, GP25 and GP29 belong to the radio (power, data, chip select, clock) and are not on the header
- Joining a WPA2 network with
WiFi.begin()and a timeout, and reading the address DHCP gave the board
How it works
When the sketch starts, the arduino-pico core powers the CYW43439 up through GP23 and talks to it over a three-wire SPI bus that a PIO state machine drives. It loads the chip's firmware (about 225 KB, kept in the Pico W's flash with your sketch) and waits for the chip to say it is ready. That is why a Pico W takes a moment longer to start than a Pico.
After that, digitalWrite(LED_BUILTIN, HIGH) sends the radio an "ioctl", a small command packet that sets its GPIO
digitalRead(LED_BUILTIN)asks the radio for its pin levels.
WiFi.scanNetworks() asks the radio to listen on every channel and returns how many access points answered; WiFi.SSID(i) and WiFi.RSSI(i) say which and how loud. WiFi.begin(ssid, password) hands the passphrase to the radio, which does the WPA2 handshake itself; the board then asks the access point for an address by DHCP. With WiFi.setTimeout(3000) the sketch waits at most six seconds (twice the timeout) for that address.
The simulated access point is set in diagram.json: its "network" names it TryEmbedded with the password lab-pass-123, so the sketch joins, gets 192.168.4.2 and the red LED stays off. The Network panel under the canvas shows the scan, the join and the DHCP lease.
Try this
- Change the password in the sketch: the join fails with a wrong password (the Network panel says so) and the red LED lights.
- Blink faster with
delay(50): each change is a packet to the radio, still well under a millisecond. - Put your own network's name and password in and run it on a real Pico W.
sketch.ino
// Raspberry Pi Pico W (Arduino core): the LED is on the CYW43439 radio (LED_BUILTIN, pin 64), not on an RP2040
// GPIO. The sketch joins the WPA2 network "TryEmbedded"; a red LED on GP15 lights when it could not.
#include <WiFi.h>
const int NO_WIFI = 15;
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 3000) delay(10); // the USB port, for the first lines (not forever: no PC, no wait)
pinMode(LED_BUILTIN, OUTPUT);
pinMode(NO_WIFI, OUTPUT);
Serial.print("radio MAC ");
Serial.println(WiFi.macAddress());
int found = WiFi.scanNetworks();
for (int i = 0; i < found; i++) Serial.printf("found %s (%d dBm)\n", WiFi.SSID(i), WiFi.RSSI(i));
WiFi.setTimeout(3000);
WiFi.begin("TryEmbedded", "lab-pass-123");
bool joined = WiFi.status() == WL_CONNECTED;
if (joined) {
Serial.print("joined, address ");
Serial.println(WiFi.localIP());
} else {
Serial.printf("could not join (status %d): the red LED is on\n", WiFi.status());
}
digitalWrite(NO_WIFI, joined ? LOW : HIGH);
}
void loop() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // a command to the radio, then a question to it
delay(250);
}