From b921ab2a9d73238d01b834d88b332ed2a473382a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:40:34 +0100 Subject: [PATCH 1/3] REPL review --- .../{00. REPL => 01.repl}/repl.md | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) rename content/micropython/03.micropython/02.enviroment/{00. REPL => 01.repl}/repl.md (67%) diff --git a/content/micropython/03.micropython/02.enviroment/00. REPL/repl.md b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md similarity index 67% rename from content/micropython/03.micropython/02.enviroment/00. REPL/repl.md rename to content/micropython/03.micropython/02.enviroment/01.repl/repl.md index a68e4b1a81..fa78bef89c 100644 --- a/content/micropython/03.micropython/02.enviroment/00. REPL/repl.md +++ b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md @@ -1,16 +1,13 @@ --- - -featured: micropython-101 -title: '1. Micropython Environment - REPL' +title: 'REPL' description: 'Learn the basics for loops on MicroPython.' author: 'Pedro Lima' -hero_image: "./hero-banner.png" - +tags: [MicroPython, REPL] --- -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. +**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. -We’ll walk through what REPL does, why it’s useful, and how you can use it to enhance your MicroPython experience. +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. ## What is REPL? @@ -23,6 +20,10 @@ The REPL process involves four basic steps: 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. +## print() + + + ## How REPL Works in MicroPython 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,9 +33,28 @@ In MicroPython, REPL can be accessed via Arduino Labs for MicroPython terminal, 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. 4. **Iterate**: The loop resets, and you can immediately enter more code, building on previous commands or testing new lines independently. -## Example: Using REPL in MicroPython +## Example: Store and Print Your Name -Let's see a simple REPL session to add two numbers interactively: +Let's create a REPL session, where you will enter your name, and then print it. + +Connect your board, and click on the **RUN** button with an empty script, then enter the following things in the REPL, line by line. + +``` +>>> name = "Pedro" +>>> name +``` + +When writing `name` in the REPL, (after `name = "Pedro"`), we should get: + +``` +'Pedro' +``` + +![TODO: GIF showing step by step so people understand to run each individually]() + +## Example: Perform a Calculation in the REPL + +Now let's create a REPL session that performs a calculation, by adding two numbers together: ```python >>> a = 5 @@ -42,12 +62,13 @@ Let's see a simple REPL session to add two numbers interactively: >>> a + b 8 ``` -TODO: GIF showing step by step so people understand to run each individually !()[] -In this REPL session: +![TODO: GIF showing step by step so people understand to run each individually]() + +In this REPL session, we: -- **Define variables**: We set `a` to 5 and `b` to 3. -- **Perform calculation**: Entering `a + b` immediately returns `8`, showing the result without having to write a full script. +- Defined variables by setting `a` to `5` and `b` to `3`. +- Performed a calculation by entering `a + b`, which immediately returns `8`, showing the result without having to write a full script. ## Common Uses of REPL @@ -57,7 +78,7 @@ REPL is particularly useful for: - **Debugging**: Test small parts of a larger project interactively. - **Learning**: Practice MicroPython commands and get instant feedback, ideal for beginners. -## Going Further With REPL +## Summary 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. @@ -68,4 +89,4 @@ REPL in MicroPython is an useful tool that enables instant testing and feedback, - **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. - **Practice Logical Expressions**: Experiment with logical statements and conditionals to understand how `if` statements, comparisons, and loops work in MicroPython. -By mastering REPL, you’ll be well-equipped to make the most of MicroPython’s interactive capabilities and streamline your development process. +By mastering REPL, you’ll be well-equipped to make the most of MicroPython’s interactive capabilities and streamline your development process. \ No newline at end of file From a7a75b6812884b947ffcb00a34a3e4e142a0316a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:41:09 +0100 Subject: [PATCH 2/3] Update repl.md --- .../micropython/03.micropython/02.enviroment/01.repl/repl.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/micropython/03.micropython/02.enviroment/01.repl/repl.md b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md index fa78bef89c..63b2f18912 100644 --- a/content/micropython/03.micropython/02.enviroment/01.repl/repl.md +++ b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md @@ -1,6 +1,6 @@ --- title: 'REPL' -description: 'Learn the basics for loops on MicroPython.' +description: 'Learn how to use the REPL (Read-Eval-Print Loop) in MicroPython.' author: 'Pedro Lima' tags: [MicroPython, REPL] --- From 5e53628e67e9ef4119e31d3a97b9b9699e225636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:05:23 +0100 Subject: [PATCH 3/3] Update content/micropython/03.micropython/02.enviroment/01.repl/repl.md Co-authored-by: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> --- content/micropython/03.micropython/02.enviroment/01.repl/repl.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/micropython/03.micropython/02.enviroment/01.repl/repl.md b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md index 63b2f18912..f654bfd45f 100644 --- a/content/micropython/03.micropython/02.enviroment/01.repl/repl.md +++ b/content/micropython/03.micropython/02.enviroment/01.repl/repl.md @@ -20,7 +20,6 @@ The REPL process involves four basic steps: 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. -## print()