The ESP32 is a versatile microcontroller board that is well-known for its built-in Wi-Fi capabilities. Here's an overview of the ESP32 board and its Wi-Fi features:
1- ESP32 Microcontroller:
- The ESP32 is a microcontroller board based on the ESP32 chip, which is developed by Espressif Systems.
- It features a dual-core Xtensa LX6 CPU, which allows for multitasking and processing tasks efficiently.
- The ESP32 includes various built-in peripherals, including GPIO pins, ADCs, DACs, UART, SPI, I2C, and more, making it suitable for a wide range of IoT (Internet of Things) and embedded projects.
2- Wi-Fi Connectivity:
- One of the standout features of the ESP32 is its integrated Wi-Fi capabilities. It supports 2.4 GHz Wi-Fi 802.11 b/g/n, which enables it to connect to wireless networks and the internet.
- The Wi-Fi stack on the ESP32 allows it to act as both a station (client) that can connect to existing Wi-Fi networks and an access point (AP) that can create its own Wi-Fi network for other devices to connect to.
- The ESP32 supports secure Wi-Fi connections using protocols like WPA/WPA2 and even more advanced security features.
3- Applications:
The combination of the ESP32's processing power and built-in Wi-Fi makes it ideal for a wide range of applications, including:
- IoT devices: Sensors and actuators can be connected to the ESP32, which can then transmit data to the cloud or a local server via Wi-Fi.
- Home automation: ESP32 boards can be used to control smart home devices, monitor energy usage, and more.
- Wi-Fi-connected gadgets: You can build Wi-Fi-connected gadgets like weather stations, smart doorbells, and Wi-Fi-controlled robots.
- Internet-connected displays: ESP32 can be used to create web servers, IoT dashboards, and even simple web-based games.
4- Programming:
- The ESP32 can be programmed using various development environments, including the Arduino IDE, PlatformIO, and the Espressif IDF (IoT Development Framework).
- A rich ecosystem of libraries and resources is available for ESP32 development, making it easier to build Wi-Fi-enabled projects.
5- Power Consumption:
The ESP32 is relatively power-efficient, especially when compared to more power-hungry Wi-Fi modules. It offers power-saving features, making it suitable for battery-operated IoT devices.
In summary, the ESP32 board is a popular choice for IoT and embedded projects that require Wi-Fi connectivity. Its combination of a powerful microcontroller, integrated Wi-Fi capabilities, and extensive development support has made it a go-to platform for building a wide range of Wi-Fi-enabled devices and applications.
The web server for the ESP32 card refers to a program or functionality within the ESP32 microcontroller that enables it to handle HTTP requests, allowing it to function as an embedded web server.
This means that the ESP32 microcontroller can be programmed to act as a server, receiving requests (such as accessing a web page or sending data) from a web browser or any other HTTP client and responding to these requests accordingly.
By using libraries such as WiFi.h and WebServer.h in the Arduino development environment, you can configure and manage the web server on the ESP32 board. This capability enables the creation of IoT (Internet of Things) applications where the ESP32 board can be controlled or communicate with other devices via a web browser, mobile app, or any other HTTP client.
In an ESP32 board running MicroPython, the boot.py and main.py files serve specific roles in the boot process and the execution of user code. Here's a brief explanation of each file:
1-boot.py:
- Role: The boot.py file is executed at boot time, specifically during the MicroPython boot sequence. It contains code that is executed immediately after the ESP32 board is powered on or reset.
- Typical Usage:
Setting up configuration options like Wi-Fi credentials.
Initializing hardware or peripherals that should be available as soon as the board starts.
Customizing the boot process, such as setting up specific logging or system-wide settings.
When the ESP32 boots, it first executes the boot.py file. After the boot.py execution, the ESP32 then proceeds to execute the main.py file, if it exists.
2- main.py:
- Role: The main.py file contains the main user code or application logic that you want the ESP32 to run. It is executed after the boot.py during the boot process. If the main.py file is present, it will be executed automatically on boot. If the main.py file does not exist, the board will still boot normally.
- Typical Usage:
Implementing your project's functionality, which could include tasks such as reading sensors, controlling actuators, communicating with other devices, or running a web server.
Structuring your MicroPython code and organizing it into functions, classes, and modules.
Implementing your custom application logic.
ESP32 board:
The ESP32 is a powerful microcontroller developed by Espressif Systems. It's renowned for its integrated Wi-Fi and Bluetooth capabilities, making it a popular choice for various IoT (Internet of Things) applications.
DHT22 Temperature and Humidity Sensor
The DHT22 sensor is used to measure the temperature and the humidity .
Jumper Wires:
For making temporary connections and wiring between components.
Breadboard:
A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.
This represents the basic connections between the DHT22 sensor and the ESP32 board:
- Connect the VCC(+) pin of the DHT22 sensor to the 3.3V pin on the ESP32 board.
- Connect the OUT pin of the DHT22 sensor to a digital pin 2 on the ESP32 board.
- Connect the GND(-) pin of the DHT22 sensor to any ground (GND) pin on the ESP32 board.
To create a web server with MicroPython on the ESP32 to read and send temperature and humidity over Wi-Fi using boot.py and main.py, follow these steps:
1- boot.py: This file will handle the Wi-Fi connection. Make sure to replace 'your_ssid' and 'your_password' with your actual Wi-Fi credentials.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
try: import usocket as socket except: import socket import network from machine import Pin import dht import esp esp.osdebug(None) import gc gc.collect() ssid = 'HUAWEI Y5 2019' # Nom du point d'accès password = 'b582058c4d86' # Mot de passe du point d'accès station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password) while station.isconnected() == False: pass print('Connection successful') print(station.ifconfig()) # Connection of DHT22 dht_pin = dht.DHT22(Pin(23)) |
2- main.py: This file will handle reading temperature and humidity from a DHT sensor and sending the data to a server. Make sure to replace 'your_api_endpoint' with the actual API endpoint where you want to send the data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
def web_page(): html = """<html><head> <title>ESP Web Server</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" href="data:,"> <style>html{font-family: Helvetica; display:inline-block; margin: 0px auto; text-align: center;} h1{color: #0F3376; padding: 2vh;}p{font-size: 1.5rem;}.button{display: inline-block; background-color: #009933; border: none; border-radius: 4px; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;} .button2{background-color: #e7bd3b;} .button3{background-color: #ff0000;} .button4{background-color: #0014ff;}</style></head> <body> <h1>ESP Web Server</h1> <h2> Receive data from DHT22 sensor </h2> <p class="button button3">Temperature: """+str(temp)+""" <span>℃</span></p> <p class="button button4">Humidity: """+str(hum)+""" %</p></body></html>""" return html s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 80)) s.listen(5) red_on=0 green_on=0 while True: conn, addr = s.accept() print('Got a connection from %s' % str(addr)) request = conn.recv(1024) request = str(request) print('Content = %s' % request) dht_pin.measure() temp = dht_pin.temperature() hum = dht_pin.humidity() response = web_page() conn.send('HTTP/1.1 200 OK\n') conn.send('Content-Type: text/html\n') conn.send('Connection: close\n\n') conn.sendall(response) conn.close() |
After saving both boot.py and main.py on your ESP32, it should connect to Wi-Fi on boot and then run the main application to read sensor data and send it to your API endpoint.
Press an EN (Reset) button on the ESP32 board to display the IP address in the Shelle (example IP address is 192.168.1.75).
You can access this data by navigating to the IP address of your ESP32 from a web browser.
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info