Skip to content

Commit 195400b

Browse files
authored
Merge pull request #2271 from arduino/karlsoderby/review-ecosystem
[PXCT-198] review ecosystem
2 parents f545c55 + 0d307ec commit 195400b

File tree

6 files changed

+93
-63
lines changed

6 files changed

+93
-63
lines changed

content/micropython/03.micropython/02.enviroment/01.code-editor/code-editor.md renamed to content/micropython/03.micropython/02.environment/01.code-editor/code-editor.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
---
2-
featured: micropython-101
3-
title: '2. Micropython Environment - Editor'
2+
title: 'Code Editor'
43
description: 'Learn the basics for loops on MicroPython.'
54
author: 'Pedro Lima'
6-
hero_image: "./hero-banner.png"
5+
tags: [MicroPython, Arduino Lab for MicroPython]
76
---
87

9-
Arduino Labs for MicroPython includes a user-friendly code editor that helps us write, format, and run MicroPython code with ease. In this article, we’ll explore how the code editor works, key formatting rules for MicroPython, and some useful tips to keep our code clean and error-free.
8+
Arduino Lab for MicroPython includes a user-friendly code editor that helps us write, format, and run MicroPython code with ease. In this article, we’ll explore how the code editor works, key formatting rules for MicroPython, and some useful tips to keep our code clean and error-free.
109

11-
## The Code Editor in Arduino Labs for MicroPython
10+
## Requirements
11+
12+
- [Arduino Lab for MicroPython]()
13+
- **MicroPython compatible board** (not required for using the editor, but for running any code).
14+
15+
***Note that the Arduino Lab for MicroPython is now also available online, as part of the Arduino Cloud platform. You will find it here: [Arduino Cloud - Arduino Lab for MicroPython]().***
16+
17+
## Arduino Labs for MicroPython
1218

1319
The code editor in Arduino Labs is designed to streamline our coding experience, providing tools to:
1420

@@ -18,6 +24,24 @@ The code editor in Arduino Labs is designed to streamline our coding experience,
1824

1925
As we get familiar with the editor, remember that MicroPython has a few syntax rules that differ from other languages we might know.
2026

27+
### Overview
28+
29+
Text / bullet points here summarizing e.g. buttons and icons in the editor.
30+
31+
![Overview of the code editor.]()
32+
33+
### Files
34+
35+
Text / bullet points here for how to manage files (and point to the file system tutorial)
36+
37+
![Managing files in Arduino Lab for MicroPython]()
38+
39+
### REPL
40+
41+
Text / bullet points here for where the REPL is and how it works (and point to the REPL tutorial)
42+
43+
![The REPL.]()
44+
2145
## Indentation
2246

2347
In MicroPython, indentation (using spaces or tabs) is essential for defining the structure of our code. Unlike many other languages, MicroPython relies on indentation instead of symbols like `{ }` to define code blocks.
@@ -104,9 +128,4 @@ Here are a few quick tips to make the most of our time in the code editor:
104128
- **Use Descriptive Names**: Name variables and functions clearly to make the code readable.
105129
- **Keep It Modular**: Split complex code into functions for easier maintenance.
106130
- **Comment as We Go**: Leave helpful comments explaining why we wrote certain sections of code.
107-
- **Indent Carefully**: Pay attention to indentation for clean, error-free code.
108-
109-
## Try It Out
110-
111-
- **Experiment with Indentation**: Try writing a few functions with nested loops or conditionals to get comfortable with indentation.
112-
- **Add Comments**: Document a small code snippet with comments explaining each part.
131+
- **Indent Carefully**: Pay attention to indentation for clean, error-free code.
File renamed without changes.

content/micropython/03.micropython/02.enviroment/02.file-system/file-system.md renamed to content/micropython/03.micropython/02.environment/02.file-system/file-system.md

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
title: 'File System'
33
description: 'Learn how to use the File Sytem in MicroPython.'
44
author: 'Pedro Lima'
5-
tags: [MicroPython, REPL]
5+
tags: [MicroPython, File System]
66
---
77

8+
When working with MicroPython, we’re not limited to a single program file like in traditional Arduino sketches (using C++). Instead, MicroPython provides a file system, enabling us to store and manage multiple files on our microcontroller. This opens up powerful capabilities for organizing code, managing assets, and creating modular projects.
89

9-
When working with MicroPython, we’re not limited to a single program like in traditional Arduino sketches. Instead, MicroPython provides a file system, enabling us to store and manage multiple files on our microcontroller. This opens up powerful capabilities for organizing code, managing assets, and creating modular projects.
10-
11-
In this article, we’ll explore how the MicroPython file system works, how to organize files effectively, and the typical structure of MicroPython projects.
10+
In this article, we'll explore how the MicroPython file system works, how to organize files effectively, and the typical structure of MicroPython projects.
1211

1312
## The MicroPython File System: Key Differences
1413

