Skip to content

Commit e579f79

Browse files
Small improvments
1 parent 3038b06 commit e579f79

File tree

1 file changed

+5
-6
lines changed
  • content/micropython/03.micropython/02.environment/04.runtime

1 file changed

+5
-6
lines changed

content/micropython/03.micropython/02.environment/04.runtime/runtime.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A **runtime environment** is the infrastructure that allows code to execute on a
1515

1616
For MicroPython, the runtime is a lightweight version of the Python runtime, optimized to work with the limited resources of microcontrollers. This means it has to manage memory efficiently, provide quick access to hardware components, and interpret Python code in real-time.
1717

18-
### How MicroPython's Runtime Works
18+
### MicroPython's Runtime
1919

2020
MicroPython's runtime environment consists of several key components:
2121

@@ -27,7 +27,7 @@ MicroPython's runtime environment consists of several key components:
2727

2828
4. **File System**: The runtime includes a file system, typically mounted on the microcontroller’s flash storage. This allows MicroPython to load and execute scripts, save configuration files, or store data persistently.
2929

30-
### Key Features of the MicroPython Runtime
30+
### MicroPython Runtime Features
3131

3232
1. **REPL (Read-Eval-Print Loop)**: One of the standout features of MicroPython's runtime is the REPL. The REPL is an interactive shell where we can type and execute Python code line by line, get immediate feedback, and test ideas quickly. It’s especially useful for debugging and learning how the hardware responds to different commands.
3333

@@ -37,15 +37,15 @@ MicroPython's runtime environment consists of several key components:
3737

3838
3. **Concurrency with `uasyncio`**: MicroPython provides support for asynchronous programming using the `uasyncio` module. This allows us to handle multiple tasks concurrently, such as reading a sensor while controlling an LED, without blocking the main program.
3939

40-
### Comparison to Standard Python
40+
### Micro vs Python
4141

4242
While MicroPython aims to be as compatible as possible with standard Python, there are some important differences due to the limited resources available on microcontrollers:
4343

4444
- **Memory Constraints**: Standard Python runs on desktops or servers with abundant RAM, but MicroPython runs on devices with as little as 16KB to 512KB of RAM. The runtime is optimized to be efficient, but we must be mindful of memory usage.
4545
- **Limited Libraries**: Many of Python’s standard libraries are unavailable in MicroPython because they are too large or not relevant for embedded systems. However, MicroPython provides specialized libraries for hardware interaction.
4646
- **Performance**: MicroPython is generally slower than compiled languages, but it’s fast enough for most embedded applications thanks to its lightweight runtime and efficient interpreter.
4747

48-
## How Code Execution Works in MicroPython
48+
## Code Execution Works in MicroPython
4949

5050
When we upload a MicroPython script to our microcontroller, the runtime handles code execution as follows:
5151

@@ -54,8 +54,7 @@ When we upload a MicroPython script to our microcontroller, the runtime handles
5454
3. **Hardware Interaction**: The runtime communicates with the microcontroller’s hardware through built-in libraries. For example, we can control GPIO pins, read sensor data, or send data over I2C using simple Python commands.
5555
4. **Error Handling**: MicroPython includes mechanisms for error handling and debugging. If the script encounters an error, the runtime will stop execution and display an error message in the REPL or console.
5656

57-
## Best Practices for Working with the MicroPython Runtime
58-
57+
## Best Practices
5958
1. **Manage Memory Wisely**: Be mindful of memory usage, especially when working with large data structures or performing frequent allocations. Use the garbage collector [(`gc`)](https://docs.micropython.org/en/latest/library/gc.html) if you need to manually free up memory.
6059
2. **Use REPL for Testing**: Take advantage of the REPL to experiment and debug code interactively. This can save time and help you understand how your code interacts with the hardware.
6160
3. **Optimize Code for Speed and Efficiency**: Use efficient data structures and algorithms to keep your code fast and responsive. Avoid blocking operations when possible, and consider using `uasyncio` for concurrency.

0 commit comments

Comments
 (0)