Skip to content

Commit 25237c5

Browse files
authored
Merge pull request #795 from pimoroni/patch/stellar-examples
Stellar: tidy examples
2 parents 8f5a944 + 52df18e commit 25237c5

38 files changed

+836
-1691
lines changed

common/fonts/3x5.bitmapfont

462 Bytes
Binary file not shown.

micropython/examples/stellar_unicorn/README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
- [Nostalgia Prompt](#nostalgia-prompt)
1313
- [Rainbow](#rainbow)
1414
- [Scrolling Text](#scrolling-text)
15+
- [Thermometer](#thermometer)
1516
- [Today](#today)
1617
- [Wireless Examples](#wireless-examples)
1718
- [Cheerlights History](#cheerlights-history)
1819
- [Stellar Paint](#stellar-paint)
1920
- [Exchange Ticker](#exchange-ticker)
2021
- [HTTP Text](#http-text)
2122
- [Weather](#weather)
22-
- [NumPy examples](#numpy-examples)
23+
- [NumPy Examples](#numpy-examples)
2324
- [Other Examples](#other-examples)
25+
- [CO2](#co2)
26+
- [Encoder Wheel](#encoder-wheel)
27+
- [Thermometer (BME280)](#thermometer-bme280)
28+
- [Thermometer (BME68x)](#thermometer-bme68x)
2429
- [Launch (Demo Reel)](#launch-demo-reel)
25-
- [Other Resources](#other-resources)
2630

2731
## About Stellar Unicorn
2832

@@ -50,6 +54,8 @@ The easiest way to start displaying cool stuff on Stellar Unicorn is using our S
5054

5155
Clock example with (optional) NTP synchronization. You can adjust the brightness with LUX + and -, and resync the time by pressing A.
5256

57+
This example uses a custom tiny bitmap font, find 3x5.bitmapfont in [fonts](../../common/fonts) and copy it to your Pico W.
58+
5359
### Eighties Super Computer
5460

5561
[eighties_super_computer.py](eighties_super_computer.py)
@@ -103,6 +109,12 @@ Some good old fashioned rainbows! You can adjust the cycling speed with A and B,
103109

104110
Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -.
105111

112+
113+
### Thermometer
114+
[thermometer_pico.py](thermometer_pico.py)
115+
116+
Shows the temperature (from the Pico W's internal sensor) against an appropriately coloured pulsing blob.
117+
106118
### Today
107119

108120
[today.py](today.py)
@@ -153,26 +165,50 @@ Requires `logging.mpy` and `tinyweb` from [micropython/examples/common](../../ex
153165

154166
[weather](weather)
155167

156-
Display current weather data from the [Open-Meteo](https://open-meteo.com/) weather API.
168+
Display current weather data from the [Open-Meteo](https://open-meteo.com/) weather API. Make sure to copy across the `icons` folder to your Unicorn.
169+
170+
Buttons:
171+
A - show / hide temperature
172+
B - swap between Celsius and Fahrenheit
173+
C - randomly select a weather icon
174+
D - add rainbows
175+
LUX + and - adjust brightness
157176

158-
## NumPy examples
177+
## NumPy Examples
159178

160179
[numpy](numpy)
161180

162181
The examples in the folder use `numpy`-like array functions contained in the `ulab` library for super fast graphical effects.
163182

164183
## Other Examples
165184

166-
### Launch (Demo Reel)
185+
These examples use additional hardware.
167186

168-
[launch](launch)
187+
### CO2
169188

170-
If you want to get the demo reel that Stellar Unicorn ships with back, copy the contents of this `launch` folder to your Pico W.
189+
[co2.py](co2.py)
190+
191+
Add a [SCD41 sensor breakout](https://shop.pimoroni.com/products/scd41-co2-sensor-breakout) to make an carbon dioxide detector. Press A, B and C to switch between modes.
192+
193+
This example uses a custom tiny bitmap font, find 3x5.bitmapfont in [fonts](../../common/fonts) and copy it to your Pico W.
171194

172-
## Other Resources
195+
### Encoder Wheel
196+
[encoder_wheel.py](encoder_wheel.py)
173197

174-
Here are some cool Stellar Unicorn community projects and resources that you might find useful / inspirational! Note that code at the links below has not been tested by us and we're not able to offer support with it.
198+
This example uses [RGB Encoder Wheel breakout](https://shop.pimoroni.com/products/rgb-encoder-wheel-breakout) to make an RGB colour picker. Use the encoder wheel to pick a hue and view the RGB breakdown of that colour on the Unicorn display (you can adjust saturation and brightness using the buttons on the breakout too).
175199

176-
- :link: [Green Energy Display with Stellar Unicorn](https://www.hackster.io/andreas-motzek/clock-and-green-energy-display-with-stellar-unicorn-641dcb)
177-
- :link: [stellar-emoji-react - paint emojis from a computer, phone or tablet](https://github.com/chriscareycode/stellar-unicorn/tree/main/stellar-emoji-react)
178-
- :link: [stellar-paste - paste images from the clipboard to Stellar Unicorn](https://github.com/chriscareycode/stellar-unicorn/tree/main/stellar-paste)
200+
### Thermometer (BME280)
201+
[thermometer_bme280.py](thermometer_bme280.py)
202+
203+
Shows temperature, humidity and pressure (from a [BME280 sensor breakout](https://shop.pimoroni.com/products/bme280-breakout)) against an appropriately coloured pulsing blob.
204+
205+
### Thermometer (BME68x)
206+
[thermometer_bme68x.py](thermometer_bme68x.py)
207+
208+
Shows temperature, humidity and pressure (from a [BME680](https://shop.pimoroni.com/products/bme680-breakout) or [BME688](https://shop.pimoroni.com/products/bme688-breakout) sensor breakout) against an appropriately coloured pulsing blob.
209+
210+
### Launch (Demo Reel)
211+
212+
[launch](launch)
213+
214+
If you want to get the demo reel that Stellar Unicorn ships with back, copy the contents of this `launch` folder to your Pico W.

micropython/examples/stellar_unicorn/clock.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# WIFI_PASSWORD = "Your WiFi password"
99
#
1010
# Clock synchronizes time on start, and resynchronizes if you press the A button
11+
#
12+
# This example uses a custom tiny font - find 3x5.bitmapfont in pimoroni-pico/fonts
1113

1214
import time
1315
import math
@@ -193,7 +195,7 @@ def redraw_display_if_reqd():
193195
gradient_background(hue, sat, val,
194196
hue + HUE_OFFSET, sat, val)
195197

196-
clock = "{:02}:{:02}:{:02}".format(hour, minute, second)
198+
clock = "{:02} {:02}".format(hour, minute)
197199

198200
# calculate text position so that it is centred
199201
w = graphics.measure_text(clock, 1)
@@ -206,7 +208,7 @@ def redraw_display_if_reqd():
206208

207209

208210
# set the font
209-
graphics.set_font("bitmap6")
211+
graphics.set_font(open("3x5.bitmapfont", "rb").read())
210212
su.set_brightness(0.5)
211213

212214
sync_time()
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Add a SCD41 sensor breakout to your Stellar Unicorn to make a handy CO2 detector!
2+
# https://shop.pimoroni.com/products/scd41-co2-sensor-breakout
3+
# Press A for CO2, B for temperature and C for humidity
4+
# This example uses a custom tiny font - find 3x5.bitmapfont in pimoroni-pico/fonts
5+
6+
from stellar import StellarUnicorn
7+
from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY
8+
import breakout_scd41
9+
from pimoroni_i2c import PimoroniI2C
10+
from pimoroni import BREAKOUT_GARDEN_I2C_PINS
11+
12+
su = StellarUnicorn()
13+
graphics = PicoGraphics(DISPLAY)
14+
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
15+
16+
# the range of readings to map to colours
17+
# https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms
18+
MIN = 400
19+
MAX = 2000
20+
21+
# pick what bits of the colour wheel to use (from 0-360°)
22+
# https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/
23+
HUE_START = 100 # green
24+
HUE_END = 0 # red
25+
26+
# some pen colours to use
27+
BLACK = graphics.create_pen(0, 0, 0)
28+
WHITE = graphics.create_pen(255, 255, 255)
29+
30+
# some other variables to keep track of stuff
31+
mode = "co2"
32+
flashy_light = False
33+
34+
35+
# sets up a handy function we can call to clear the screen
36+
def clear():
37+
graphics.set_pen(BLACK)
38+
graphics.clear()
39+
40+
41+
# set up
42+
breakout_scd41.init(i2c)
43+
breakout_scd41.start()
44+
45+
graphics.set_font(open("3x5.bitmapfont", "rb").read())
46+
graphics.set_pen(WHITE)
47+
graphics.text("WAIT", 0, 0, scale=1)
48+
su.update(graphics)
49+
50+
while True:
51+
52+
if su.is_pressed(StellarUnicorn.SWITCH_A):
53+
mode = "co2"
54+
if su.is_pressed(StellarUnicorn.SWITCH_B):
55+
mode = "temp"
56+
if su.is_pressed(StellarUnicorn.SWITCH_C):
57+
mode = "humidity"
58+
59+
if breakout_scd41.ready():
60+
clear()
61+
62+
# read the sensor
63+
co2, temperature, humidity = breakout_scd41.measure()
64+
65+
# calculate a colour from the co2 reading
66+
hue = max(0, HUE_START + ((co2 - MIN) * (HUE_END - HUE_START) / (MAX - MIN)))
67+
68+
# draw the border and background
69+
graphics.set_pen(graphics.create_pen_hsv((hue / 360), 1.0, 0.8))
70+
graphics.clear()
71+
graphics.set_pen(graphics.create_pen_hsv((hue / 360), 1.0, 0.2))
72+
graphics.rectangle(1, 1, 14, 14)
73+
74+
graphics.set_pen(WHITE)
75+
if mode == "co2":
76+
# draw the co2 level
77+
co2_string = str(co2)
78+
if co2 < 1000:
79+
graphics.text(f"{co2:.0f}", 2, 2, scale=1, fixed_width=True)
80+
else:
81+
graphics.text(f"{co2_string[0]}", 1, 2, scale=1, fixed_width=True)
82+
graphics.text(f"{co2_string[1]}K", 7, 2, scale=1, fixed_width=True)
83+
graphics.pixel(5, 6)
84+
85+
graphics.text("PPM", 3, 9, scale=1)
86+
87+
if mode == "temp":
88+
# draw the temperature
89+
graphics.text("T:", 2, 2, scale=1)
90+
graphics.text(f"{temperature:.0f}°", 2, 8, scale=1, fixed_width=True)
91+
92+
if mode == "humidity":
93+
# draw the temperature
94+
graphics.text("H:", 2, 2, scale=1)
95+
graphics.text(f"{humidity:.0f}%", 2, 8, scale=1, fixed_width=True)
96+
97+
# flash the top right pixel to show the sensor's been read
98+
if flashy_light is False:
99+
graphics.pixel(15, 0)
100+
flashy_light = True
101+
else:
102+
flashy_light = False
103+
104+
su.update(graphics)

0 commit comments

Comments
 (0)