You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/micropython/03.micropython/00.first-steps/00.into-micropython/intro-micropython.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,23 @@ author: 'Pedro Lima'
6
6
hero_image: "./hero-banner.png"
7
7
---
8
8
9
-
# Intro to MicroPython
10
-
11
9
MicroPython is a lightweight implementation of Python 3 designed to run on microcontrollers and embedded systems. Think of it as a mini-version of Python, tailored for hardware with limited resources like memory and processing power. Despite its smaller size, MicroPython retains the simplicity and flexibility of Python, making it an excellent option for programming hardware.
12
10
13
11
## MicroPython on Arduino Boards
14
12
15
-
When using MicroPython on Arduino boards, the language is installed directly onto the microcontroller. This allows the board to interpret and run Python code. Once MicroPython is installed on your board (don't worry, we'll cover installation in a future article), you can start writing and executing Python scripts instantly.
13
+
![Placeholder graphic]()
14
+
15
+
When using MicroPython on Arduino boards, the software is first installed on your Arduino. This allows the board to interpret and run Python code. Once MicroPython is installed on your board (don't worry, we'll cover this [here]()), you can start writing and executing Python scripts instantly.
16
16
17
-
Unlike traditional development approaches, where you compile code and then flash it to the board, with MicroPython you write Python scripts and load them directly onto the microcontroller. This makes the development process much faster and more interactive.
17
+
Unlike traditional development approaches, where you compile code and then flash it to the board, with MicroPython you write Python scripts and run them instantly on your Arduino. This makes the development process much faster and more interactive.
18
18
19
19
## Running Programs in MicroPython
20
20
21
21
Once MicroPython is installed, you can start programming by writing scripts and uploading them to the board. These scripts are interpreted in real-time, meaning you can make quick changes and see immediate results, streamlining the development process.
22
22
23
-
TODO: Image of code edit with imediate change
23
+
![TODO: Image of code edit with immediate change]()
24
24
25
-
MicroPython also includes a simple file system where your scripts are stored. For example, when you write a script, it is saved directly on the board and can be executed immediately without compiling.
25
+
MicroPython also includes a simple file system where your scripts are stored. For example, when you write a script, it is saved directly on the board and can be executed immediately without compiling. You can also save other scripts that can be activated from the main script!
26
26
27
27
### How it Works
28
28
@@ -36,21 +36,21 @@ The MicroPython installation includes several key components:
36
36
37
37
2.**Base Modules**: MicroPython comes with built-in modules for working with hardware like pins, sensors, and communication protocols (I2C, SPI, etc.). This includes essential modules like `machine`, `network`, and `time`.
38
38
39
-
TODO: A diagram showing how `boot.py` and `main.py` are loaded during the boot process and how they fit into the file system could be useful here.
39
+
![TODO: A diagram showing how `boot.py` and `main.py` are loaded during the boot process and how they fit into the file system could be useful here.]()
40
40
41
41
## How to Program for MicroPython
42
42
43
-
Programming in MicroPython involves writing Python scripts in a text editor and uploading them to the board. Many IDEs, like Thonny or even Arduino IDE, provide support for MicroPython, allowing you to write and upload code easily.
43
+
Programming in MicroPython involves writing Python scripts in a text editor and then running them on your board. For this, we can use the [Arduino Lab for MicroPython]().
44
44
45
45
When writing MicroPython code, it's essential to think in terms of **modularity**. A good practice is to break down your code into smaller, reusable modules rather than writing everything in one large file. This approach makes it easier to manage and maintain code, especially for larger projects.
46
46
47
47
### Structuring Your Code
48
48
49
-
1.**Main Logic**: This would typically go into `main.py`. You can think of it as your "sketch" in Arduino terms.
49
+
1.**Main Logic**: This goes into the `main.py` file. You can think of it as your "sketch" in Arduino terms.
50
50
2.**Helper Modules**: Break down your code into smaller modules for specific tasks, such as controlling a sensor or managing a display. These modules can be imported into `main.py` as needed.
51
51
3.**Interrupts and Background Tasks**: If you're dealing with hardware, you may also need to work with interrupts or periodic tasks, which can be handled in dedicated modules.
52
52
53
-
TODO: A flowchart here could be beneficial to illustrate how to structure a MicroPython project, with `main.py` at the top and helper modules branching off.
53
+
![TODO: A flowchart here could be beneficial to illustrate how to structure a MicroPython project, with `main.py` at the top and helper modules branching off.]()
54
54
55
55
## MicroPython vs. C++ for Electronics Projects
56
56
@@ -60,6 +60,6 @@ MicroPython offers a different approach to programming compared to the tradition
60
60
-**Real-Time Interactivity**: With MicroPython, you can write and test code interactively, without needing to compile. This makes it faster to experiment and troubleshoot hardware setups.
61
61
-**Resource Efficiency**: C++ is more efficient in terms of memory and speed, making it a better option for projects that need to squeeze every bit of performance out of the hardware. MicroPython, on the other hand, prioritizes ease of development over raw performance, but it is still capable of handling many common hardware tasks.
62
62
63
-
TODO: A side-by-side table comparing typical tasks (like reading a sensor or blinking an LED) in MicroPython and C++ could help illustrate the differences.
63
+
![TODO: A side-by-side table comparing typical tasks (like reading a sensor or blinking an LED) in MicroPython and C++ could help illustrate the differences.]()
64
64
65
65
In summary, MicroPython provides a powerful and flexible way to develop electronic projects, especially for those familiar with Python. Its ability to run on microcontrollers like Arduino boards makes it an attractive option for both beginners and experienced developers who want a fast and efficient workflow.
0 commit comments