Skip to content

Commit c1b22fb

Browse files
Merge branch 'content/micropython/micropython-revamp' of https://github.com/arduino/docs-content into content/micropython/micropython-revamp
2 parents ec287b0 + 917e07f commit c1b22fb

File tree

21 files changed

+1120
-270
lines changed

21 files changed

+1120
-270
lines changed

content/micropython/03.micropython/00.first-steps/00.into-micropython/intro-micropython.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Introduction to MicroPython'
33
description: 'Learn about the fundamentals of Micropython on Arduino boards.'
44
author: 'Pedro Lima'
5-
hero_image: "./hero-banner.png"
5+
tags: [MicroPython, Introduction]
66
---
77

88
MicroPython is a lightweight implementation of Python 3 designed to run on microcontrollers and embedded systems. Think of it as a mini-version of Python, tailored for hardware with limited resources like memory and processing power. Despite its smaller size, MicroPython retains the simplicity and flexibility of Python, making it an excellent option for programming hardware.

content/micropython/03.micropython/00.first-steps/01.install-guide/installing-micropython.md

+77-36
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
---
22
featured: micropython-101
3-
title: '1. Introduction to Arduino'
4-
description: 'Learn about the Arduino platform'
5-
author: 'Karl Söderby'
6-
hero_image: "./hero-banner.png"
3+
title: 'Installing MicroPython'
4+
description: 'Learn how to install MicroPython on your Arduino board.'
5+
author: 'Pedro Lima'
6+
tags: [MicroPython, Installation]
77
---
88

99
# Installing MicroPython
1010

11-
In this article, we'll walk you through the process of installing MicroPython on your Arduino board. By the end of this guide, you (and your board) will be ready to write and run your first MicroPython script. Let's get started!
11+
In this article, we will go through the necessary tools needed to install and run MicroPython on an Arduino board. By the end of this guide, we will be ready to write and run our first MicroPython script. Let's get started!
1212

1313
## Requirements
1414

15-
Before you begin, make sure you have the following:
15+
Before we start, let's check the requirements:
1616

17-
### Supported Arduino Boards
18-
MicroPython is officially supported on several Arduino boards. Here’s a list of compatible boards:
17+
### MicroPython Compatible Arduino Boards
18+
19+
MicroPython is officially supported on several Arduino boards. Here’s a list of the compatible boards:
1920

