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/00.first-steps/00.into-micropython/intro-micropython.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: 'Introduction to MicroPython'
3
3
description: 'Learn about the fundamentals of Micropython on Arduino boards.'
4
4
author: 'Pedro Lima'
5
-
hero_image: "./hero-banner.png"
5
+
tags: [MicroPython, Introduction]
6
6
---
7
7
8
8
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.
Copy file name to clipboardExpand all lines: content/micropython/03.micropython/00.first-steps/01.install-guide/installing-micropython.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
featured: micropython-101
3
3
title: 'Installing MicroPython'
4
4
description: 'Learn how to install MicroPython on your Arduino board.'
5
-
author: 'Pedro Lima & Karl Söderby'
6
-
hero_image: "./hero-banner.png"
5
+
author: 'Pedro Lima'
6
+
tags: [MicroPython, Installation]
7
7
---
8
8
9
9
# Installing MicroPython
@@ -40,7 +40,7 @@ MicroPython is officially supported on several Arduino boards. Here’s a list o
40
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
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
42
43
-
***Note that the editor is also available online, at [Arduino Cloud - Arduino Labs for MicroPython](https://lab-micropython.arduino.cc/)
43
+
***Note that the editor is also available online, at [Arduino Cloud - Arduino Labs for MicroPython](https://lab-micropython.arduino.cc/)***
Copy file name to clipboardExpand all lines: content/micropython/03.micropython/00.first-steps/02.first-sketch/first-sketch.md
+76-55
Original file line number
Diff line number
Diff line change
@@ -2,33 +2,51 @@
2
2
title: 'My First Script'
3
3
description: 'Learn how to write a basic MicroPython script to blink an LED.'
4
4
author: 'Pedro Lima'
5
-
hero_image: "./hero-banner.png"
5
+
tags: [MicroPython, Blink]
6
6
---
7
7
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.
9
9
10
-
## Hardware & Software Needed
10
+
## Requirements
11
11
12
-
For this tutorial, you will need a MicroPython compatible Arduino Board:
12
+
Before we start, let's check the requirements:
13
13
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
20
15
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:
22
17
23
-
-[Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython).
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/)***
28
40
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.]()
32
50
33
51
***Need help installing MicroPython on your board? Visit the [MicroPython installation guide]().***
34
52
@@ -44,6 +62,9 @@ Once your board is connected, we can start writing code! Below you will find a b
@@ -53,44 +74,19 @@ Once your board is connected, we can start writing code! Below you will find a b
53
74
time.sleep(1)
54
75
```
55
76
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`.***
57
78
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.]()
59
81
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.
61
83
62
84
![LED blinking on your board.]()
63
85
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
-
92
86
### Code Breakdown
93
87
88
+
Let's take a look at the code, line by line, to understand what is happening:
89
+
94
90
-**Import Modules**:
95
91
96
92
```python
@@ -126,6 +122,31 @@ A `while True` loop creates an infinite loop, allowing the code inside it to run
126
122
- Wait for another second.
127
123
- Repeat the cycle.
128
124
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
+
129
150
## Modification: Make the LED Blink Faster
130
151
131
152
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)
140
161
141
162
whileTrue:
142
163
led.value(1)
143
-
time.sleep(2)
164
+
time.sleep(0.5) # 0.5 seconds
144
165
led.value(0)
145
-
time.sleep(2)
166
+
time.sleep(0.5) # 0.5 seconds
146
167
```
147
168
148
169
### Steps
149
170
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)`.
151
172
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.
153
174
154
-
## Conclusion
175
+
## Summary
155
176
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:
157
178
158
179
- Importing modules (`machine`, `time`)
159
180
- Initializing hardware components (LED)
160
181
- Using loops (`while`)
161
182
- Controlling time delays (`time.sleep()`)
162
183
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.
0 commit comments