Search code examples
pythoncontiki

Contiki and Python


I have come across Contiki recently and looks like a really interesting platform for many awesome projects. Contiki uses C for developing its applications. So what I want to ask about is whether Python can be used instead of C?!


Solution

  • As @morty pointed out, Python requires a runtime to be executed. So, as in any operating system you need a native interpreter for the bytecode.

    Most python interpreters could not fit on a constrained device where Contiki would run but there is a very nice project called Python-on-a-chip http://code.google.com/p/python-on-a-chip/

    From the main page

    Welcome! Python-on-a-Chip (p14p) is a project to develop a reduced Python virtual machine (codenamed PyMite) that runs a significant subset of the Python language on microcontrollers without an OS. The other parts of p14p are the device drivers, high-level libraries and other tools.

    Be aware of what PyMite can or cannot do:

    Features of the PyMite VM:

    • Requires roughly 55 KB program memory
    • Initializes in 4KB RAM; print "hello world" needs 5KB; 8KB is the minimum recommended RAM.
    • Supports integers, floats, tuples, lists, dicts, functions, modules, classes, generators, decorators and closures
    • Supports 25 of 29 keywords and 89 of 112 bytecodes from Python 2.6
    • Can run multiple stackless green threads (round-robin)
    • Has a mark-sweep garbage collector
    • Has a hosted interactive prompt for live coding
    • Licensed under the GNU GPL ver. 2

    The PyMite VM DOES NOT HAVE:

    • A built-in compiler
    • Any of Python's libraries (no batteries included)
    • A ready-to-go solution for the beginner (you need to know C and how to work with microcontrollers)

    An interesting project on top of PyMite is https://github.com/tecip-nes/contiki-tres, a programming abstraction framework for IoT-based WSNs.