[Release & Competition] Online Python Editor for Pokitto!


OK, it’s fixed. I had forgotten that I’d checked out the latest upstream micropython and that required a full rebuild.


I have today updated micropython, which is now in sync with the latest PokittoLib.


Now that I am at it, should I make a PR and merge libtilemap to PokittoLib?


Sure, go ahead. :slight_smile:


Da dum ti dum… implemented wind and steering :kissing_heart:

Animation now 4x smoother



This is AWESOME :clap::clap:



  • Python Editor now contains a time function: umachine.time_us(), which returns current tics in milliseconds.
This is how you can implement a FPS counter with it
import upygame as upg
import framebuf
import urandom as random
import umachine

screen_sf = upg.display.set_mode() # full screen

# Set palette

# pokitto picture
w2 = 16
h2 = 16
pokittoPixels = b'\

hero_sf = upg.surface.Surface(w2, h2, pokittoPixels)

vx = 0;
vy = 0;
frameNum = 0
lastFpsTime = umachine.time_us()
fps = 0
while True:

    eventtype = upg.event.poll()
    if eventtype != upg.NOEVENT:
        if eventtype.type== upg.KEYDOWN:
            if eventtype.key == upg.K_RIGHT:
                vx = 1
            if eventtype.key == upg.K_LEFT:
                vx = -1
            if eventtype.key == upg.K_UP:
                vy = -1
            if eventtype.key == upg.K_DOWN:
                vy = 1
        if eventtype.type == upg.KEYUP:
            if eventtype.key == upg.K_RIGHT:
                vx = 0
            if eventtype.key == upg.K_LEFT:
                vx = 0
            if eventtype.key == upg.K_UP:
                vy = 0
            if eventtype.key == upg.K_DOWN:
                vy = 0

    for i in range(1,200):
        x2 = random.getrandbits(6) + 20
        y2 = random.getrandbits(6) + 5
        screen_sf.blit(hero_sf, x2, y2)

    x = x + vx
    y = y + vy
    screen_sf.blit(hero_sf, x, y)

    # FPS
    frameNum += 1
    if(frameNum%50 == 0): # Calculate in 50 frame intervals
        now = umachine.time_us()
        fps = 50000 // (now-lastFpsTime)
        lastFpsTime = now


Anybody mind if we increase the FPS cap? I just noticed that there’s no PROJ_FPS, so it defaults to about 20. Ideally we’d have a function to set the desired cap, but for now we could just set it to something higher.


Do we need a cap at all? Practically, something like 50 FPS cap would be good as well, but there has been a discussion that the limiter is not working correctly. Would it be easiest just to set it to 100?

If somebody really wants to slow down the Python program, there is a umachine.wait() for that purpose.

Usually, the problem is too low FPS. Even 20 FPS could be challenging to achieve, if you have a lot of objects.


I wouldn’t mind removing the cap entirely.


@FManga @Hanski Bigger problem is the sudden increase of bins from ~140kB to 200+kB after latest release.

“Pyrates” is very close to playable alpha but its already 204kB


Still? It should’ve dropped back down.


Ok I haven’t checked in a moment


I’d like to point out @jonne that will be really unfair if you’re going to win… :wink:


No chance of that :wink:



hey everyone, i’ve just started playing around with the python editor, its the first time I’ve tried making something for the pokitto so I apologise for any ignorance I may have about the hardware. When running my program on the website it eventually crashes with the error “Attempt to write to flash (0x680002a) on PC=0x1c4e0” - @Hanski can you please elaborate on what this means? thanks in advance!


Hi @andrewb! Can you post the code you’re working on? It’s easier to find out what’s wrong that way, especially since you’re the first to report this error.


At the moment it is just a program that switches between different states. However, after going through the five “levels”, restarting and trying again it crashes.
I tried putting all the code in 1 file and it didn’t fix it. I also thought it was maybe something to do with memory management but I’ve tried using gc.collect() and there has still been crashes.
It could just be something silly I’ve overlooked though, or how I’m organising the code, or maybe what I’m trying isn’t possible? Any input would be great!
pokitto-mpy-project (4).zip (5.3 KB)


It’s crashing because it’s running out of memory. Specifically, it’s a stack overflow.
The reason that happens is that you don’t exit each state before you enter the next. Each state is an endless loop that never returns.
Changing from one state to the next should be setting a variable and then returning.
pokitto-mpy-project(41).zip (5.4 KB)


Right, I understand now, I’ll put that fix into my code before I do anything else! Thank you for your help, it probably would have taken me a while to figure that out, its good to have another set of eyes to check over your code sometimes.