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.
ximport network
import rp2
rp2.country('CN')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
print(wlan.scan())
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.
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().
xxxxxxxxxx
import network
import time
import rp2
rp2.country('CN')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
print(wlan.scan())
ssid = "insert-your-SSID-here"
pw = "insert-your-pw-here"
wlan.connect(ssid, pw)
def light_onboard_led():
led = machine.Pin('LED', machine.Pin.OUT)
led.on();
timeout = 10
while timeout > 0:
if wlan.status() >= 3:
light_onboard_led()
break
timeout -= 1
print('Waiting for connection...')
time.sleep(1)
print(wlan.ifconfig())
wlan_status = wlan.status()
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.
xxxxxxxxxx
#define CYW43_LINK_UP (3)
wlan.ifconfig() Get WiFi network interface parameters: IP address, subnet mask, gateway and DNS server.