""" Connect to a Wifi Hotspot, creds are stored in 'creds' file. """ import network # For display import random from machine import Pin, SPI import st7789 as st7789 import time import utime # Choose a font #from fonts import vga1_8x8 as font #from fonts import vga2_8x8 as font #from fonts import vga1_8x16 as font from fonts import vga2_8x16 as font #from fonts import vga1_16x16 as font #from fonts import vga1_bold_16x16 as font #from fonts import vga2_16x16 as font #from fonts import vga2_bold_16x16 as font def main(): tft = st7789.ST7789( SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)), 135, 240, reset=Pin(23, Pin.OUT), cs=Pin(5, Pin.OUT), dc=Pin(16, Pin.OUT), backlight=Pin(4, Pin.OUT), rotation=3 ) tft.init() tft.fill(st7789.BLACK) file = open('creds', 'r') wifi_ssid = file.readline().rstrip("\n") wifi_pass = file.readline().rstrip("\n") file.close() wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): tft.text(font, "Init", 0, 0, st7789.WHITE) print('Init connection to Wifi...') wlan.connect(wifi_ssid, wifi_pass) while not wlan.isconnected(): tft.text(font, "Connecting ...", 0, 0, st7789.RED) print('connecting...') utime.sleep(1) tft.text(font, "Connecting ...", 0, 0, st7789.BLACK) pass tft.text(font, "Connected", 0, 0, st7789.WHITE) print('Connected') wlan_config = wlan.ifconfig() print('network config:', wlan_config) tft.text(font, "IP/network: ", 0, 32, st7789.WHITE) tft.text(font, wlan_config[0] + "/" + wlan_config[1], 10, 53, st7789.GREEN) tft.text(font, "Gw/DNS: ", 0, 75, st7789.WHITE) tft.text(font, wlan_config[2] + "/" + wlan_config[3], 10, 96, st7789.GREEN) main()