Skip to content

Commit 5b32259

Browse files
committed
Improve content
- Rewrite external module section - fix spi illustration to show c1 and c2 - fix code snippets for ext. modules.
1 parent ceee816 commit 5b32259

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

content/micropython-course/course/01.introduction-python/02.intro-to-micropython.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,64 @@ For example, to use a module for a specific sensor, we need to install it **exte
146146

147147
### Install External Modules
148148

149-
To install an external module, we are going to use something called `mip`. With `mip`, we can install a module on the board directly, by connecting to Wi-Fi and downloading the module directly to the board. So how do we do this?
149+
To install an external module, we are going to use a package manager called `mip`. With `mip`, we can install a module on the board by connecting to Wi-Fi® and downloading the module directly to the board. So how do we do this?
150150

151-
Below is a script that first connects to Wi-Fi®, and then downloads a specific module. In this case, we will provide a URL to a file stored on GitHub (the raw file). In this case, we will install the `lis3dh` module, which will be used later on in this course.
151+
To download external modules from the internet we first a foremost need a working internet connection. To connect to your local Wi-Fi you can upload the following script to your `boot.py` file. Why `boot.py`?
152152

153-
Please note that you need to add your own Wi-Fi® network and password in the `WIFI_NETWORK` and `WIFI_PASSWORD` fields.
153+
Because we want to make sure our board connects to the internet as soon as it boots up.
154+
155+
***Please note that you need to add your own Wi-Fi network and password in the `WIFI_NETWORK` and `WIFI_PASSWORD` fields.***
156+
157+
![Wi-Fi script inside boot.py](./assets/boot.png)
158+
159+
**Connect to Wi-Fi**
154160

155161
```python
156162
"""
157-
This script first connects to Wi-Fi,
158-
then installs the module specified
159-
in the URL variable.
163+
This script connects to Wi-Fi
160164
"""
161165

162166
import network
163-
import mip
164167

165168
WIFI_NETWORK='YOUR_NETWORK_NAME'
166169
WIFI_PASSWORD='YOUR_NETWORK_PASSWORD'
167170

168-
# add the URL of the module you want to install
169-
URL = "https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py"
170-
171171
wlan = network.WLAN(network.STA_IF)
172172
wlan.active(True)
173173
wlan.connect(WIFI_NETWORK, WIFI_PASSWORD)
174174

175175
print()
176176
print("Connected to ",WIFI_NETWORK)
177+
```
178+
Press run and you should see `Connected to <your Wi-Fi>` being printed inside the REPL.
179+
180+
![Successful connection](./assets/wifiConnected.png)
181+
182+
Next, you need to run a script that installs the external module from a specific url. Place the following script inside `main.py` and press run.
183+
184+
![Module installation script inside main.py](./assets/main.png)
177185

178-
mip.install(URL)
186+
**Install external module**
187+
```python
188+
'''
189+
This script installs external modules using mip
190+
'''
191+
192+
import mip
193+
mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py")
179194
```
180195

181-
Once you run the script successfully, you will have installed the module on your board.
196+
Press run and you should see the following inside the REPL:
197+
198+
![Successful download](./assets/download.png)
199+
200+
In this case, we will provide a URL to a file stored on GitHub (the raw file). The script installs the `lis3dh` module, which will be used later on in this course.
201+
202+
You can verify that the module was installed correctly by pressing `Files` and checking inside the `lib` folder. You should see a file called `lis3dh.py` inside.
203+
204+
![Installed module](./assets/libFolderIn.png)
205+
206+
When asked later in the course to install external modules simply paste the provided script into `main.py` and press run.
182207

183208
### Removing Modules
184209

@@ -215,9 +240,9 @@ OSError: -202
215240

216241
Some things to check are:
217242
- Did you enter your network credentials properly?
218-
- Did you already connect to Wi-Fi®?
243+
- Did you already connect to Wi-Fi?
219244

220-
If the error persist, you can try to "soft-reset" the board, by clicking the **"Reset"** button, and run the script again.
245+
If the error persists, you can try to "soft-reset" the board, by clicking the **"Reset"** button, and run the script again.
221246

222247
![](assets/reset.png)
223248

136 KB
Loading
142 KB
Loading
103 KB
Loading
104 KB
Loading
157 KB
Loading
4.55 KB
Loading

content/micropython-course/course/08.examples/examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ This example demonstrates how to use an [OLED](https://store.arduino.cc/products
287287
This module is not part of the MicroPython installation, and needs to be installed via the following command:
288288

289289
```python
290+
import mip
290291
mip.install("https://raw.githubusercontent.com/micropython/micropython-lib/master/micropython/drivers/display/ssd1306/ssd1306.py")
291292
```
292293

@@ -386,6 +387,7 @@ This example shows how to use a [Grove Accelerometer](https://store.arduino.cc/p
386387
This module is not part of the MicroPython installation, and needs to be installed via the following command:
387388

388389
```python
390+
import mip
389391
mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py")
390392
```
391393

@@ -502,6 +504,7 @@ This example shows how to use a [Grove 4-digit display](https://store.arduino.cc
502504
This module is not part of the MicroPython installation, and needs to be installed via the following command:
503505

504506
```python
507+
import mip
505508
mip.install("https://raw.githubusercontent.com/mcauser/micropython-tm1637/master/tm1637.py")
506509
```
507510

0 commit comments

Comments
 (0)