You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've spent several hours figuring out how to make the Stellar Paint example work because it simply doesn't work at all. I'm just going to dump here what I did to get it to work.
My first problem was that this
You will also have to install micropython-phew and microdot through Thonny's Tools -> Manage Packages.
didn't work to the extent that searching for those in Thonny didn't even return any results.
My Stellar Unicorn was running MicroPython v1.21.0, stellar_unicorn v1.21.0 so I downloaded the currently newest stable release v1.23.0-1 and installed that. That didn't result in Thonny being able to find either of the packages. I've still no idea why Thonny won't find the packages (it finds others like if I search for "http" I get a bunch of results). In the end I ended up using something called pipkin to get them installed. On my laptop, with the Stellar Unicorn plugged in and Thonny not running:
Stellar Paint now chucked different errors at me and I eventually figured out that it's written to work with Microdot 1 and Microdot 2 has breaking changes, so, barely knowing what I was doing, fiddled around with stellar_paint.py until it looked like this.
import os
from microdot import Microdot, send_file, websocket
from phew import connect_to_wifi
from stellar import StellarUnicorn
from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY
from WIFI_CONFIG import SSID, PSK
su = StellarUnicorn()
graphics = PicoGraphics(DISPLAY)
mv_graphics = memoryview(graphics)
su.set_brightness(0.5)
WIDTH, HEIGHT = graphics.get_bounds()
ip = connect_to_wifi(SSID, PSK)
print(f"Start painting at: http://{ip}")
server = Microdot()
@server.route("/", methods=["GET"])
def route_index(request):
return send_file("stellar_paint/index.html")
@server.route("/static/<path:path>", methods=["GET"])
def route_static(request, path):
return send_file(f"stellar_paint/static/{path}")
def get_pixel(x, y):
if x < WIDTH and y < HEIGHT and x >= 0 and y >= 0:
o = (y * WIDTH + x) * 4
return tuple(mv_graphics[o:o + 3])
return None
def flood_fill(x, y, r, g, b):
todo = []
def fill(x, y, c):
if get_pixel(x, y) != c:
return
graphics.pixel(x, y)
up = get_pixel(x, y - 1)
dn = get_pixel(x, y + 1)
lf = get_pixel(x - 1, y)
ri = get_pixel(x + 1, y)
if up == c:
todo.append((x, y - 1))
if dn == c:
todo.append((x, y + 1))
if lf == c:
todo.append((x - 1, y))
if ri == c:
todo.append((x + 1, y))
c = get_pixel(x, y)
if c is None:
return
fill(x, y, c)
while len(todo):
x, y = todo.pop(0)
fill(x, y, c)
@server.route("/paint")
@websocket.with_websocket
async def echo(request, ws):
while True:
data = await ws.receive()
try:
x, y, r, g, b = [int(n) for n in data[0:5]]
graphics.set_pen(graphics.create_pen(r, g, b))
graphics.pixel(x, y)
except ValueError:
if data == "show":
su.update(graphics)
if data == "fill":
data = await ws.receive()
x, y, r, g, b = [int(n) for n in data[0:5]]
graphics.set_pen(graphics.create_pen(r, g, b))
flood_fill(x, y, r, g, b)
if data == "clear":
graphics.set_pen(graphics.create_pen(0, 0, 0))
graphics.clear()
if data == "save":
filename = await ws.receive()
print(f"Saving to {filename}.bin")
try:
os.mkdir("saves")
except OSError:
pass
with open(f"saves/{filename}.bin", "wb") as f:
f.write(graphics)
await ws.send(f"alert: Saved to saves/{filename}.bin")
server.run(host="0.0.0.0", port=80)
And that works.
The text was updated successfully, but these errors were encountered:
I've spent several hours figuring out how to make the Stellar Paint example work because it simply doesn't work at all. I'm just going to dump here what I did to get it to work.
My first problem was that this
didn't work to the extent that searching for those in Thonny didn't even return any results.
My Stellar Unicorn was running MicroPython v1.21.0, stellar_unicorn v1.21.0 so I downloaded the currently newest stable release v1.23.0-1 and installed that. That didn't result in Thonny being able to find either of the packages. I've still no idea why Thonny won't find the packages (it finds others like if I search for "http" I get a bunch of results). In the end I ended up using something called
pipkin
to get them installed. On my laptop, with the Stellar Unicorn plugged in and Thonny not running:Stellar Paint now chucked different errors at me and I eventually figured out that it's written to work with Microdot 1 and Microdot 2 has breaking changes, so, barely knowing what I was doing, fiddled around with
stellar_paint.py
until it looked like this.And that works.
The text was updated successfully, but these errors were encountered: