Skip to content

Instantly share code, notes, and snippets.

@gkowalski
Created November 24, 2022 16:42
Show Gist options
  • Save gkowalski/2b9e151697d72c6cbbd8b0c2e138004e to your computer and use it in GitHub Desktop.
Save gkowalski/2b9e151697d72c6cbbd8b0c2e138004e to your computer and use it in GitHub Desktop.
WiFi Network Test for RP2040 Pico W
import network
import time
import machine
import config
# Test program for Raspberry PI PIC)-W
# Starts Network, Connects to WiFi Network and turns on Light when Connected
# Need to create a config.py with:
#
# sid="your_wiki_ac"
# password="your_password"
#
# George Kowalski 11/2022
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(config.sid, config.password)
led = machine.Pin('LED', machine.Pin.OUT)
led.off()
time.sleep(.5)
# Wait for connect or fail
wait = 15
while wait > 0:
led.on()
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('waiting for connection...')
led.off()
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
led.off()
raise RuntimeError('wifi connection failed')
else:
led.on()
print('\nconnected\n')
print('We Received an IP: ', wlan.ifconfig()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment