Raspberry Pi Pico W

Getting started with Raspberry Pi Pico W Built-in Wifi


Getting Started with Raspberry Pi Pico W Built-in Wifi- In this article, we will guide you through the process of getting started with Raspberry Pi Pico W WiFi, from setting it up to exploring its features and connecting to WiFi. The basic operation of this project is that the Raspberry Pi Pico W automatically connects to WiFi. If the Pico W is not connected to WiFi, the onboard LED on the Raspberry Pi Pico W will blink. Once it connects to WiFi, the LED will stop blinking. This process, along with status messages, will be displayed on the console. Throughout this piece, readers will be introduced to the foundational steps of setting up the Raspberry Pi Pico W, including the initial configurations necessary to enable WiFi connectivity. We will also cover the programming aspects required to establish and maintain a stable wireless connection. By the end of this article, you will have gained a thorough understanding of how to leverage the WiFi functionality of the Raspberry Pi Pico W, allowing you to embark on a variety of innovative and exciting projects that harness the power of wireless technology. In this project, we will only utilize the built-in Wi-Fi connectivity of the Raspberry Pi Pico W, which will assist in our upcoming articles because we will be using the Raspberry Pi Pico W’s built-in Wi-Fi in many projects. Our next project will involve controlling the External LED with Raspberry Pi Pico W through a web server.

Amazon link:

Raspberry Pi Pico W

Micro USB Cable

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Raspberry Pi Pico W:

The RP2040 Chip

Central to the Raspberry Pi Pico W is the RP2040, an in-house ARM chip developed by the Raspberry Foundation. The dual-core ARM Cortex M0+ processor at its heart is flexible and powerful, with a clock speed reaching up to 133 MHz. This makes the Pico W both robust and versatile for a variety of applications.

Wireless Connectivity

A key advancement in the Pico W is its wireless capabilities, made possible by the Infineon CYW43439 wireless chip. This component brings IEEE 802.11 b/g/n wireless LAN and Bluetooth 5.2 to the board, opening up a realm of possibilities in connected and IoT applications.

GPIOs and Pinout:

The Raspberry Pi Pico W boasts 40 pins, including 26 multipurpose GPIOs, all operating at a 3.3V logic level. The board is designed to be pin-to-pin compatible with the older Pico board, maintaining continuity and ease of upgrade for existing projects. It also includes a 3-Pin header for a debug interface, strategically located near the RP2040 Chip.

Raspberry Pi Pico W Specifications:

Specification Detail
Microcontroller Chip RP2040 (by Raspberry Pi)
Processor Dual-core ARM Cortex M0+
Clock Speed Up to 133 MHz
SRAM 264kB
Flash Memory 2MB onboard
Wireless Interfaces Single-band 2.4GHz (802.11n)
Bluetooth Bluetooth 5.2
Wireless Chip Infineon CYW43439
GPIO Pins 26 multi-function GPIO pins
Interfaces 2×SPI, 2×I2C, 2×UART
Analog-to-Digital Converters 3×12-bit ADC
PWM Channels 16×controllable
USB Support USB 1.1 Host and Device
Power Modes Low-power sleep and dormant modes
Additional Features Temperature sensor, floating-point libraries
Programmable IO 8×Programmable IO (PIO) state machines
PCB Dimensions 51mm x 21mm x 1mm
Power Input USB port or VSYS pin
Programming Languages C/C++ and MicroPython
IDE Support Thonny IDE, Arduino IDE

Distinguishing Pico W from Raspberry Pi Pico

The Raspberry Pi Pico W differentiates itself from its predecessor with the CYW43439 Wi-Fi chip and an updated power section featuring the RT6154A from Richtek. This change addresses both connectivity and power efficiency, making the Pico W more suitable for a range of applications.

Powering and Programming the Pico W

The Pico W can be powered through the USB port or the VSYS pin. For programming, users have the flexibility to use C/C++ and MicroPython, with support for the Thonny IDE and Arduino IDE, catering to a wide spectrum of developers.


To save the program, open Thonny IDE or any other IDE of your choice, and copy and paste the program given below. Then save it as ‘main.py’ in the Raspberry Pi Pico W.

Raspberry pi pico W Built-in Wifi

Raspberry pi pico W Built-in Wifi

Practical demonstration:

Once the program is saved, simply press the ‘Run’ button, or press the ‘F5’ key on the keyboard.

Raspberry pi pico W Built-in Wifi

When the program runs, you will see an output like this in the Thonny IDE console, and the onboard LED of the Raspberry Pi Pico W will stop blinking.

Raspberry pi pico W Built-in Wifi

And when you turn off the Wi-Fi, a message like this will be displayed on the console. And the onboard LED of the Raspberry Pi Pico W will start blinking again.

Raspberry pi pico W Built-in Wifi

And when you turn on the Wi-Fi, this message will be displayed.

Raspberry pi pico W Built-in Wifi

Code explanation:

In the script, we use three libraries for different purposes. The network library helps to connect the microcontroller to a WiFi network. The time library is used to add pauses in the script, which can be necessary for timing things right. Finally, the machine library allows the script to work with the microcontroller’s hardware, like turning on and off lights or reading sensor data. These libraries together help the microcontroller connect to the internet, wait when needed, and control physical devices.

