Connect WiFi

PicoW comes with CYW43439 wireless chip, supports WiFi 4 (802.11n), single frequency (2.4 GHz).

At present, only wireless LAN is supported for the time being, and the official Raspberry Pi may release firmware that supports Bluetooth in the future.

 

In Micropython, you can use network.WLAN to drive the wireless module. For a detailed description of the function, you can check the library documentation

https://docs.micropython.org/en/latest/library/network.WLAN.html

 

The following uses WLAN.scan() to scan the surrounding WiFi.

 

import network , import rp2 import the network and RP2040 libraries.

rp2.country('CN') Set WiFi region, China.

wlan = network.WLAN(network.STA_IF) creates a wireless LAN interface object, set to network.STA_IF — client, connecting to an upstream WiFi access point.

wlan.active(True) — Activate ("up") the network interface.

wlan.scan() — prints out a scan of available wireless networks, returning a list of information about WiFi access points.

 

image-20220924192259793

 

Add the WLAN.connect function to the original code to connect to WiFi, the WiFi connection successfully lights up the LED on the carrier board and prints the current IP information of PicoW through wlan.ifconfig().

 

 

wlan.connect(ssid, pw) Specify the connected WiFi network, ssid is the WiFi name, and pw is the WiFi password.

wlan.status() Returns the current status of the wireless connection. Defined in the CYW43 wireless driver and pass the status code directly. The return of 3 indicates that the WiFi connection is successful. The rest of the status codes can be viewed in the micropython SDK manual.

wlan.ifconfig() Get WiFi network interface parameters: IP address, subnet mask, gateway and DNS server.

 

image-20220924193320112