Skip to content

Commit fb0b540

Browse files
committed
Added itsaSNAP project contents
1 parent 7601d79 commit fb0b540

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+149
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import time
2+
import terminalio
3+
from adafruit_matrixportal.matrixportal import MatrixPortal
4+
5+
# --- Display setup ---
6+
matrixportal = MatrixPortal(width=64, height=32, bit_depth=6, debug=True)
7+
8+
# Create a label for the temperature
9+
matrixportal.add_text(
10+
text_font=terminalio.FONT,
11+
text_position=(33, 24), # Positioned on the right side, near the bottom
12+
scrolling=False,
13+
)
14+
15+
# Create a label for the weather condition
16+
matrixportal.add_text(
17+
text_font=terminalio.FONT,
18+
text_position=(33, 8), # Positioned on the right side, above the temperature
19+
scrolling=False,
20+
)
21+
22+
# Dictionary mapping weather conditions to BMP filenames
23+
WEATHER_IMAGES = {
24+
"Sunny": "images/sunny.bmp",
25+
"Clear": "images/moon.bmp",
26+
"Cloudy": "images/cloudy.bmp",
27+
"Drizzle": "images/rain.bmp",
28+
"Rainy": "images/cloudy.bmp",
29+
"Heavy rain": "images/rain.bmp",
30+
"Thunderstorms": "images/thunder.bmp",
31+
"Isolated thunderstorms": "images/thunder.bmp",
32+
"Scattered thunderstorms": "images/thunder.bmp",
33+
"Strong storms": "images/thunder.bmp",
34+
"Sun showers": "images/rain.bmp",
35+
"Snow": "images/snow.bmp",
36+
"Light snow": "images/snow.bmp",
37+
"Heavy snow": "images/snow.bmp",
38+
}
39+
40+
# Update this to your weather feed
41+
WEATHER_FEED = "weather-feed"
42+
UPDATE_DELAY = 1800 # 30 minutes
43+
44+
def get_last_data(feed_key):
45+
try:
46+
data = matrixportal.get_io_data(feed_key)
47+
if data:
48+
return data[0]["value"]
49+
except (KeyError, IndexError) as e:
50+
print(f"Error fetching data from feed {feed_key}: {e}")
51+
return None
52+
53+
def is_daytime(hour):
54+
return 5 <= hour < 18 # True if between 5:00 AM and 5:59 PM
55+
56+
def clean_condition(condition, is_day):
57+
condition = condition.replace("Mostly ", "").replace("Partly ", "")
58+
condition_mapping = {
59+
"Drizzle or light rain": "Rainy",
60+
"Heavy rain": "Rainy",
61+
"Isolated thunderstorms": "Thunderstorms",
62+
"Sun showers": "Rainy",
63+
"Scattered thunderstorms": "Thunderstorms",
64+
"Strong storms": "Thunderstorms",
65+
"Light snow": "Snow",
66+
"Heavy snow": "Snow",
67+
}
68+
if condition == "Sunny" and not is_day:
69+
return "Clear"
70+
return condition_mapping.get(condition, condition)
71+
72+
def parse_weather_data(data):
73+
try:
74+
_, weather_info = data.split(" at ")
75+
time_str, weather_data = weather_info.split(" ", 1)
76+
hour = int(time_str.split(":")[0])
77+
if "PM" in time_str and hour != 12:
78+
hour += 12
79+
elif "AM" in time_str and hour == 12:
80+
hour = 0
81+
temperature, condition = weather_data.split(" and ")
82+
return hour, temperature, condition
83+
except ValueError as e:
84+
print(f"Error parsing weather data: {e}")
85+
return None, None, None
86+
87+
def update_display():
88+
weather_data = get_last_data(WEATHER_FEED)
89+
if weather_data:
90+
hour, temperature, condition = parse_weather_data(weather_data)
91+
if hour is not None and temperature is not None and condition is not None:
92+
is_day = is_daytime(hour)
93+
current_condition = clean_condition(condition, is_day)
94+
95+
matrixportal.set_text(temperature, 0)
96+
matrixportal.set_text(current_condition, 1)
97+
98+
# Determine which image to show based on condition and time
99+
if current_condition == "Sunny" and is_day:
100+
image_key = "images/sunny.bmp"
101+
elif current_condition == "Clear" or (current_condition == "Sunny" and not is_day):
102+
image_key = "images/moon.bmp"
103+
else:
104+
image_key = WEATHER_IMAGES.get(current_condition, "images/sunny.bmp")
105+
106+
try:
107+
matrixportal.set_background(image_key)
108+
except OSError as e:
109+
print(f"Error loading image for {current_condition}: {e}")
110+
else:
111+
print(f"Failed to parse weather data: {weather_data}")
112+
matrixportal.set_text("Parse Error", 0)
113+
matrixportal.set_text("", 1)
114+
else:
115+
print("Failed to retrieve data from feed")
116+
matrixportal.set_text("No Data", 0)
117+
matrixportal.set_text("", 1)
118+
119+
last_update = time.monotonic()
120+
update_display()
121+
122+
# Main loop
123+
while True:
124+
current_time = time.monotonic()
125+
if current_time - last_update > UPDATE_DELAY:
126+
update_display()
127+
last_update = current_time
128+
129+
time.sleep(1) # Sleep for 1 second

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_bitmap_font/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_bus_device/__init__.py

Whitespace-only changes.
Binary file not shown.

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_esp32spi/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_io/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_matrixportal/__init__.py

Whitespace-only changes.

Matrix_Portal_S3_itsaSNAP_Daily_Forecast_Display/lib/adafruit_minimqtt/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To auto-connect to Wi-Fi
2+
CIRCUITPY_WIFI_SSID= "YOUR-WIFI-SSID"
3+
CIRCUITPY_WIFI_PASSWORD= "YOUR-WIFI-PASSWORD"
4+
5+
WIFI_SSID = "YOUR-WIFI-SSID"
6+
WIFI_PASSWORD = "YOUR-WIFI-PASSWORD"
7+
8+
9+
10+
# For Adafruit IO Login
11+
AIO_USERNAME="YOUR-ADAFRUIT-IO-USERNAME"
12+
AIO_KEY="YOUR-ADAFRUIT-IO-KEY"
13+
14+
15+
16+
# To enable modifying files from the web. Change this too!
17+
# Leave the User field blank in the browser.
18+
CIRCUITPY_WEB_API_PASSWORD="passw0rd"
19+
20+
CIRCUITPY_WEB_API_PORT=80

0 commit comments

Comments
 (0)