Virtual Machine for microcontrollers lets you run Python on AVR chips

[Clifford Wolf] wrote in to let us know about a project he recently completed called EmbedVM. It’s a virtual machine for AVR microcontrollers. The package has a relatively small overhead, taking up about 3kB of program memory. The VM can execute 74,000 instructions per second, and runs asynchronously from the microcontroller. As [Clifford] demonstrates in the videos after the break, this can be handy for preloading commands to prevent slowdown during heavy VM processor loads.

The snippet in the image above is an example program written in the C-like VM code which will play some [Rick Astley] on a speaker. This code can be run from RAM, EEPROM, or even external storage like an SD card. Recently there was a supplemental compiler project that even takes Python code and compiles it into VM byte-code. What a nice abstraction tool for making inexpensive microcontroller-based designs easily programmable for those that have a bit of Python experience.

If you don’t recognize the name, [Clifford Wolf] is also the author of OpenSCAD, a tool that is quite popular with 3D printing.

Comments

  1. Stevie says:

    ownage!

    ps: first

  2. EllisGL says:

    Next up Javascript!

  3. Bernhard says:

    go clifford!

  4. I have been tpying with this idea, I wanted to use PHP. I tried several times, but scrapped my work, wasnt happy.

    This is great, keep it up!

  5. FDP says:

    I’m not a huge fan of microcontrollers (usually try to use an FPGA), but this is awesome.

    • Steve-O-Rama says:

      I’m just the opposite, though not through experience with both (only with the uCs). Could you tell me how you got started with FPGAs, and why you prefer them? Just curious.

  6. Chris says:

    The more I look at this, the more impressed I am.

  7. Mike says:

    Wow!

    I hang my head in shame for posting my crusty port of TinyBASIC to the AVR.

  8. xorpunk says:

    code has to be converted by external tools, where is the vm part?

  9. overflo says:

    YAY \ö/

    this is soooooo cool.

    microncontrollers with virtually unlimited ROM for programming.
    codeimages on SDcards
    live code updates over zigbee / rmf modules++
    the possibilities!

    thank you so much clifford

  10. JSN says:

    Where’s the Python? All I see is a C variant.

    I’m not saying it’s unimpressive. I’m just commenting that the title is *highly* misleading.

  11. Mark says:
  12. lochnessduck says:

    can’t wait to see somebody demonstrate python on a chip!

  13. swapwizard says:

    The tools for this are written in Python. It otherwise reminds me of the “Sweet-16″ virtual machine that Woz wrote for the Apple II.

  14. fredboboss says:

    Hi,

    you’ll have the python frontend in the pysrc/ directory.

    I’ve used pymite as well, and it’s as nice a job as embedvm.

    I think both have their own advantages.

    pymite : intends to be 100% compatible with python bytecode, portable along multiple platforms (ARM, …) but higher requirements

    embedvm : lower requirements, and multiple frontend languages (C like & python)

    Fred

  15. Prov says:

    Great, great, great project. I had been looking for this on-and-off for a while.

    Keep in mind that this doubles as a Rick/Roll.
    This makes Clifford is an evil genius.

  16. jf says:

    This must be the most elaborate rickroll ever.

    Apart from that, seems like a nifty way of sharing code among different microcontrollers, although the loss in performance kind of defeats the point of using a microcontroller in the first place.

  17. mp says:

    It is a very nice VM, I have played whole day with it.
    My background is C/C++ and I am happy whit C like scripting language.
    But I have same suggestions about it:
    – Need full description of language
    – Full description how to pass / get values between VM and native functions
    – Need floating point types / arithmetic
    – 32 bit VM in this days 32bit microcontrollers are common
    Thanks Clifford Wolf for good job

  18. chrysn says:

    hi,

    i (the one who wrote the python extension) would like to clarify a bit about the python part — it’s rather underdocumented atm:

    the python branch of embedvm is not intended to be a fully functional python implementation. it translates a very restricted subset of python to embedvm bytecode. “very restricted” currently means that all variables are either 16bit integers or integer arrays (the only kind of variable embedvm supports; arithmetics wrap instead of changing to long), no proper objects, no functional programming, not even proper imports (imports can be done, but there is a dispatch between being run in native python and compilation for embedvm).

    some of the shortcomings can be adressed, others probably won’t. (classes and objects — although only statically typed with inference from first assignment — seem possible; others, like dynamic typing, i don’t consider reasonable on this platform.) if that’s too far off from what you would like to call python, call it an ad-hoc language with python syntax.

    @jf (“loss in performance”): the idea is to have a system where all the hardware interaction stuff (where you need speed) is done in C, and gets bindings to the vm (the funny sounds it can play are a typical example). the vm then handles stuff that requires more flexibility (where you’d normally have to flash the microcontroller). it’s a tradeoff between flexibility and performance.

    @mp: while the vm is platform independent, its typical use is on atmega or attiny devices — which lack native floating point or 32bit support.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 94,508 other followers