Skip to content

Commit 917e07f

Browse files
authored
Merge pull request #2265 from arduino/hannes7eicher/Modulino-MicroPython
Modulino Micropython Docs
2 parents 129c995 + c238e04 commit 917e07f

File tree

14 files changed

+586
-0
lines changed

14 files changed

+586
-0
lines changed
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
title: 'Modulino Installation'
3+
description: 'Get started with using the Modulinos'
4+
author: 'Hannes Siebeneicher, Sebastian Romero'
5+
tags: [MicroPython, Package Installation]
6+
---
7+
8+
In this tutorial, we will go through the installation process required for programming the Arduino Modulinos with MicroPython.
9+
10+
## Goals
11+
12+
The goals of this tutorial are:
13+
14+
- Learn how to install a MicroPython package on an Arduino board (the Modulino package).
15+
16+
## Hardware & Software Needed
17+
18+
We will need a MicroPython compatible board that works with the Modulinos:
19+
- [Arduino Nano ESP32](https://store.arduino.cc/products/nano-esp32?queryID=undefined)
20+
- [Arduino Nano RP2040 Connect](https://store.arduino.cc/en-se/products/arduino-nano-rp2040-connect)
21+
22+
We will also need the following software:
23+
- [MicroPython Labs](https://lab-micropython.arduino.cc/)
24+
- [MicroPython Installer](https://labs.arduino.cc/en/labs/micropython-installer)
25+
- [Modulino MicroPython package](https://github.com/arduino/arduino-modulino-mpy)
26+
27+
## Install MicroPython
28+
29+
To follow this tutorial, we will need to install MicroPython on our Arduino board. The easiest way is to install it using the [MicroPython Installer](https://labs.arduino.cc/en/labs/micropython-installer).
30+
31+
- Open the installer.
32+
- Connect the board to the computer.
33+
- If it does not appear press the refresh button.
34+
- Press "Install MicroPython".
35+
- Wait for the installation to finish.
36+
37+
![MicroPython Installer](./assets/microPythonInstaller.png)
38+
39+
***More details on installing MicroPython on our board are available in the [MicroPython Installation guide]().***
40+
41+
## Install Modulino Package
42+
43+
To program Modulinos using MicroPython we must first install the Modulino package. It's where all the code, necessary to interact with the Modulinos is being stored.
44+
45+
There are two ways of installing a package:
46+
- Through a terminal
47+
-
48+
49+
### Terminal Installation
50+
51+
The easiest way of installing it is using `mpremote`. Currently, we will need a version of Python installed on our computer.
52+
53+
1. Open a terminal, and write the following line:
54+
```bash
55+
pip install mpremote
56+
```
57+
This will install `mpremote`, which makes it possible to install packages on our board via our computer.
58+
2. With `mpremote` installed, we need to run the following command to identify our board's serial port:
59+
```bash
60+
mpremote connect list
61+
```
62+
63+
Which will give us something like this:
64+
65+
```bash
66+
/dev/cu.usbmodem101 ecda3b60a4dccb3f 2341:056b Arduino Nano ESP32
67+
```
68+
- The port here is `/dev/cu.usbmodem101`. Copy this.
69+
70+
3. Now, run the following the command. Make sure to replace `<PORT>` with the port of our device obtained in the previous step.
71+
```bash
72+
mpremote connect <PORT> mip install github:arduino/arduino-modulino-mpy
73+
```
74+
75+
Upon completion, we should see something like this in the terminal, to verify the success of the installation:
76+
![Successful installation.](assets/package-installed.png)
77+
78+
4. Great job. We have now installed the Modulino package on our board!
79+
80+
**Troubleshooting:**
81+
- Make sure your board is connected to your computer.
82+
- Make sure it is **not** connected in the Arduino Lab for MicroPython, as this might disturb the connection.
83+
- If you are unable to run `mpremote` in the terminal, this means it is not installed.
84+
- If you are unable to run `python` in the terminal, make sure you have installed Python (you can download and install it [here](https://www.python.org/downloads/))
85+
- If you have installed Python and it is still not working, try running `python3` and `pip3` instead.
86+
- If you installed Python while having the terminal open, try closing the terminal and re-opening it.
87+
- If you run `mpremote` and there's no board appearing in the list, try re-installing the firmware on your board as it might have failed during installation.
88+
89+
## MicroPython Labs
90+
91+
We can now verify that everything was installed correctly. Go to [MicroPython Labs](https://lab-micropython.arduino.cc/) and click on the connect icon in the top left corner.
92+
93+
![MicroPython Labs](./assets/microPythonLabs.png)
94+
95+
Select the board and press select "connect". We should now be connected to our Arduino board.
96+
97+
***If we experience any issues, try disconnecting and connecting the board again and reinstall MicroPython using the [MicroPython Installer](https://labs.arduino.cc/en/labs/micropython-installer).***
98+
99+
To verify that the Modulino package has been installed correctly, click on the file icon in the top bar of the Labs editor.
100+
101+
We should see a folder called `lib` and a file called `boot.py`. Go ahead and press on the `lib` folder and we should see several files and a folder called `modulino`.
102+
103+
![MicroPython Lab Files](./assets/microPythonLabsFiles.png)
104+
105+
If we see this, it means the package has been installed successfully.
106+
107+
## Next Steps
108+
109+
Now that we have successfully installed everything it's time to program our first Modulino. Below are links to the documentation for all Modulinos. They are also accessible in the side menu at [Arduino Docs - MicroPython](https://docs.arduino.cc/micropython/), under "Modulinos".
110+
111+
- [Modulino Distance](/micropython/modulinos/modulino-distance)
112+
- [Modulino Pixels](/micropython/modulinos/modulino-pixels)
113+
- [Modulino Buzzer](/micropython/modulinos/modulino-buzzer)
114+
- [Modulino Buttons](/micropython/modulinos/modulino-buttons)
115+
- [Modulino Knob](/micropython/modulinos/modulino-knob)
116+
- [Modulino Movement](/micropython/modulinos/modulino-movement)
117+
- [Modulino Thermo](/micropython/modulinos/modulino-thermo)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: 'Modulino Distance'
3+
description: 'Get started with the Modulino Distance using MicroPython'
4+
author: 'Hannes Siebeneicher, Sebastian Romero'
5+
tags: [MicroPython, Time of Flight, Sensors]
6+
---
7+
8+
In this tutorial, we will get started with the Modulino Distance, which can measure the distance to an object.
9+
10+
***Note that the installation of the Modulino package is not covered in this tutorial. For details on how to install this, visit the [MicroPython - Modulino Package Installation tutorial](/micropython/modulinos/installation).***
11+
12+
## Goals
13+
14+
The goals of this tutorial are:
15+
16+
- learn how to connect a Modulino to an Arduino using MicroPython
17+
- learn how to program the Modulino Distance.
18+
19+
## Hardware & Software Needed
20+
21+
For this tutorial, we will need the following hardware:
22+
- [Modulino Distance](https://store.arduino.cc/products/plug-and-make-kit)
23+
- [Arduino Nano to QWIIC Connector Carrier]()
24+
- [Arduino Nano ESP32](https://store.arduino.cc/products/nano-esp32?queryID=undefined) or [Arduino Nano RP2040 Connect](https://store.arduino.cc/en-se/products/arduino-nano-rp2040-connect)
25+
26+
We will also need the following software:
27+
- [MicroPython Labs](https://lab-micropython.arduino.cc/)
28+
- [Modulino MicroPython Package](https://github.com/arduino/arduino-modulino-mpy)
29+
30+
## Connect the Modulino
31+
32+
Before we start programming, we will need to connect our Modulino Distance to our Arduino board. For this we can follow the circuit diagram below:
33+
34+
![Circuit Diagram]()
35+
36+
## Modulino Distance Code Example
37+
38+
Copy the code below and run it in Arduino MicroPython labs, while connected to our board.
39+
40+
```python
41+
from modulino import ModulinoDistance
42+
from time import sleep_ms
43+
44+
distance = ModulinoDistance()
45+
46+
while True:
47+
print(f"📏 Distance: {distance.distance} cm")
48+
sleep_ms(50)
49+
```
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: 'Modulino Pixels'
3+
description: 'Get started with the Modulino Pixels using MicroPython'
4+
author: 'Hannes Siebeneicher, Sebastian Romero'
5+
tags: [MicroPython, RGB, Pixel Strip]
6+
---
7+
8+
In this tutorial, we will get started with the Modulino Pixels and control its RGB LEDs.
9+
10+
***Note that the installation of the Modulino package is not covered in this tutorial. For details on how to install this, visit the [MicroPython - Modulino Package Installation tutorial](/micropython/modulinos/installation).***
11+
12+
## Goals
13+
14+
The goals of this tutorial are:
15+
16+
- learn how to connect a Modulino to an Arduino board.
17+
- learn how to program the Modulino Pixels.
18+
19+
## Hardware & Software Needed
20+
21+
For this tutorial, we will need the following hardware:
22+
- [Modulino Pixels](https://store.arduino.cc/products/plug-and-make-kit)
23+
- [Arduino Nano to QWIIC Connector Carrier]()
24+
- [Arduino Nano ESP32](https://store.arduino.cc/products/nano-esp32?queryID=undefined) or [Arduino Nano RP2040 Connect](https://store.arduino.cc/en-se/products/arduino-nano-rp2040-connect)
25+
26+
We will also need the following software:
27+
- [MicroPython Labs](https://lab-micropython.arduino.cc/)
28+
- [Modulino MicroPython Package](https://github.com/arduino/arduino-modulino-mpy)
29+
30+
## Connect the Modulino
31+
32+
Before we start programming, we will need to connect our Modulino Pixels to our Arduino board. For this we can follow the circuit diagram below:
33+
34+
![Circuit Diagram]()
35+
36+
## Modulino Pixels Code Example
37+
38+
Copy the code below and run it in Arduino MicroPython labs, while connected to our board.
39+
40+
```python
41+
from modulino import ModulinoPixels, ModulinoColor
42+
from time import sleep
43+
44+
pixels = ModulinoPixels()
45+
46+
for index in range(0, 8):
47+
color_wheel_colors = [
48+
(255, 0, 0),
49+
(255, 85, 0),
50+
(255, 255, 0),
51+
(0, 255, 0),
52+
(0, 255, 255),
53+
(0, 0, 255),
54+
(255, 0, 255),
55+
(255, 0, 0)
56+
]
57+
pixels.set_rgb(index, *color_wheel_colors[index], 100)
58+
pixels.show()
59+
sleep(1)
60+
61+
pixels.set_all_rgb(255, 0, 0, 100)
62+
pixels.show()
63+
sleep(1)
64+
65+
pixels.set_all_color(ModulinoColor.GREEN, 100)
66+
pixels.show()
67+
sleep(1)
68+
69+
pixels.set_all_color(ModulinoColor.BLUE, 100)
70+
pixels.show()
71+
sleep(1)
72+
73+
74+
# Night Rider animation
75+
76+
for j in range(0, 3):
77+
for i in range(0, 8):
78+
pixels.clear_all()
79+
pixels.set_rgb(i, 255, 0, 0, 100)
80+
pixels.show()
81+
sleep(0.05)
82+
83+
for i in range(7, -1, -1):
84+
pixels.clear_all()
85+
pixels.set_rgb(i, 255, 0, 0, 100)
86+
pixels.show()
87+
sleep(0.05)
88+
89+
# Turn off all LEDs
90+
pixels.clear_all()
91+
pixels.show()
92+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: 'Modulino Buzzer'
3+
description: 'Get started with the Modulino Buzzer using MicroPython'
4+
author: 'Hannes Siebeneicher, Sebastian Romero'
5+
tags: [MicroPython, Piezo, Speaker]
6+
---
7+
8+
In this tutorial, we will get started with the Modulino Buzzer, a piezo speaker that can output sound.
9+
10+
***Note that the installation of the Modulino package is not covered in this tutorial. For details on how to install this, visit the [MicroPython - Modulino Package Installation tutorial](/micropython/modulinos/installation).***
11+
12+
## Goals
13+
14+
The goals of this tutorial are:
15+
16+
- learn how to connect a Modulino to an Arduino board.
17+
- learn how to program the Modulino Buzzer.
18+
19+
## Hardware & Software Needed
20+
21+
For this tutorial, we will need the following hardware:
22+
- [Modulino Buzzer](https://store.arduino.cc/products/plug-and-make-kit)
23+
- [Arduino Nano to QWIIC Connector Carrier]()
24+
- [Arduino Nano ESP32](https://store.arduino.cc/products/nano-esp32?queryID=undefined) or [Arduino Nano RP2040 Connect](https://store.arduino.cc/en-se/products/arduino-nano-rp2040-connect)
25+
26+
We will also need the following software:
27+
- [MicroPython Labs](https://lab-micropython.arduino.cc/)
28+
- [Modulino MicroPython Package](https://github.com/arduino/arduino-modulino-mpy)
29+
30+
## Connect the Modulino
31+
32+
Before we start programming, we will need to connect our Modulino Buzzer to our Arduino board. For this we can follow the circuit diagram below:
33+
34+
![Circuit Diagram]()
35+
36+
## Modulino Buzzer Code Example
37+
38+
Copy the code below and run it in Arduino MicroPython labs, while connected to our board.
39+
40+
```python
41+
from modulino import ModulinoBuzzer
42+
from time import sleep
43+
44+
buzzer = ModulinoBuzzer()
45+
46+
# Super Mario Bros theme intro
47+
melody = [
48+
(ModulinoBuzzer.NOTES["E5"], 125),
49+
(ModulinoBuzzer.NOTES["REST"], 25),
50+
(ModulinoBuzzer.NOTES["E5"], 125),
51+
(ModulinoBuzzer.NOTES["REST"], 125),
52+
(ModulinoBuzzer.NOTES["E5"], 125),
53+
(ModulinoBuzzer.NOTES["REST"], 125),
54+
(ModulinoBuzzer.NOTES["C5"], 125),
55+
(ModulinoBuzzer.NOTES["E5"], 125),
56+
(ModulinoBuzzer.NOTES["REST"], 125),
57+
(ModulinoBuzzer.NOTES["G5"], 125),
58+
(ModulinoBuzzer.NOTES["REST"], 375),
59+
(ModulinoBuzzer.NOTES["G4"], 250)
60+
]
61+
62+
for note, duration in melody:
63+
buzzer.tone(note, duration, blocking=True)
64+
65+
# Wait 2 seconds before playing the next melody
66+
sleep(2)
67+
68+
# Police siren sound effect
69+
def generate_siren(frequency_start, frequency_end, total_duration, steps, iterations):
70+
siren = []
71+
mid_point = steps // 2
72+
duration_rise = total_duration // 2
73+
duration_fall = total_duration // 2
74+
75+
for _ in range(iterations):
76+
for i in range(steps):
77+
if i < mid_point:
78+
# Easing in rising part
79+
step_duration = duration_rise // mid_point + (duration_rise // mid_point * (mid_point - i) // mid_point)
80+
frequency = int(frequency_start + (frequency_end - frequency_start) * (i / mid_point))
81+
else:
82+
# Easing in falling part
83+
step_duration = duration_fall // mid_point + (duration_fall // mid_point * (i - mid_point) // mid_point)
84+
frequency = int(frequency_end - (frequency_end - frequency_start) * ((i - mid_point) / mid_point))
85+
86+
siren.append((frequency, step_duration))
87+
88+
return siren
89+
90+
# 4 seconds up and down siren, with 200 steps and 2 iterations
91+
siren_melody = generate_siren(440, 880, 4000, 200, 2)
92+
93+
for note, duration in siren_melody:
94+
buzzer.tone(note, duration, blocking=True)
95+
```

0 commit comments

Comments
 (0)