Uses latest firmware from Pinorami
MicroPython v1.21.0, picow v1.21.0 on 2023-10-06; Raspberry Pi Pico W with RP2040
you may have to set up your own api at open weather and put in your location at line 21
import network
import time
import secrets
import urequests
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
WIDTH, HEIGHT = display.get_bounds()
set up the hardware
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
WHITE = display.create_pen(255, 255, 255)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(secrets.SSID, secrets.PASSWORD)
while wlan.isconnected()==False:
print(‘Connecting . . .’)
print(‘Congratulations, You Have Connected’)
#weather=urequests.get(“https://api.openweathermap.org/data/2.5/weather?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial”).json()
weather=urequests.get(“https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial”).json()
tm=time.localtime(weather[‘dt’]+weather[‘timezone’])
print(‘Welcome to ‘+weather[‘name’]+’, ‘+weather[‘sys’][‘country’])
print(‘Local Time: ‘+str(tm[3])+’:’+str(tm[4])+’ ‘+str(tm[1])+’/’+str(tm[2])+‘/’+str(tm[0]))
sr=time.localtime(weather[‘sys’][‘sunrise’]+weather[‘timezone’])
print(‘Sunrise at: ‘+str(sr[3])+’:’+str(sr[4]))
ss=time.localtime(weather[‘sys’][‘sunset’]+weather[‘timezone’])
print(‘Sunset at: ‘+str(ss[3]-12)+’:’+str(ss[4])+’ PM’)
print(‘Current Temp: ‘+str(weather[‘main’][‘temp’])+’ F’)
print(‘Current Humidity: ‘+str(weather[‘main’][‘humidity’])+’ %’)
print(‘Current Barometric Pressure: ‘+str(weather[‘main’][‘pressure’]*0.0009869233)+’ ATM’)
for i in range(len(weather[‘weather’])):
print('Current Conditions: ‘+weather[‘weather’][i][‘main’]+’, '+weather[‘weather’][i][‘description’])
print(‘Wind: ‘+str(weather[‘wind’][‘speed’])+’ MPH’)
myTime=time.time()
while True:
if time.time()-myTime>300:
weather=urequests.get(“https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=098014b8c21bddb718496a654f417674&units=imperial”).json()
tm=time.localtime(weather[‘dt’]+weather[‘timezone’])
ss=time.localtime(weather[‘sys’][‘sunset’]+weather[‘timezone’])
myTime=time.time()
print(‘New Data Read’)
display.set_pen(WHITE)
display.text('Welcome '+weather['name'],0,0)
sr=time.localtime(weather['sys']['sunrise']+weather['timezone'])
display.set_pen(WHITE)
display.text('Time: '+str(tm[3])+':'+str(tm[4]),0,16)
display.text('Date: '+str(tm[1])+'/'+str(tm[2])+'/'+str(tm[0]),0,32)
display.text('Sunrise: '+str(sr[3])+':'+str(sr[4]),0,48)
display.text('Sunset: '+str(ss[3]-12)+':'+str(ss[4])+' PM',0,64)
display.update()
time.sleep(10)
display.set_pen(WHITE)
#display.text('Welcome to '+weather['name'],0,82)
display.text('Weather: ',0,82)
display.text('Temp: '+str(weather['main']['temp'])+' F',0,94)
display.text('Humidity: '+str(weather['main']['humidity'])+' %',0,110)
display.text('BP: '+str(weather['main']['pressure']*0.0009869233)+' ATM',0,126)
display.text('Wind: '+str(weather['wind']['speed'])+' MPH',0,142)
display.update()
time.sleep(5)
#dsp.fill(0)
WHITE = display.create_pen(255, 255, 255)
display.set_pen(WHITE)
#display.text('Welcome to '+weather['name'],0,178)
display.text('Conditions: ',0,160)
row=26
for i in range(len(weather['weather'])):
display.text(weather['weather'][i]['main'],0,176)
row=row+10
display.text(weather['weather'][i]['description'],0,192)
row=row+10
display.update()
time.sleep(5)
#dsp.fill(0)