A calculator with micropython!

I recently got a calculator called the numworks. My absolute favorite feature of it is that you can program micropython directly on it! I’m currently porting my raycasting engine to it https://www.reddit.com/r/numworks/comments/f94vbl/increased_the_speed_by_alot/?utm_medium=android_app&utm_source=share


Would it be possible to have a micropython ide right on the pokitto?

Possible, yes, but it wouldn’t be practical:

  • We’d need some way to plug a keyboard into the Pokitto
  • There would be less available RAM, since it would be used to store code

Both of these issues can be solved by using the online IDE instead.

1 Like

I’m not a big fan of Python, but I’ve always loved programmable calculators.

I have a scientific calculator that I like to use (I’ve had it since secondary school, so it’s quite old) but it doesn’t have bitwise operations, which (being a programmer) would be incredibly handy.

The more time goes by, the more I think this would be useful.
I think one of the goals for this year ought to be to develop either a keyboard hat or a bluetooth hat that can interact with a bluetooth keyboard.

If code was written to the SD card instead of kept in RAM then you’d theoretically be able to have the IDE as one program, write the code and then switch to the other program to test.
(Possibly even making the compiler a separate program, assuming the Python is to be compiled rather than interpreted.)

It wouldn’t be very practical because there would be a lot program switching involved, but it would theoretically work.

There’s more to MicroPython bytecode than just an array of bytes. You’d need to have a C++ compiler on the Pokitto to get it to run.

I would have thought you’d be able to precompile the C++ functions and then compiling the Python would be more of a matter of linking to the precompiled functions.

But if it’s more complex than that then there’s unlikely to be enough RAM.
Not unless there’s a C implementation of micropython,
I expect a C compiler might just about fit in RAM.

If a MicroPython implementation wouldn’t work, Lua probably would,
but the challenge is getting Lua to work on the Pokitto in the first place because it uses things like printf and C’s file API.

Unfortunately this is not the case. The bytecode compiler generates a big array and C++ code.

I couldn’t find one that doesn’t try to keep the entire AST in RAM.
Simply writing an assembler that can output programs bigger than RAM is tricky enough.

That’s annoying.

Lua doesn’t have that problem, it only generates bytecode chunks.
It doesn’t care whether functions are machine code or byte code,
it interacts with both in the same way, and it retrieves the functions it needs either from the ‘global table’ of its environment or through function parameters

I’m tempted to try, but if I were to attempt it I’d wait at least until we’ve got the file API sorted.

It is awesome! they also provide the stl parts for printing the case (at least one of the old ones).


Wow, impressive piece of hardware! :stuck_out_tongue:

Maybe I’m wrong, but I’m not able to find microSD slot (but there’s 8Mb ext flash for storage and USB port) nor audio output nor speaker. Add them, install a loader and you’ve got the ultimate killer handheld!

Really nice of them to make a page listing all the parts, going so far as to linking the datasheets.
That (non-qwerty) keyboard must be terrible for writing code on, even if it’s Python.

1 Like

Luckily you can write code on a PC and pass it over then if you edit it on the calculator you can send it back for safe keeping. The keyboard isn’t bad for simple debugging but I wouldn’t want to type the whole engine on it

Update on the micropython fps:

1 Like

Just making sure you checked those possible generic optimizations:

  • Sin/cos pre-computed tables (both are costly to call!)
  • No allocation on the fly (= reuse any kind of table/list/etc instead of reallocating them)
  • Pre-compute as much as you can (related to sin/cos tables).
    • That also means moving any calculations out of loops. Maybe you don’t need to compute a sin(a) X times if a doesn’t vary at all, and instead store the result before the loop starts, for example!
  • If possible, switch to integer math (not sure how this work in Python).

As for any intrusive optimization, it’s best to measure before and after the individual part that is being refined.

Also, you got a strong fish-eye effect, you might want to adjust your rays’s length relative to the center of the screen, unless that’s what you want to achieve :stuck_out_tongue: (the multiplier for each ray is a good candidate for being precalculated too!)

As for the calculator itself, that’d have been a dream for my younger self. I learned a lot of programming on my old CASIO calculator, basic, c, c++ and asm (those last three not directly on said device). Even got that exam mode hehe

a little more optimization, a lowered resolution and color.


Yeah there’s no SD card slot and you’re limited to 16kb for python scripts (as I painfully found out today)

Oops. That just killed my interest. 16kb is not gonna go very far

@jonne: Remember that this device has got 256kb RAM and everyone can contribute improvements to its SW.

NumWorks is the first open graphing calculator: all our engineering effort is made available online under a Creative Commons license

So it’s a only a question of time that someone addresses this limitation. Also, I expect sooner than later a loader that allows browsing and running compiled user programs is also added to expand the device’s possibilities.

There’s already a custom firmware that allows 32kb and that’s just for the python scripts of you write c++/c and build your own version of the os you can some cool stuff (some one’s ported an nes emulator and someone else is working on A sprite and tile graphics engine)

1 Like

Figured out simple way to compress my maps. Got it down. From 20kb to 1.39kb