ESP32
Aligned with the Introduction’s Blockchain + IoT + AI architecture, ESP32 is the IoT edge: it reads sensors, can run lightweight AI, and signs/transmits telemetry to gateways or on-chain services. This guide shows how to choose Arduino, MicroPython, or ESP‑IDF to build devices that fit the Neurai model and can participate in DePIN‑style sensing and asset‑aware workflows. See the Introduction for the bigger picture.
What you’ll learn
- When to use Arduino Core, MicroPython, or ESP-IDF
- Flashing firmware and running a first program
- Reading sensors, using Wi‑Fi, and sending data to backends
- Good practices: power, security, OTA updates
Prerequisites
- ESP32 dev board (e.g., ESP32‑WROOM, ESP32‑S3)
- USB cable, and a computer with admin rights
- Drivers for your USB‑serial chip (CP210x/CH340 as needed)
Options at a glance
- Arduino Core: fastest learning curve, good library ecosystem.
- MicroPython: write Python on-device, great for quick iteration/teaching.
- ESP‑IDF: official SDK (C/C++), best performance and deep control.
Quickstart — Arduino Core (Blink)
- Install Arduino IDE and add “ESP32 by Espressif Systems” from Boards Manager.
- Select your ESP32 board and the correct serial port.
- New sketch and upload:
// File: Blink.ino
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
If your board has no LED_BUILTIN, pick a known GPIO (e.g., 2) and wire an LED+resistor.
Quickstart — MicroPython (Blink)
- Flash MicroPython firmware for your ESP32 model.
- Open a REPL/Thonny and run:
# main.py
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT) # adjust if your LED is on another GPIO
while True:
led.value(1)
sleep(0.5)
led.value(0)
sleep(0.5)
Quickstart — ESP‑IDF (Hello + Blink)
- Install ESP‑IDF (uses CMake + Ninja). Create a new project from the “blink” template and flash.
- Pros: fine‑grained control, performance, advanced peripherals; Cons: steeper learning curve.
Networking and telemetry
- Wi‑Fi STA/AP: connect to LAN, serve HTTP, or push data to an API/MQTT.
- MQTT: publish sensor readings to a broker; subscribe for remote control.
- Security basics: use TLS when possible, rotate credentials, sign messages.
Next steps
- Sensors: DHT22/HTU21D, BME280, ADS1115, I2C/SPI basics.
- Power: deep sleep, wake sources, battery management.
- OTA: safe remote updates (partition layout, versioning, rollback).