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/02.environment/02.file-system/file-system.md
+17-16
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ When working with MicroPython, we’re not limited to a single program file like
9
9
10
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.
11
11
12
+
12
13
## The MicroPython File System: Key Differences
13
14
14
15
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:
@@ -26,7 +27,7 @@ To interact with the MicroPython file system, we’ll use Arduino Labs for Micro
26
27
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.
27
28
3.**Organize Files**: We can create folders and store multiple files, making it easy to organize our project.
@@ -51,30 +52,30 @@ To run code from a separate script in our `main.py` file, we can follow the inst
51
52
52
53
1. Create a file named `my_new_script.py`, and add the following function:
53
54
54
-
```python
55
-
deftest():
56
-
print("This runs from my_new_script.py")
57
-
```
55
+
```python
56
+
deftest():
57
+
print("This runs from my_new_script.py")
58
+
```
58
59
59
60
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:
60
61
61
-
```python
62
-
import my_new_script
63
-
print("This runs from main.py")
62
+
```python
63
+
import my_new_script
64
+
print("This runs from main.py")
64
65
65
-
my_new_script.test()
66
-
```
66
+
my_new_script.test()
67
+
```
67
68
68
69
3. Check the REPL, we should see:
69
70
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
-
```
71
+
```bash
72
+
This runs from main.py # executed from main.py
73
+
This runs from my_new_script #executed from my_new_script
74
+
```
74
75
75
76
Essentially, this is how [modules]() work. You import a module, and use a function from that module.
76
77
77
-
![Import code from a script.]()
78
+

78
79
79
80
## Example: Directly Executing a Script
80
81
@@ -99,7 +100,7 @@ We can also directly execute another script stored on the device. For this examp
99
100
100
101
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
102
-
![Executing a script directly.]()
103
+

0 commit comments