forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Milestone
Description
CircuitPython version and board name
Adafruit CircuitPython 10.0.1 on 2025-10-09; Raspberry Pi Pico W with rp2040
Code/REPL
# code.py
import mount_sdcard, basic_wifi_test
******************************************
# mount_sdcard.py
# 08/10/2025
import board, busio, sdcardio, storage, sys
sck = board.GP18
si = board.GP19
so = board.GP16
cs = board.GP17
# SPI setup for SD card
spi = busio.SPI(sck, si, so)
sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
try:
storage.mount(vfs, "/sd")
sys.path.append("/sd")
sys.path.append("/sd/lib")
print("SD card mounted.")
except ValueError:
print("No SD card!")
******************************************
# basic_wifi_test
# 10/16/2025
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
from os import getenv
import ipaddress
import wifi
import socketpool
networks = []
for network in wifi.radio.start_scanning_networks():
networks.append(network)
wifi.radio.stop_scanning_networks()
networks = sorted(networks, key=lambda net: net.rssi, reverse=True)
for network in networks:
print("ssid:",network.ssid, "rssi:",network.rssi)
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
if None in [ssid, password]:
raise RuntimeError(
"WiFi settings are kept in settings.toml, "
"please add them there. The settings file must contain "
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
"at a minimum."
)
print()
print("Connecting to WiFi")
# connect to your SSID
try:
wifi.radio.connect(ssid, password)
except TypeError:
print("Could not find WiFi info. Check your settings.toml file!")
raise
print("Connected to WiFi")
pool = socketpool.SocketPool(wifi.radio)
# prints MAC address to REPL
print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address])
# prints IP address to REPL
print(f"My IP address is {wifi.radio.ipv4_address}")
# pings Google
ipv4 = ipaddress.ip_address("8.8.4.4")
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
Behavior
SD card mounted.
ssid: network1 rssi: -38
ssid: network1 rssi: -39
ssid: network1 rssi: -39
ssid: network1 rssi: -40
ssid: network1 rssi: -42
ssid: rssi: -75
ssid: rssi: -75
ssid: rssi: -76
ssid: network2 rssi: -85
ssid: rssi: -86
ssid: network3 rssi: -87
ssid: network4 rssi: -88
ssid: rssi: -90
Connecting to WiFi
Connected to WiFi
My MAC addr: ['0xZZ', '0xZZ', '0xZZ', '0xZZ', '0xZZ', '0xZZ']
My IP address is 192.168.1.144
Ping google.com: 32.999985 ms
Code done running.
[09:02:46.067] Disconnected
[09:02:47.072] Warning: Could not open /dev/tty.usbmodem144101 (No such file or directory)
[09:02:47.072] Waiting for tty device..
*I've edited the network names and MAC address.
pico w disconnects and CIRCUITPY unmounts after "Code done running."
Description
Mounting the sd card and then scanning for wifi networks causes the disconnections...not necessarily immediately nor every time, but eventually. If I don't mount the sd card at all, or mount the sd card after scanning for networks, it seems to work reliably. If I don't scan for networks, everything works as it should no matter when the sd card is mounted.
Additional information
pico w with picow bell proto underplate and Adafruit datalogger; also pico w with Cytron Maker Pi Pro.
tested with different wifi networks, host computers, USB hubs, cabling, etc.