[Wiki]Introduction to MicroPython under Pokitto Simulator


#1

MicroPython is an open source subset of the Python (v. 3) language. Python is an easy to learn, interpreted, and object oriented programming language. MicroPython does not contain all the Python libraries, because of the memory and performance restrictions of embedded systems. MicroPython has been made very configurable and the list of implemented features depends on the device the port is targeted to.

The Pokitto port of MicroPython also contains a very limited subset of the PyGame library to help you creating great games.

The MicroPython library comes with the Pokitto simulator. No special installing is needed after you have the simulator environment set up. Currently, only the windows environment is supported.

Running the demo python script

  1. Choose the “MicroPython” target
  2. Rebuild
  3. Run the program

You should now see the Frogitto demo running on the simulator window :slight_smile:

Running the interactive Python prompt

  1. In the Project window, select the file PokittoLib\Pokitto\POKITTO_LIBS\MicroPython\My_settings.h for editing
  2. Change the relevant line as follows: #define PROJ_PYTHON_REPL 1
  3. Rebuild
  4. Run the program

You should now see Python prompt in the simulator console window. The Pokitto main window has the Pokitto logo.

You can type in some python commands, like print(‘Hello World!’)

Making own Python scripts

The Python source files for the example are in the folder:
C:\git\PokittoLib2\Pokitto\POKITTO_LIBS\MicroPython\src_py
You change or replace the contents of the folder and make your own Python program. Any additional python scripts, which are imported to the example_main.py, should be placed in the same folder.

Debugging tip: If your python script repors an error, the console window is closed before you can see the error message. You can put a breakpoint to the end of PythonMain.cpp file, and start the simulator with debug button. Now you can see the error as the execution stops at the breakpoint and the console window is still open.

Using the interactive prompt

The interactive prompt is also called REPL, which means read-evaluate-print-loop.

It is excellent for testing single library functions or own code snippets. You can copy-paste a block of python code to REPL like this:

  1. Enter paste mode: ctrl + e.
  2. Paste the code block to the console window
  3. Run the pasted code: ctrl + d

When using the paste mode as described above, the spaces and tabs are preserved correctly.
The tab completion also works in the console. If you first import a library (e.g. “import gc”), you can see the available objects by typing: “gc.” + tab.

Instructions and references


#2

This is so great. Thank you @Hanski for hard work and an in-depth writeup!


#3

Thanks! While I want to stress that this is still preliminary version of the Pokitto MicroPython port, I also like to hear about any bugs you all face when testing this.


#4

2 posts were merged into an existing topic: Problem with PokittoSim