Skip to content

Commit e9d5539

Browse files
MatteoCnda1nedseb
andauthored
feat(wsen-pads): Climate Station example with OLED Display. (#373)
* feat(wsen-pads): Climate Station example with OLED Display. * fix(wsen-pads): Fix ruff lint issues and missing final newlines. * fix(wsen-pads): Simplify display using steami_screen and fix lint issues. * fix(hts221): Remove unused env_station.py example. * refactor(wsen-pads): Rewrite climate station with steami_screen widgets. Major rewrite of the station_env example: 1. Use steami_screen (Screen, SSD1327Display, gauge, title, value, subtitle) instead of 100+ lines of pixel-by-pixel manual drawing (draw_hline, draw_vline, draw_rect, draw_fill_rect, draw_circle). The native framebuf primitives behind steami_screen are implemented in C and are orders of magnitude faster than Python pixel loops. 2. Remove fake calibration that forced readings toward arbitrary "ideal" values (20C, 50%RH, 1013hPa). A sensor reading 23C at startup was being shifted to 20C, making every subsequent reading wrong by -3C. The example now shows raw sensor values. For real calibration, use steami_config (see calibrate_temperature.py). 3. Translate all UI text and comments from French to English to match the project convention. 4. Add try/except/finally with power_off() for both sensors so Ctrl+C does not leave WSEN-PADS and HTS221 running. 5. Use named comfort thresholds (TEMP_MIN/MAX, HUM_MIN/MAX, PRES_MIN/MAX) instead of inline magic numbers. --------- Co-authored-by: Sébastien NEDJAR <sebastien@nedjar.com>
1 parent a6a70d2 commit e9d5539

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Climate station example using WSEN-PADS, HTS221 and SSD1327 OLED.
2+
3+
Reads temperature and pressure from the WSEN-PADS sensor and humidity
4+
from the HTS221 sensor. Displays live readings with a comfort index
5+
on the round 128x128 OLED using steami_screen widgets.
6+
7+
Hardware:
8+
- WSEN-PADS (temperature + pressure)
9+
- HTS221 (humidity)
10+
- SSD1327 128x128 OLED display (round)
11+
"""
12+
13+
from time import sleep_ms
14+
15+
import ssd1327
16+
from hts221 import HTS221
17+
from machine import I2C, SPI, Pin
18+
from steami_screen import GRAY, GREEN, LIGHT, RED, WHITE, Screen, SSD1327Display
19+
from wsen_pads import WSEN_PADS
20+
21+
# --- Display ---
22+
spi = SPI(1)
23+
dc = Pin("DATA_COMMAND_DISPLAY")
24+
res = Pin("RST_DISPLAY")
25+
cs = Pin("CS_DISPLAY")
26+
display = SSD1327Display(ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs))
27+
screen = Screen(display)
28+
29+
# --- Sensors ---
30+
i2c = I2C(1)
31+
pads = WSEN_PADS(i2c)
32+
hts = HTS221(i2c)
33+
34+
# --- Comfort thresholds ---
35+
TEMP_MIN, TEMP_MAX = 18.0, 26.0
36+
HUM_MIN, HUM_MAX = 40.0, 60.0
37+
PRES_MIN, PRES_MAX = 1000.0, 1025.0
38+
39+
POLL_MS = 1000
40+
41+
42+
def comfort_label(temp, hum, pres):
43+
"""Return a (label, color) tuple describing indoor comfort."""
44+
if TEMP_MIN <= temp <= TEMP_MAX and HUM_MIN <= hum <= HUM_MAX and PRES_MIN <= pres <= PRES_MAX:
45+
return "IDEAL", GREEN
46+
if temp > 30 or hum > 75:
47+
return "HOT", RED
48+
if temp < 15 or hum < 25:
49+
return "COLD", GRAY
50+
if pres < PRES_MIN:
51+
return "LOW P", GRAY
52+
if pres > PRES_MAX:
53+
return "HIGH P", LIGHT
54+
return "OK", WHITE
55+
56+
57+
def draw_screen(temp, hum, pres):
58+
"""Render one frame with all readings and comfort index."""
59+
label, color = comfort_label(temp, hum, pres)
60+
61+
screen.clear()
62+
screen.gauge(
63+
int(temp), min_val=0, max_val=50, color=color,
64+
)
65+
screen.title("CLIMATE")
66+
screen.value("{:.1f}".format(temp), unit="C")
67+
screen.subtitle(
68+
"H:{:.0f}% P:{:.0f}hPa".format(hum, pres),
69+
label,
70+
)
71+
screen.show()
72+
73+
74+
# --- Main loop ---
75+
print("Climate station started")
76+
print("Press Ctrl+C to exit.")
77+
78+
try:
79+
while True:
80+
temp = pads.temperature()
81+
hum = hts.humidity()
82+
pres = pads.pressure_hpa()
83+
hum = max(0.0, min(100.0, hum))
84+
print("T:{:.1f}C H:{:.1f}% P:{:.0f}hPa".format(temp, hum, pres))
85+
draw_screen(temp, hum, pres)
86+
sleep_ms(POLL_MS)
87+
except KeyboardInterrupt:
88+
print("\nClimate station stopped.")
89+
finally:
90+
screen.clear()
91+
screen.show()
92+
pads.power_off()
93+
hts.power_off()

0 commit comments

Comments
 (0)