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
- Choose the “MicroPython” target
- Run the program
You should now see the Frogitto demo running on the simulator window
Running the interactive Python prompt
- In the Project window, select the file
- Change the relevant line as follows:
#define PROJ_PYTHON_REPL 1
- 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:
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:
- Enter paste mode: ctrl + e.
- Paste the code block to the console window
- 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
- Using REPL: https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/repl.html#using-the-repl
- MicroPython homepage: https://micropython.org/
- Python homepage: https://www.python.org/
- PyGame homepage: http://www.pygame.org/