From LeafLabs
Jump to: navigation, search

Python-on-a-Chip (P14P) is software for running Python (via the PyMite virtual machine) on microcontrollers without an OS.


[edit] PyMite port for Maple

PyMite takes up a relatively large amount of room: roughly 73kB in Flash and 40kB in RAM. Although the size in RAM can be adjusted, the large resource footprint restricts PyMite to either Maple RET6 or Maple Native.

[edit] Maple Native Support

What good is Python if all you can do is print "Hi" and set variables? PyMite is capable of controlling all the peripherals of Maple. The libraries are a work in progress, but blinking the LED is fully supported at this time.

[edit] How to Build

  • The command-line toolchain must be installed and the environmental variable $LIB_MAPLE_HOME must be exported for the Makefile to find it
  • unfortunately PyMite is extremely sensitive to the version of Python being used on the host and as of now the only version that has successfully been tested is Python 2.6.5. One easy way to get this done (on Ubuntu) is by obtaining the source, making and install it then changing the symbolic link within /usr/bin/python2.6 to point to python2.6.5. If you don't want to change your symbolic link for python2.6 you can change scripts within pmvm/tools to point to your local version of 2.6.5
  • PySerial is required to communicate with the MCU and if downgrading/upgrading to Python 2.6.5 is required, then so is installing PySerial for Python 2.6.5. Ugh. Download the source from pyserial and after setting up Python 2.6.5 go into that directory and type
   $ python2.6 ./
  • get our source from GitHub:
   $ git clone git://
  • change to the pmvm/platform/maple directory
  • run
   $ make clean
   $ make
   $ make install

The compiled program should upload to the Maple Native.

[edit] How to set up Interactive PyMite (IPM)

Interactive Pymite IPM requires a Python script on the host to communicate with the MCU interpreter. You'll also need a USB-to-serial adapter to connect to the Maple Native. Connect the adapter to Serial3 TX and RX (pins 0 and 1). (Don't forget to ground the adapter as appropriate).

Here's how to start it up:

In the pmvm/platform/maple directory,

   $ ../../tools/ -f --serial=/dev/<Serial Device> --baud=<Baudrate>

As an example, my TTL USB serial device is found at /dev/ttyUSB0 and has a baudrate of 115200, so I type:

   $ ../../tools/ -f --serial=/dev/ttyUSB0 --baud=115200

It's possible to use the built in USB Serial port, but both main.cpp and plat.cpp must be modified.

[edit] Working with Interactive PyMite (IPM)

Just type Python at the prompt:

   ipm> print "hi"
   ipm> x = 4
   ipm> x

It's possible to control the Maple Native's hardware from the prompt as well. As an example, the following code can be typed into IPM at runtime to toggle the LED every second:

   import maple
   import sys
   x = 0
   while (True):
       if (sys.time() > x + 1000):
           x = sys.time()
Personal tools