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
description: 'Learn the basics for loops on MicroPython.'
2
+
title: 'REPL'
3
+
description: 'Learn how to use the REPL (Read-Eval-Print Loop) in MicroPython.'
6
4
author: 'Pedro Lima'
7
-
hero_image: "./hero-banner.png"
8
-
5
+
tags: [MicroPython, REPL]
9
6
---
10
7
11
-
REPL, which stands for Read-Eval-Print Loop, is an interactive environment that makes programming in MicroPython fast and flexible. REPL allows you to enter code line-by-line and see the results immediately. Although sometimes overlooked it is a great way for testing and debugging on the fly.
8
+
**REPL**, short for **Read-Eval-Print Loop**, is an interactive environment that makes programming in MicroPython fast and flexible. REPL allows you to enter code line-by-line and see the results immediately. Although sometimes overlooked it is a great way for testing and debugging on the fly.
12
9
13
-
We’ll walk through what REPL does, why it’s useful, and how you can use it to enhance your MicroPython experience.
10
+
In this guide, we’ll go through how the REPL functions, why it’s useful, and how you can use it to enhance your MicroPython experience.
14
11
15
12
## What is REPL?
16
13
@@ -23,6 +20,9 @@ The REPL process involves four basic steps:
23
20
24
21
Think of REPL as a conversation between you and your MicroPython environment, where each line you type gets an instant response, making it ideal for exploring ideas and troubleshooting.
25
22
23
+
24
+
25
+
26
26
## How REPL Works in MicroPython
27
27
28
28
In MicroPython, REPL can be accessed via Arduino Labs for MicroPython terminal, enabling you to run code in real-time directly on your device. Here’s a step-by-step guide on using it:
@@ -32,22 +32,42 @@ In MicroPython, REPL can be accessed via Arduino Labs for MicroPython terminal,
32
32
3.**See Results Instantly**: Any output, return values, or errors are displayed right away. If your code contains expressions, REPL will evaluate and print them for you.
33
33
4.**Iterate**: The loop resets, and you can immediately enter more code, building on previous commands or testing new lines independently.
34
34
35
-
## Example: Using REPL in MicroPython
35
+
## Example: Store and Print Your Name
36
36
37
-
Let's see a simple REPL session to add two numbers interactively:
37
+
Let's create a REPL session, where you will enter your name, and then print it.
38
+
39
+
Connect your board, and click on the **RUN** button with an empty script, then enter the following things in the REPL, line by line.
40
+
41
+
```
42
+
>>> name = "Pedro"
43
+
>>> name
44
+
```
45
+
46
+
When writing `name` in the REPL, (after `name = "Pedro"`), we should get:
47
+
48
+
```
49
+
'Pedro'
50
+
```
51
+
52
+
![TODO: GIF showing step by step so people understand to run each individually]()
53
+
54
+
## Example: Perform a Calculation in the REPL
55
+
56
+
Now let's create a REPL session that performs a calculation, by adding two numbers together:
38
57
39
58
```python
40
59
>>> a =5
41
60
>>> b =3
42
61
>>> a + b
43
62
8
44
63
```
45
-
TODO: GIF showing step by step so people understand to run each individually !()[]
46
64
47
-
In this REPL session:
65
+
![TODO: GIF showing step by step so people understand to run each individually]()
66
+
67
+
In this REPL session, we:
48
68
49
-
-**Define variables**: We set`a` to 5 and `b` to 3.
50
-
-**Perform calculation**: Entering `a + b` immediately returns `8`, showing the result without having to write a full script.
69
+
-Defined variables by setting`a` to `5` and `b` to `3`.
70
+
-Performed a calculation by entering `a + b`, which immediately returns `8`, showing the result without having to write a full script.
51
71
52
72
## Common Uses of REPL
53
73
@@ -57,7 +77,7 @@ REPL is particularly useful for:
57
77
-**Debugging**: Test small parts of a larger project interactively.
58
78
-**Learning**: Practice MicroPython commands and get instant feedback, ideal for beginners.
59
79
60
-
## Going Further With REPL
80
+
## Summary
61
81
62
82
REPL in MicroPython is an useful tool that enables instant testing and feedback, making coding more interactive and efficient. Whether you're learning, debugging, or exploring ideas, REPL provides a flexible and powerful coding experience.
63
83
@@ -68,4 +88,4 @@ REPL in MicroPython is an useful tool that enables instant testing and feedback,
68
88
-**Debug Variable Values**: Enter and modify variables on the spot to test changes in data or simulate inputs, allowing you to observe how your program behaves step-by-step.
69
89
-**Practice Logical Expressions**: Experiment with logical statements and conditionals to understand how `if` statements, comparisons, and loops work in MicroPython.
70
90
71
-
By mastering REPL, you’ll be well-equipped to make the most of MicroPython’s interactive capabilities and streamline your development process.
91
+
By mastering REPL, you’ll be well-equipped to make the most of MicroPython’s interactive capabilities and streamline your development process.
0 commit comments