From cfcf7eb8b62b6bf3acfd9000fc9aa396d9f16da2 Mon Sep 17 00:00:00 2001 From: zvevqx Date: Thu, 21 Mar 2024 13:13:40 +0100 Subject: [PATCH] added upython.md --- pages/upython.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/pages/upython.md b/pages/upython.md index 2ece3e7..69444d0 100644 --- a/pages/upython.md +++ b/pages/upython.md @@ -43,4 +43,84 @@ Fedora sudo dnf install thonny ``` +Sure, here's the introduction to MicroPython with Thonny IDE and ESP32 as a microcontroller, written entirely in raw Markdown with code examples. +```markdown +# Introduction to MicroPython with Thonny IDE and ESP32 + +## What is MicroPython? + +MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers and in constrained environments. [MicroPython Documentation](https://docs.micropython.org/en/latest/index.html) + +## What is Thonny IDE? + +Thonny is a Python IDE for beginners. It has a simple and clean interface, and it is designed specifically for teaching and learning programming. [Thonny IDE](https://thonny.org/) + +## What is ESP32? + +ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. [ESP32 Series](https://www.espressif.com/en/products/socs/esp32) + +## Getting Started + +1. **Install Thonny IDE**: Download and install Thonny IDE from the official website. It's available for Windows, macOS, and Linux. [Thonny IDE](https://thonny.org/) + +2. **Set up ESP32 with MicroPython**: You'll need to flash the MicroPython firmware onto your ESP32 board. You can do this using a tool like esptool.py. Once you've flashed the firmware, you can connect to the ESP32 using Thonny. [Getting Started with ESP32 and MicroPython](https://randomnerdtutorials.com/micropython-programming-esp32-esp8266/) + +3. **Write Your First Program**: In Thonny, you can write Python code in the editor on the left and see the output in the shell on the right. Try writing a simple program like blinking an LED or printing to the serial console. + +```python +from machine import Pin, Timer + +led = Pin(2, Pin.OUT) # create output pin on GPIO2 +tim = Timer(-1) # create software timer + +def blink(timer): + led.toggle() # toggle LED + +tim.init(freq=2.5, mode=Timer.PERIODIC, callback=blink) # blink LED at 2.5Hz +``` + +This code will blink an LED connected to GPIO2 of the ESP32 at a frequency of 2.5Hz. + +## Basic Python Concepts + +- **Variables**: Variables are used to store data. They can hold different types of values, like numbers, strings, and lists. + +```python +x = 10 # integer +y = "Hello, World!" # string +z = [1, 2, 3] # list +``` + +- **Functions**: Functions are reusable blocks of code that perform a specific task. They help break down complex programs into smaller, more manageable parts. + +```python +def greet(name): + print(f"Hello, {name}!") + +greet("Alice") # prints "Hello, Alice!" +``` + +- **Control Flow**: Control flow statements, like if/else and for/while loops, determine the order in which code is executed. + +```python +for i in range(5): + print(i) # prints numbers from 0 to 4 + +x = 10 +if x > 0: + print("x is positive") # prints "x is positive" +``` + +## References + +- [MicroPython Documentation](https://docs.micropython.org/en/latest/index.html) +- [Thonny IDE](https://thonny.org/) +- [ESP32 Series](https://www.espressif.com/en/products/socs/esp32) +- [Getting Started withomitempty ESP32 and MicroPython](https://randomnerdtutorials.com/micropython-programming-esp32-esp8266/) +- [First Steps with ESP32 and MicroPython](https://docs.micropython.org/en/latest/esp32/quickref.html) +- [Python Variables](https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming) +- [Python Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) +- [Python Control Flow](https://docs.python.org/3/tutorial/controlflow.html) +``` +This markdown text contains all the information, links, and code examples in raw markdown format.