from machine import Pin, I2C, Timer
from ssd1306 import SSD1306_I2C
import random, time
# --- OLEd setup ------
i2c = I2C(0, scl=Pin(1), sda=Pin(0))
oled = SSD1306_I2C(128, 64, i2c)
# ------ GPS simulation function ------
def simulate_gps(timer):
# Simulate GPS coordinates around Toronto
lat = 43.7000 + random.uniform(-0.01, 0.01)
lon = -79.4200 + random.uniform(-0.01, 0.01)
# Display on OLED
oled.fill(0)
oled.text("GPS Tracker", 10, 0)
oled.text("Lat: {:.5f}".format(lat), 0, 20)
oled.text("Lon: {:.5f}".format(lon), 0, 35)
oled.show()
# Also print to Serial Monitor
print("🎈 Latitude:", round(lat, 6), "longitude:", round(lon, 6))
# ---- Timer to update every 3 seconds ----
gps_timer = Timer()
gps_timer.init(period=3000, mode=Timer.PERIODIC, callback=simulate_gps)
# ----- keep program running -----
while True:
time.sleep(1)
Loading
ssd1306
ssd1306