User Tools

Site Tools


connect_pico_to_wifi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
connect_pico_to_wifi [2026/08/17 12:08] – [Running the Code] walkeradminconnect_pico_to_wifi [2026/08/17 12:26] (current) – [Wifi Connect with LCD] walkeradmin
Line 107: Line 107:
 \\  \\ 
 ---- ----
 +==== Wifi Connect with LCD ====
 +\\ 
 +If you have completed the wiki page [[using_pico_with_ssd1306_based_lcd|Using Pico with SSD1306 based LCD]] and you still have your LCD, then you can use this following code to:
  
 +  * Connect to the Wifi
 +  * Print IP to LCD
 +
 +Download the code below and save it to your Pico as lcd-test-wifi.py
 +
 +<code:python | download>
 +from machine import Pin, I2C
 +import ssd1306
 +import network
 +import time
 +
 +#------------- wufi connect --------------------
 +wlan = network.WLAN(network.STA_IF)
 +wlan.active(True)
 +ssid = "YOUR-SSID"
 +password = "YOUR-WIFI-PASSWORD"
 +wlan.connect(ssid, password)
 +
 +
 +while not wlan.isconnected():
 +    print("Connecting...")
 +    time.sleep(0.5)
 +
 +#Print your IP address
 +print("Connected!")
 +print(wlan.ifconfig())
 +
 +#------------------------------------------------
 +
 +#-------------- LCD Show ------------------------
 +
 +# Your wiring: SDA=GP4, SCL=GP5 → I2C0
 +i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
 +
 +lcd = ssd1306.SSD1306_I2C(128, 64, i2c)
 +
 +lcd.fill(0)
 +lcd.text("Yo Tuesday Club!", 0, 0)
 +lcd.text("SSD1306 LCD", 0, 16)
 +lcd.text("Address 0x3C", 0, 32)
 +
 +#converts IP information (its a tuple, kinda like an array, into a string)
 +ip = wlan.ifconfig()[0]   # first item = IP address
 +lcd.text("IP: " + ip, 0, 48)
 +
 +lcd.show()
 +#------------------------------------------------
 +
 +time.sleep(300)
 +lcd.fill(0)
 +lcd.show()
 +</code>
 +
 +If this has worked then you should see something similar to below.
 +\\ 
 +\\ 
 +{{ :wifi-connect-lcd.png?800 |}}
 +\\ 
 +Here we can see the last line on the LCD is my Pico IP Address
connect_pico_to_wifi.1786968507.txt.gz · Last modified: by walkeradmin