Skip to content

Commit c76e493

Browse files
authored
Merge pull request #1388 from arduino/karlsoderby/mp-install-libs
[MicroPython] Install/remove modules
2 parents 7d80c86 + 1863e78 commit c76e493

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

content/micropython/01.basics/02.board-installation/board-installation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ So what do you need to start your first project with MicroPython and Arduino? Fi
1111

1212
In order to understand which board is more suitable to your project, you can visit the documentation of each board.
1313

14+
## Supported Boards
15+
16+
The following boards support MicroPython:
17+
- [Nano BLE](https://store.arduino.cc/products/arduino-nano-33-ble) / [Nano BLE Sense](https://store.arduino.cc/products/arduino-nano-33-ble-sense) / [Nano BLE Sense Rev2](https://store.arduino.cc/products/nano-33-ble-sense-rev2)
18+
- [Nano RP2040 Connect](https://store.arduino.cc/products/arduino-nano-rp2040-connect)
19+
- [Nano ESP32](https://store.arduino.cc/products/nano-esp32)
20+
- [Nicla Vision](https://store.arduino.cc/products/nicla-vision)
21+
- [GIGA R1 WiFi](https://store.arduino.cc/products/giga-r1-wifi)
22+
- [Portenta H7](https://store.arduino.cc/collections/portenta-family/products/portenta-h7)
23+
- [Portenta C33](https://store.arduino.cc/collections/portenta-family/products/portenta-c33)
24+
25+
1426
## Arduino MicroPython Installer
1527

1628
We have developed a tool for installing the MicroPython firmware to your Arduino boards with a simple click. This tool lets you plug in the board, select it from a menu, and automatically flash the latest firmware, or a custom one of your choice to the board.
Loading
Loading
Loading
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: Installing Modules
3+
description: Learn how to install and remove external modules on your Arduino board.
4+
author: Karl Söderby
5+
micropython_type: basics
6+
hero_image: "./hero-banner.png"
7+
---
8+
9+
Your MicroPython installation comes with a set of modules built-in to the firmware. If you are using any external components such as sensors, displays or neopixels, you will need to install these manually.
10+
11+
There are currently two methods available when installing a module on your board running MicroPython:
12+
- Using the `mip` module on your **board**, (download and install via Wi-Fi® connection),
13+
- using `mpremote` on your **computer** (download and install through a USB connection),
14+
15+
In this article, we will cover these two methods, as well as how to remove them from your board.
16+
17+
## Hardware & Software Needed
18+
19+
- [A MicroPython compatible board](/micropython/basics/board-installation#supported-boards),
20+
21+
- [Arduino Lab for MicroPython editor](https://labs.arduino.cc/en/labs/micropython),
22+
- [mpremote](https://pypi.org/project/mpremote/) (optional).
23+
24+
## Option 1: MIP
25+
26+
***Please note that the `mip` module requires a stable Internet connection via Wi-Fi. Installation may fail if connection is unstable.***
27+
28+
[mip](https://docs.micropython.org/en/latest/reference/packages.html#installing-packages-with-mip) is a module that allows you to install external packages/libraries/modules remotely. This module is built in to your MicroPython firmware.
29+
30+
To use the `mip` module, you will however need to connect to Internet via a Wi-Fi network first. To do so, open the **Arduino Lab for MicroPython editor**, and run the following code:
31+
32+
***Note: Replace "YOUR_NETWORK_NAME" and "" YOUR_NETWORK_PASSWORD" with the SSID and password for your Wi-Fi® network.***
33+
34+
35+
```python
36+
import network
37+
38+
WIFI_NETWORK='YOUR_NETWORK_NAME'
39+
WIFI_PASSWORD='YOUR_NETWORK_PASSWORD'
40+
41+
wlan = network.WLAN(network.STA_IF)
42+
wlan.active(True)
43+
wlan.connect(WIFI_NETWORK, WIFI_PASSWORD)
44+
45+
print()
46+
print("Connected to ",WIFI_NETWORK)
47+
```
48+
49+
Once you are connected, you can use the `mip` module to install external modules.
50+
51+
You can install by specifying the **organisation** and **repository**:
52+
53+
```python
54+
import mip
55+
mip.install(github:org/repo)
56+
```
57+
58+
Or you can specify the url to the file you want to install:
59+
60+
```
61+
mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py")
62+
63+
```
64+
65+
Files are added to a folder named `lib` on your board.
66+
67+
***There are a number of ways you can use the `install()` method, read more about this in the [MIP documentation](https://docs.micropython.org/en/latest/reference/packages.html#installing-packages-with-mip).***
68+
69+
### Complete Example
70+
71+
In this example, we first connect to Wi-Fi®, and then proceed to install the `[arduino-iot-cloud-py](https://github.com/arduino/arduino-iot-cloud-py) module.
72+
73+
```python
74+
import network
75+
import mip
76+
77+
# enter wi-fi creds
78+
WIFI_NETWORK='YOUR_NETWORK_NAME'
79+
WIFI_PASSWORD='YOUR_NETWORK_PASSWORD'
80+
81+
# connect to wi-fi
82+
wlan = network.WLAN(network.STA_IF)
83+
wlan.active(True)
84+
wlan.connect(WIFI_NETWORK, WIFI_PASSWORD)
85+
86+
print()
87+
print("Connected to ",WIFI_NETWORK)
88+
89+
# install the arduino-iot-cloud module
90+
mip.install("github:arduino/arduino-iot-cloud-py")
91+
```
92+
93+
***Running this example twice will result in a `202` error, as you have already connected to Wi-Fi. Once you have connected once to Wi-Fi, you only need to use the `mip.install()` method.***
94+
95+
### Failed Installation
96+
97+
Installation via `mip` may fail due to an unstable Internet connection. If you have installed a module but you are receiving errors, make sure your Internet connection is good (your board is within reach of your router), and run the installation again.
98+
99+
This is typically not an issue with smaller installations (like single files), but when installing larger packages it is increased.
100+
101+
You can install the same module again, it will only overwrite the existing version.
102+
103+
## Option 2: Mpremote
104+
105+
To install a MicroPython module on your board, you can use the Python based tool `mpremote`. This requires Python to be installed. On macOS and Linux Python usually comes pre-installed. If it's not installed on your system you may download it from [here](https://www.python.org/downloads/). Then, to install `mpremote` you can use pip:
106+
107+
```bash
108+
$ pip install mpremote
109+
```
110+
111+
Run `mpremote connect list` to retrieve the serial number of your device. The output will look similar to this:
112+
113+
```
114+
/dev/cu.usbmodem3871345733302 335B34603532 2341:055b Arduino Portenta Virtual Comm Port in HS Mode
115+
```
116+
117+
Pass this serial number (the second value) to the install command:
118+
119+
```bash
120+
$ mpremote connect id:335B34603532 mip install github:arduino/arduino-iot-cloud-py
121+
```
122+
123+
This will install the library and all required dependencies on the board.
124+
125+
### Error: Certificate Verify Fail (MacOS)
126+
127+
On some computers, you may receive error:
128+
129+
```
130+
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
131+
unable to get local issuer certificate (_ssl.c:1002)
132+
```
133+
134+
This indicates a problem with the Python version installed, and that it is unable to locate the SSL certificate. To work around this, navigate to your Python installation (typically **Applications > Python 3.X**), and run the `Install Certificates.command` script.
135+
136+
![Install Certificate.](assets/install-cert.png)
137+
138+
## Delete Files
139+
140+
To delete a file from your board, open the **Arduino Lab for MicroPython** editor, connect to your board, and click the **"File"** button. This will open your local files as well as your board's files.
141+
142+
If you want to remove a file, simply mark it and click on the trashcan icon in the top right of the file window, as the image below shows:
143+
144+
![Removing files.](assets/delete-file.png)

0 commit comments

Comments
 (0)