2023-02-08 06:44:22 +00:00
:PROPERTIES:
:ID: 6cd321bb-34bf-4a93-96f6-a9ef93257bd1
:END:
#+title : MicroPython
A pared down version of [[id:cda9c620-fec5-4549-b979-22fc06819d77 ][Python ]] designed for programming [[id:c412e81c-9271-4224-89b7-315a4b89968e ][Microcontrollers ]] like
2023-03-21 04:40:28 +00:00
the [[id:d97fde4a-0e91-40f9-ac57-d0cd67295d14 ][ESP8266 ]].
2023-03-21 05:04:20 +00:00
* REPL
The [[https://docs.micropython.org/en/latest/reference/repl.html ][MicroPython REPL ]] is available through a device's serial interface. It
functions in two modes:
- Friendly :: A user-friendly REPL with indentation and tab completion.
Evaluation is echoed back. Indentation may be temporarily disabled toggling
"paste mode" with =Ctrl+E= . Execution may be interrupted with =Ctrl+C= .
- Raw :: A machine-friendly REPL for tools to provide raw code to be executed.
Essentially functions similar to the friendly REPL in paste mode, without
output echoing. /Note: Automatic startup/soft-reset execution of =main.py= is
disabled while the REPL is in raw mode./
2023-02-08 06:44:22 +00:00
* Documentation
- [[https://docs.micropython.org/en/latest/index.html ][Official documentation ]]
2023-03-21 05:04:20 +00:00
2023-02-08 06:44:22 +00:00
* Tools
- [[https://docs.micropython.org/en/latest/reference/mpremote.html#][mpremote]] :: MicroPython remote control. Provides REPL access, editing, and
file system mounting.
2023-03-21 04:40:28 +00:00
* Questions
** What files does the MicroPython firmware expect to find?
- =boot.py= :: Performs initialization when the device is powered up.
- =main.py= :: If present (and no errors occurred while executing =boot.py= ), it
is executed after =boot.py= and functions as an application code entry point.
2023-03-21 05:04:20 +00:00
/Execution of this file is skipped if the REPL is not in "friendly" mode, e.g.
if a tool has switched to the "raw" REPL./
2023-03-21 05:11:39 +00:00
The =mpremote= tool uses the raw REPL to execute its commands, including
performing a soft reset. Therefore, it is advisable to keep application code
(particularly application loops) in =main.py= rather than =boot.py= so that
=mpremote= commands aren't blocked by running application code. This way,
application code is only executed when requested explicitly while developing,
but will still execute automatically during a normal device boot.