specific WiFi credentials are defined to enable the connection to a wireless network. The ssid represents the name of the WiFi network that the device aims to connect to. It’s a unique identifier that distinguishes one network from another. Similarly, the password is a crucial component, providing the necessary security key to access the specified WiFi network.

These lines are used for wifi activating, It begins with the initialization of the WLAN interface in station mode, achieved through the command wlan=network.WLAN(network.STA_IF). This mode is essential for allowing the device to connect to a WiFi network. Once the WLAN interface is initialized, it is activated using the command wlan.active(True). Activation is necessary to enable the interface to start functioning and to begin the process of connecting to a network. Finally, the device attempts to connect to the specified WiFi network using wlan.connect(ssid, password). This command utilizes the previously defined WiFi credentials – the network’s SSID and password – to establish a secure connection. This setup is pivotal in enabling the device to communicate with a WiFi network, forming the basis of its network connectivity.

configuring an onboard LED, which serves as a visual indicator. This is accomplished through the command onboard_led = machine.Pin(‘LED’, machine.Pin.OUT), which sets up the LED as an output device. Here, machine.Pin is used to specify the pin to which the LED is connected, In the Raspberry Pi Pico, the onboard LED is connected to GPIO 25, but in the Raspberry Pi Pico W, this LED is connected to a GPIO on the wireless chip instead of the RP2040 chip. That’s why ‘LED’ is used instead of a GPIO pin.

In the script, the initial phase of attempting to connect to the WiFi network is managed through a loop. This loop is designed to keep trying to establish a connection up to a predefined number of times, specified by max_attempts. In this particular case, the script will make a maximum of 10 connection attempts. During these attempts, the state of the onboard LED is toggled using onboard_led.toggle(). This action causes the LED to blink, serving as a visual indicator of each connection attempt being made. To manage the timing between each attempt, a delay of 1 second is introduced using time.sleep(1). This pause ensures that the connection attempts are not made too rapidly, allowing time for the network response. Additionally, after each attempt, the attempt counter is incremented with attempts += 1. This counter keeps track of the number of attempts made, ensuring that the process stops after reaching the maximum number of attempts. This structured approach in the script efficiently manages the initial attempts to connect to the WiFi network, providing visual feedback and controlled timing.

In the script, the process of verifying the WiFi connection’s success or failure is handled through conditional statements. When the condition if wlan.isconnected(): is met, it indicates that the WLAN (WiFi) interface has successfully connected to a network. The script then executes several actions to reflect this successful connection. It first prints a confirmation message, declaring that the device has successfully connected to the specified WiFi network, identified by ssid. Following this, it displays the network configuration details, including the device’s IP address, subnet mask, gateway, and DNS server, obtained through wlan.ifconfig(). Additionally, the onboard LED’s value is set to 1, which typically turns it on, serving as a visual cue that the WiFi connection is established. A variable named connected is also set to True, signifying the success of the connection.

Conversely, if the connection attempt fails (covered by the else: part of the condition), it suggests that wlan.isconnected() returned False. In this scenario, the script responds by printing a message to inform that the WiFi connection was unsuccessful. Furthermore, it sets the onboard LED’s value to 0, which usually turns it off. This action serves as an indicator that the device failed to connect to the WiFi network. This bifurcation in the script ensures clear communication regarding the status of the WiFi connection, whether successful or unsuccessful, and provides appropriate visual feedback through the LED.

infinite loop, defined by while True:, which ensures that the enclosed code executes continuously without interruption. Within this loop, it performs several checks and actions related to the WiFi connection status.

First, it checks for a reconnection to the WiFi network with if wlan.isconnected() and not connected:. This condition verifies whether the WiFi is connected while the connected variable is False, indicating a previous disconnection. When a reconnection is detected, several actions follow: it prints a “Reconnected to WiFi.” message, turns the onboard LED on (using onboard_led.value(1)) as a visual cue for the connection, prints the network configuration details retrieved from wlan.ifconfig(), and sets the connected variable to True, reflecting the connected state.

The script also checks for WiFi disconnection with elif not wlan.isconnected() and connected:. This condition checks if the WiFi is not connected while the connected variable is True, indicating a previous connection. Upon disconnection, it prints “Disconnected from WiFi.” and sets the connected variable to False, signifying the disconnected state.

Furthermore, the script manages the disconnected state by evaluating if not connected:. In this scenario, if the WiFi is disconnected, it toggles the onboard LED (onboard_led.toggle()), which usually results in the LED blinking. This blinking serves as a visual indication of the disconnected state.

Lastly, the script includes a delay of 1 second between each loop iteration, implemented via time.sleep(1). This pause is essential to prevent the processor from being overloaded with constant checks and to ensure the blinking of the LED is noticeable if it’s in a toggling state. This combination of continuous monitoring, visual feedback, and systematic checking ensures effective management of the WiFi connection status.


With the Raspberry Pi Pico W built-in WiFi capabilities, you can easily connect your projects to the internet and create exciting IoT applications. By following the steps outlined in this article, you should have no trouble getting started with the Raspberry Pi Pico W and exploring its Wi-Fi functionality. Have fun experimenting and building!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button