Yarana Iot Guru
Published © MIT

Unlocking MicroPython on Arduino Nano ESP32

Run MicroPython on the Arduino Nano ESP32 — flash firmware, use REPL, build micro‑Python projects quickly. Perfect for rapid prototyping

BeginnerProtip8 hours23
Unlocking MicroPython on Arduino Nano ESP32

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Wi‑Fi connect + simple webserver (webrepl optiona

C/C++
# wifi_web.py - Connect to WiFi and run a tiny webserver
import network
import socket
import machine

SSID = 'YourSSID'
PASSWORD = 'YourPassword'
LED_PIN = 2

led = machine.Pin(LED_PIN, machine.Pin.OUT)

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)

# wait for connection
import time
for _ in range(20):
    if wlan.isconnected():
        break
    time.sleep(1)

print('Network config:', wlan.ifconfig())

# simple HTTP server
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print('Listening on', addr)

while True:
    cl, addr = s.accept()
    print('Client connected from', addr)
    req = cl.recv(1024).decode('utf-8')
    # Basic route handling
    if '/?led=on' in req:
        led.on()
    if '/?led=off' in req:
        led.off()
    response = """HTTP/1.1 200 OK
Content-Type: text/html

<html>
  <head><title>Nano ESP32</title></head>
  <body>
    <h1>YaranaIoT Guru - Nano ESP32</h1>
    <p><a href="/?led=on">Turn LED ON</a></p>
    <p><a href="/?led=off">Turn LED OFF</a></p>
  </body>
</html>
"""
    cl.send(response)
    cl.close()

Blink (main.py)

C/C++
# main.py - Blink LED on Nano ESP32
import machine
import time

LED_PIN = 2  # change if your board uses different pin

led = machine.Pin(LED_PIN, machine.Pin.OUT)

while True:
    led.on()
    time.sleep(0.5)
    led.off()
    time.sleep(0.5)

Credits

Yarana Iot Guru
30 projects • 0 followers
Yarana Iot Guru Yarana IoT Guru: Arduino, ESP32, GSM, NodeMCU & more. Projects, Tutorials & App Development. Innovate with us!
Thanks to YaranaIoT Guru.

Comments