15-
In traditional Arduino programming, we upload a single compiled file directly to the microcontroller, where it runs immediately. With MicroPython, however, we work within a file system that can store multiple files. This file system allows us to:
14+
In traditional Arduino programming, we upload a single compiled file directly to the microcontroller, where it runs immediately. In MicroPython we work within a file system that can store multiple files. This file system allows us to:
1615

1716
- **Upload and Download Files**: We can save individual scripts, libraries, and assets directly on the device.
1817
- **Organize Project Files**: Create folders, save multiple scripts, and organize files for a modular approach.
1918
- **Edit Files Directly on the Device**: Modify files without needing to overwrite everything, making adjustments faster and more flexible.
19+
- **Run Different Scripts**: while we have `boot.py` (runs at start) and `main.py` (runs after start), we can also create more scripts that we can run, either from the editor, or from the board itself.
2020

2121
## Accessing the MicroPython File System
2222

@@ -26,9 +26,11 @@ To interact with the MicroPython file system, we’ll use Arduino Labs for Micro
2626
2. **Upload and Download Files**: Use the file manager to upload files from our computer to the microcontroller or download files back to our computer.
2727
3. **Organize Files**: We can create folders and store multiple files, making it easy to organize our project.
2828

29+
![Accessing the file system.]()
30+
2931
## Basic MicroPython File Structure
3032

31-
A typical MicroPython project includes a main file, boot script, libraries, and any supporting files our project needs. Here’s a standard layout:
33+
A typical MicroPython project includes a `main.py` file, `boot.py` file, libraries, and any supporting files our project needs. Here’s a standard layout:
3234

3335
```
3436
/ (Root Directory)
@@ -41,59 +43,64 @@ A typical MicroPython project includes a main file, boot script, libraries, and
4143
- **`boot.py`**: Runs once at startup, before `main.py`, and is typically used for system configurations that need to be set when the device first powers on.
4244
- **`main.py`**: This is the primary script, similar to the `setup()` and `loop()` structure in Arduino. It runs automatically after `boot.py` finishes.
4345

44-
## Example: Switching Execution from `main.py` to `favorite_things.py`
46+
## Example: Importing Code from Scripts
4547

46-
Let’s say we’re creating a project where `main.py` runs and, at a certain point, hands off control to `favorite_things.py` to perform a specific task. Here’s how we might organize it.
48+
With the MicroPython file system, we can create our own scripts and import them in the `main.py` script. This can be helpful in avoiding long scripts, as we instead can store the code in other files. This approach also makes it more modular.
4749

48-
1. **Write the Main Script** (`main.py`): This script runs some initial code and then switches to executing `favorite_things.py`.
49-
2.Create the file "favourite_things.py".
50-
3. **Add Content to `favorite_things.py`**: In this case, we’ll simply print a message from `favorite_things.py`.
50+
To run code from a separate script in our `main.py` file, we can follow the instructions below:
5151

52-
### Sample `main.py` Code
52+
1. Create a file named `my_new_script.py`, and add the following function:
5353

54-
Here’s how `main.py` might look, printing an introductory message and then executing `favorite_things.py`:
54+
```python
55+
def test():
56+
print("This runs from my_new_script.py")
57+
```
5558

56-
```python
57-
def main():
58-
print("Getting the list of my favourite things...")
59+
2. In `main.py`, we run some initial code and then switches to executing a function from `my_new_script.py`. Here's an example:
5960

60-
# Now execute favorite_things.py
61-
print("Switch to favorite_things.py...")
62-
try:
63-
with open("favorite_things.py") as f:
64-
exec(f.read())
65-
except OSError:
66-
print("Error: Could not open favorite_things.py")
67-
68-
if __name__ == "__main__":
69-
main()
70-
```
61+
```python
62+
import my_new_script
63+
print("This runs from main.py")
7164