2021
- [Portenta C33](https://store.arduino.cc/products/portenta-c33)
2122
- [Arduino GIGA R1 WiFi](https://store.arduino.cc/products/arduino-giga-r1-wifi)
@@ -35,50 +36,90 @@ MicroPython is officially supported on several Arduino boards. Here’s a list o
3536

3637

3738
### Software Requirements
38-
- **Arduino Labs for Micropython**: Ensure you have the [latest version](https://labs.arduino.cc/en/labs/micropython) of the IDE. (Optional)
39-
- **MicroPython Firmware Installer**: [This installer](https://labs.arduino.cc/en/labs/micropython-installer) is needed to upload the MicroPython firmware onto your Arduino board. You can download it from the official Arduino website under the MicroPython section.
4039

41-
## How to setup your board
40+
- [MicroPython Firmware Installer](https://labs.arduino.cc/en/labs/micropython-installer) - the firmware installer is needed to install MicroPython on our Arduino board.
41+
- [Arduino Lab for Micropython](https://labs.arduino.cc/en/labs/micropython) - Arduino Lab for MicroPython is an editor where we can create and run MicroPython scripts on our Arduino board.
42+
43+
***Note that the editor is also available online, at [Arduino Cloud - Arduino Labs for MicroPython](https://lab-micropython.arduino.cc/)***
44+
45+
## Install MicroPython
4246

43-
1. If you haven’t already, download the [Micropython Firmware Installer](https://labs.arduino.cc/en/labs/micropython-installer) and launch it.
44-
2. Plug your board, it should be recognized by the installer.
45-
![Arduino Nano ESP32 detected!](./assets/board-selected.png)
47+
1. First, download the [Micropython Firmware Installer](https://labs.arduino.cc/en/labs/micropython-installer) and launch it.
48+
2. Connect your board to your computer, it should be recognized by the installer.
49+
![Arduino Nano ESP32 detected!](./assets/board-selected.png)
4650
3. Press **INSTALL MICROPYTHON**. A loading animation will appear.
4751

48-
Once the firmware is installed a "Installation successful" message will appear. At this point you can safely close the installer as your board is now ready for tinkering!
49-
![Firmware Successfully Uploaded!](./assets/flashed.png)
52+
Once the firmware is installed a "Installation successful" message will appear. At this point you can safely close the installer as your board is now ready for tinkering!
53+
![Firmware Successfully Uploaded!](./assets/flashed.png)
54+
55+
## Editor Setup
56+
57+
After installing MicroPython on your board, we will need an editor to write code. We now have the option to choose the **offline** or **online** option.
58+
59+
### Offline Setup
60+
61+
First, download the latest version of [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython) for your operative system. See instructions for MacOS / Windows below:
62+
63+
#### MacOS
64+
65+
Run the downloaded file, and move it to your **"Applications"** folder.
66+
67+
![Installation MacOS.]()
5068

51-
### IDE setup
69+
#### Windows
5270

53-
#### Offline IDE
71+
Unzip the downloaded file, and run the executable file (`.exe`).
5472

55-
After downloading the [latest version](https://labs.arduino.cc/en/labs/micropython) of the IDE you can use it for the first time by:
56-
- Unpack the compressed folder you downloaded.
57-
- Execute "Arduino Lab for MicroPython.exe"
73+
![Installation Windows]()
5874

59-
#### Online IDE
75+
### Online Setup
6076

61-
Alternatively, you can use the IDE without installing it by using the online version available [here](https://lab-micropython.arduino.cc/).
77+
Alternatively, we can use the IDE without the need of installing anything. Simply visit the link below:
78+
- [Arduino Lab for MicroPython (online).](https://lab-micropython.arduino.cc/).
6279

63-
#### Connecting Board and IDE
80+
## Connecting Board and IDE
6481

65-
1. Plug your Arduino board into your computer using a USB cable.
66-
2. Press the connection button on the top left corner of the window. This will look like a plug and socket as in this image:
67-
TODO: ADD IMAGE OF CONNECTION
68-
3. Select the COM port where your board is connected.
82+
At this point in the tutorial, we have
83+
- Installed MicroPython on our board
84+
- Downloaded and installed the editor (or opted for the online version).
6985

70-
You are now ready to upload your first sketch.
71-
TODO: A 4 step screenshot to explain the processimage
86+
We will now try out running a script on the board, to make sure things are working properly.
87+
88+
1. Plug the Arduino board into the computer using a USB cable.
89+
![Connect board to computer.]()
90+
2. Press the connection button on the top left corner of the window.
91+
![Connect the editor to the board.]()
92+
3. The connected Arduino board should appear, and we can click it:
93+
![Select board.]()
94+
95+
We have now set up all necessary steps for running a script!
96+
97+
## Running a Test Script
98+
99+
With the installation and setup complete, let's try out running a very simple script: **Hello World!**
100+
101+
1. In the text area field of the editor, write the following: `print("Hello World!")`
102+
![Write hello world.]()
103+
2. Click on the play symbol (RUN).
104+
![Run the script.]()
105+
3. After running it, you should see `Hello World!` in the black box. This is the board sending the **"Hello World!"** back to you, because the script is run on the board, not on the computer. This means everything is successful, and you are ready to start writing MicroPython scripts!
106+
![Hello world from the board.]()
72107

73108
## Troubleshooting
74109

75110
If you run into any issues during installation, here are some common problems and solutions:
76111

77-
### 1. **Board Not Detected**
78-
- **Solution**: Ensure that your board is properly connected and the correct USB drivers are installed. Try using a different USB cable or port.
112+
- **Board Not Detected** - if you cannot locate your board, ensure that your board is properly connected and the correct USB drivers are installed. Try using a different USB cable, or double tap the reset button on the board. If a light starts fading, it means it is in default mode, and is ready to be installed!
113+
114+
- **Unable to Install Firmware** - double-check that the MicroPython Firmware Installer was able to install the firmware and that your board is compatible (it will not show up on the installer if it is not). Also, verify that no other software is using the same serial port.
115+
116+
## Summary
117+
118+
By following these steps, you should be able to successfully install MicroPython on your Arduino board and run your first script.
119+
120+
### Next Steps
79121

80-
### 2. **Unable to Flash Firmware**
81-
- **Solution**: Double-check that the MicroPython Firmware Installer was able to burn the firmware and that your board is compatible(it will not show up on the installer if it is not). Also, verify that no other software is using the serial port.
122+
This tutorial is **Part Two** of the **"First Steps"** series. We recommend you following the next tutorial that will allow you to control the Arduino board's LED.
123+
- [First Steps - Part Three]()
124+
82125

83-
By following these steps, you should be able to successfully install MicroPython on your Arduino board and run your first script. Stay tuned for more tutorials to help you get the most out of MicroPython!
84-
For information on how to uploadyour first sketch please check [](). TODO: We need to add here the guide for first sketch once it is linkable

content/micropython/03.micropython/00.first-steps/02.first-sketch/first-sketch.md

+76-55
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,51 @@
22
title: 'My First Script'
33
description: 'Learn how to write a basic MicroPython script to blink an LED.'
44
author: 'Pedro Lima'
5-
hero_image: "./hero-banner.png"
5+
tags: [MicroPython, Blink]
66
---
77

8-
In this tutorial, we'll guide create our very first MicroPython script that will run on an Arduino board. We'll make an LED blink, a classic beginner project that introduces you to basic MicroPython programming concepts.
8+
In this tutorial, we will create our very first MicroPython script that will run on an Arduino board. Starting of simple, we will make an LED blink, a classic beginner project that will get us familiar with the MicroPython programming environment.
99

10-
## Hardware & Software Needed
10+
## Requirements
1111

12-
For this tutorial, you will need a MicroPython compatible Arduino Board:
12+
Before we start, let's check the requirements:
1313

14-
- [Arduino Nano 33 BLE]()
15-
- [Arduino Nano ESP32]()
16-
- [Arduino Nano RP2040 Connect]()
17-
- [Arduino GIGA R1 WiFi]()
18-
- [Arduino Portenta H7]()
19-
- [Arduino Nicla Vision]()
14+
### MicroPython Compatible Arduino Boards
2015

21-
You will also need the following software installed:
16+
MicroPython is officially supported on several Arduino boards. Here’s a list of the compatible boards:
2217

23-
- [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython).
18+
- [Portenta C33](https://store.arduino.cc/products/portenta-c33)
19+
- [Arduino GIGA R1 WiFi](https://store.arduino.cc/products/arduino-giga-r1-wifi)
20+
- [Portenta H7](https://store.arduino.cc/products/portenta-h7)
21+
- [Portenta H7 Lite](https://store.arduino.cc/products/portenta-h7-lite)
22+
- [Portenta H7 Lite Connected](https://store.arduino.cc/products/portenta-h7-lite-connected)
23+
- [Opta](https://store.arduino.cc/products/opta)
24+
- [Opta Wifi](https://store.arduino.cc/products/opta-wifi)
25+
- [Opta RS485](https://store.arduino.cc/products/opta-rs485)
26+
- [Arduino Nano RP2040 Connect](https://store.arduino.cc/products/arduino-nano-rp2040-connect)
27+
- [Nicla Vision](https://store.arduino.cc/products/nicla-vision)
28+
- [Arduino Nano 33 BLE](https://store.arduino.cc/products/arduino-nano-33-ble)
29+
- [Arduino Nano 33 BLE Rev2](https://store.arduino.cc/products/arduino-nano-33-ble-rev2)
30+
- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/products/arduino-nano-33-ble-sense)
31+
- [Arduino Nano 33 BLE Sense Rev2](https://store.arduino.cc/products/arduino-nano-33-ble-sense-rev2)
32+
- [Arduino Nano ESP32](https://store.arduino.cc/products/arduino-nano-esp32)
2433

25-
## Board and Editor Setup
2634

27-
Blinking an LED is a simple yet effective way to get started with MicroPython while still understanding how to control hardware using code.
35+
### Software Requirements
36+
37+
- [Arduino Lab for Micropython](https://labs.arduino.cc/en/labs/micropython) - Arduino Lab for MicroPython is an editor where we can create and run MicroPython scripts on our Arduino board.
38+
39+
***Note that the editor is also available online, at [Arduino Cloud - Arduino Labs for MicroPython](https://lab-micropython.arduino.cc/)***
2840

29-
1. Connect your Arduino board to your computer via USB.
30-
2. Open the Arduino Lab for MicroPython application.
31-
3. Click on the **Connect** button, and select the board from the list.
41+
## Board and Editor Setup
42+
43+
1. Open the [Arduino Lab for MicroPython]() application.
44+
2. Plug the Arduino board into the computer using a USB cable.
45+
![Connect board to computer.]()
46+
3. Press the connection button on the top left corner of the window.
47+
![Connect the editor to the board.]()
48+
4. The connected Arduino board should appear, and we can click it:
49+
![Select board.]()
3250

3351
***Need help installing MicroPython on your board? Visit the [MicroPython installation guide]().***
3452

@@ -44,6 +62,9 @@ Once your board is connected, we can start writing code! Below you will find a b
4462
import machine
4563
import time
4664

65+
# The pin used for built-in LED varies
66+
# GIGA: 0 (green), Nano ESP32: 0 (green), Nano RP2040 Connect: 25
67+
# Nano BLE Sense: 13
4768
led = machine.Pin(25, machine.Pin.OUT)
4869

4970
while True:
@@ -53,44 +74,19 @@ Once your board is connected, we can start writing code! Below you will find a b
5374
time.sleep(1)
5475
```
5576

56-
***Note: On some boards, the built-in LED might be on a different pin. For example, on the Arduino Nano RP2040 Connect, the built-in LED is on pin `25`. Check your board's documentation to confirm the correct pin number.***
77+
***Note: The built-in LED pin varies from board to board. For example, on the Arduino Nano RP2040 Connect, the built-in LED is on pin `25`.***
5778

58-
3. Click the **Run** or **Upload** button in your editor to transfer the script to your board.
79+
3. Click the **Run** button in your editor to transfer the script to your board.
80+
![Run the script.]()
5981

60-
Once the script is running, the LED on your board should start blinking at one-second intervals. This means your MicroPython script has loaded successfully.
82+
Once the script is running, the LED on the board should start blinking at one-second intervals. This means our MicroPython script has loaded successfully.
6183

6284
![LED blinking on your board.]()
6385

64-
## Programming Concepts Explained
65-
66-
Let's break down the key programming concepts used in this script:
67-
68-
### `machine` Module
69-
70-
The machine module is a built-in MicroPython library that provides direct access to your board's hardware components. It allows you to control and interact with the microcontroller's features, such as:
71-
72-
-**Pins:** Configure and control digital and analog pins.
73-
-**Timers:** Set up timers for scheduling tasks.
74-
-**Communication Interfaces:** Use protocols like I2C, SPI, and UART.
75-
-**Hardware-Specific Functions:** Access features unique to your microcontroller.
76-
77-
In our script, we use the machine.Pin class to interact with a specific pin on the board. By creating a Pin object, we can control the voltage level of that pin, which in turn controls the LED.
78-
79-
### `time` Module
80-
81-
The time module provides functions for managing time-related tasks. It allows you to add delays, measure time intervals, and schedule events. Key functions include:
82-
83-
-**time.sleep(seconds):** Pauses the execution of your script for the specified number of seconds. It accepts floating-point numbers for sub-second delays.
84-
-t**ime.ticks_ms():** Returns the number of milliseconds(ms) since the board was last reset.
85-
-**time.ticks_us()**: Returns the number of microseconds(us) since the board was last reset.
86-
-In our script, ``time.sleep(1)`` pauses the program for one second. This creates a delay between turning the LED on and off, controlling the blink rate.
87-
88-
### `while True` Loop
89-
90-
A `while True` loop creates an infinite loop, allowing the code inside it to run repeatedly. This is essential for tasks that need to run continuously, like blinking an LED.
91-
9286
### Code Breakdown
9387

88+
Let's take a look at the code, line by line, to understand what is happening:
89+
9490
- **Import Modules**:
9591

9692
```python
@@ -126,6 +122,31 @@ A `while True` loop creates an infinite loop, allowing the code inside it to run
126122
- Wait for another second.
127123
- Repeat the cycle.
128124

125+
## Understanding Programming Concepts
126+
127+
Let's break down the key programming concepts used in this script:
128+
129+
### `machine` Module
130+
131+
The machine module is a built-in MicroPython library that provides direct access to your board's hardware components. It allows you to control and interact with the microcontroller's features, such as:
132+
133+
- **Pins:** Configure and control digital and analog pins.
134+
- **Timers:** Set up timers for scheduling tasks.
135+
- **Communication Interfaces:** Use protocols like I2C, SPI, and UART.
136+
- **Hardware-Specific Functions:** Access features unique to your microcontroller.
137+
138+
In our script, we use the `machine.Pin` class to interact with a specific pin on the board. By creating a `Pin` object, we can control the voltage level of that pin, which in turn controls the LED.
139+
140+
### `time` Module
141+
142+
The time module provides functions for managing time-related tasks. It allows you to add delays, measure time intervals, and schedule events. Key functions include:
143+
144+
- `time.sleep(seconds)` Pauses the execution of your script for the specified number of seconds. It accepts floating-point numbers for sub-second delays.
145+
146+
### `while True` Loop
147+
148+
A `while True` loop creates an infinite loop, allowing the code inside it to run repeatedly. This is essential for tasks that need to run continuously, like blinking an LED.
149+
129150
## Modification: Make the LED Blink Faster
130151

131152
Let's modify the script to make the LED blink faster. We'll change the delay from 1 second to 0.2 seconds.
@@ -140,25 +161,25 @@ led = machine.Pin(25, machine.Pin.OUT)
140161

141162
while True:
142163
led.value(1)
143-
time.sleep(2)
164+
time.sleep(0.5) # 0.5 seconds
144165
led.value(0)
145-
time.sleep(2)
166+
time.sleep(0.5) # 0.5 seconds
146167
```
147168

148169
### Steps
149170

150-
1. Change the `time.sleep(1)` lines to `time.sleep(2)`.
171+
1. Change the `time.sleep(1)` lines to `time.sleep(0.5)`.
151172
2. Upload the modified script to your board.
152-
3. Observe that the LED now blinks faster, turning on and off every 2 seconds.
173+
3. Observe that the LED now blinks faster, turning on and off every 0.5 seconds.
153174

154-
## Conclusion
175+
## Summary
155176

156-
Congratulations! You've written and modified your first MicroPython script on an Arduino board. This exercise introduced you to:
177+
Great work! We have now written and modified our first MicroPython script on an Arduino board. This exercise introduced:
157178

158179
- Importing modules (`machine`, `time`)
159180
- Initializing hardware components (LED)
160181
- Using loops (`while`)
161182
- Controlling time delays (`time.sleep()`)
162183

163-
These concepts are key for a vast majoraty of the operations you will be performing when writing your own programs and are present in the industry at large.
184+
These concepts are key for a vast majoraty of operations we can perform while writing MicroPython programs.
164185

0 commit comments

Comments
 (0)