: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 the [[id:d97fde4a-0e91-40f9-ac57-d0cd67295d14][ESP8266]]. * 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./ * Documentation - [[https://docs.micropython.org/en/latest/index.html][Official documentation]] * Tools - [[https://docs.micropython.org/en/latest/reference/mpremote.html#][mpremote]] :: MicroPython remote control. Provides REPL access, editing, and file system mounting. * 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. /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./ 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.