72-
### Sample `favorite_things.py` Code
65+
my_new_script.test()
66+
```
7367

74-
In `favorite_things.py`, we’ll keep it simple with a message:
68+
3. Check the REPL, we should see:
7569

76-
```python
77-
# favorite_things.py
78-
print("Bears. Beets. Battlestar Galactica.")
79-
```
70+
```bash
71+
This runs from main.py # executed from main.py
72+
This runs from my_new_script.py #executed from my_new_script.py
73+
```
8074

81-
### Explanation
75+
Essentially, this is how [modules]() work. You import a module, and use a function from that module.
8276

83-
- **Switching Execution**: `main.py` starts by printing an introductory message, and then uses `exec(f.read())` to read and run the content of `favorite_things.py`.
84-
- **Running Another Script**: The `exec()` function allows `main.py` to execute `favorite_things.py` as if it were part of `main.py`, printing “Bears. Beets. Battlestar Galactica.” directly.
77+
![Import code from a script.]()
8578

86-
### Expected Output
79+
## Example: Directly Executing a Script
8780

88-
When you run `main.py`, the output should look like this:
81+
We can also directly execute another script stored on the device. For this example, let's create a script and name it `run_directly.py`.
8982

90-
```
91-
Getting the list of my favourite things...
92-
Switch to favorite_things.py...
93-
Bears. Beets. Battlestar Galactica.
94-
```
83+
1. In the script, store this code:
84+
85+
```python
86+
print("I was run from main.py")
87+
```
88+
89+
2. Then in `main.py`, we will use the `open()`, `exec()` and `read()` functions.
90+
91+
```python
92+
with open("run_directly.py") as f:
93+
exec(f.read())
94+
```
95+
96+
- `open()` - opens a file
97+
- `exec()` - executes a file
98+
- `read()` - reads a file
99+
100+
As a result, we should read `"I was run from main.py"` in the REPL. How this differs from the previous example, is that the `run_directly.py` script was just run from top to bottom, as opposed to importing a specific segment of code.
101+
102+
![Executing a script directly.]()
95103

96-
This setup demonstrates how to use MicroPython’s file system to organize and execute multiple scripts, allowing for modular and readable code.
97104

98105
## Organizing Code with Modules and Libraries
99106

content/micropython/03.micropython/02.enviroment/03.modules/modules.md renamed to content/micropython/03.micropython/02.environment/03.modules/modules.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: 'Modules'
3-
description: 'Understanding Modules and how to use them.'
3+
description: 'Understanding modules in MicroPython and how to use them.'
44
author: 'Pedro Lima'
55
tags: [MicroPython, Modules]
66
---
77

88

9-
In this article, we’ll cover how modules work in MicroPython, explore a few built-in modules, and demonstrate how to install an external package like Modulino to extend our MicroPython project’s functionality.
9+
In this guide, we’ll cover how modules work in MicroPython, explore a few built-in modules, and demonstrate how to install an external package like Modulino to extend our MicroPython project’s functionality.
1010

1111
## What Are Modules?
1212

@@ -38,7 +38,7 @@ In this example, `time.sleep()` introduces a delay. Built-in modules like `time`
3838

3939
## External Modules
4040

41-
Some modules aren’t included with the default MicroPython installation and need to be installed separately. External modules, often provided by the community or specific hardware packages, extend MicroPython’s functionality. For example, the **Modulino** library is an external module that provides tools for working with Arduino Modulinos.
41+
Some modules aren’t included with the default MicroPython installation and need to be installed separately. External modules, often provided by the community or specific hardware packages, extend MicroPython’s functionality. For example, the [Modulino library]() is an external module that provides tools for working with Arduino Modulinos.
4242

4343
To demonstrate how to use external modules, we’ll go through the steps to install the Modulino package on an Arduino board.
4444

@@ -51,37 +51,41 @@ Before we can install external modules, we need to have MicroPython running on o
5151
- Press the "Refresh" button if the board does not appear.
5252
- Click "**Install MicroPython**" and wait for the installation to complete.
5353

54+
***For more details, visit the [MicroPython installation guide]()***
55+
5456
### Step 2: Install the Modulino Package
5557

5658
To install the Modulino package, we’ll use `mpremote`, a tool that allows us to install MicroPython packages directly onto our board from the command line.
5759

58-
1. **Install `mpremote`**: Make sure Python is installed on your computer, then open a terminal and type:
60+
1. Make sure Python is installed on your computer
61+
2. Open a terminal on your machine.
62+
3. Run the following command to install `mpremote`.
5963

6064
```bash
6165
pip install mpremote
6266
```
6367

64-
2. **Connect to Your Board**: Find your boards serial port by running:
68+
4. With `mpremote` installed, run the following script to find our board's serial port.
6569

6670
```bash
6771
mpremote connect list
6872
```
6973

70-
This command should return something like:
74+
This command should return something akin to:
7175

7276
```bash
7377
/dev/cu.usbmodem101 ecda3b60a4dccb3f 2341:056b Arduino Nano ESP32
7478
```
7579

7680
- Copy the port, e.g., `/dev/cu.usbmodem101`.
7781

78-
3. **Install the Modulino Package**: Use the following command to install the Modulino package, replacing `<PORT>` with your board’s port:
82+
5. Use the following command to install the Modulino package (or any other package we want to install), replacing `<PORT>` with our board’s port retrieved in the previous step.
7983

8084
```bash
8185
mpremote connect <PORT> mip install github:arduino/arduino-modulino-mpy
8286
```
8387

84-
4. **Verify Installation**: After installation, check Arduino Labs for MicroPython. You should see a `/lib` folder with the Modulino library inside, indicating a successful installation.
88+
6. After the installation, open Arduino Labs for MicroPython, and connect your board. In the board's files, we should see a `/lib` folder with the Modulino library inside, indicating a successful installation.
8589

8690
![MicroPython Lab Files](./assets/microPythonLabsFiles.png)
8791

File renamed without changes.

0 commit comments

Comments
 (0)