Getting Started

IoT Development Environment Setup

Set up your IoT development environment with Thonny, Arduino IDE, PlatformIO, and online simulators for ESP32 and Raspberry Pi projects.

IoT Development Environment Setup

You can develop IoT applications on any laptop or desktop. This guide covers the tools for MicroPython (ESP32), Arduino (C/C++), and Raspberry Pi (full Python 3).


Option A: MicroPython on ESP32

MicroPython lets you write Python directly on an ESP32 microcontroller.

Step 1 — Install Thonny IDE

Thonny is the easiest way to program MicroPython boards.

Windows/macOS/Linux:
  Download from: https://thonny.org
  Install and open Thonny.

Step 2 — Flash MicroPython Firmware

First, install esptool to flash the firmware:

bash
pip install esptool

Download the latest MicroPython .bin for ESP32 from micropython.org/download/ESP32_GENERIC.

bash
# Erase existing firmware
esptool.py --chip esp32 --port COM3 erase_flash

# Flash MicroPython (replace COM3 with your port, e.g. /dev/ttyUSB0 on Linux)
esptool.py --chip esp32 --port COM3 --baud 460800 \
  write_flash -z 0x1000 esp32-20240105-v1.22.0.bin

Step 3 — Connect via Thonny

  1. In Thonny: Run → Configure interpreter
  2. Select MicroPython (ESP32)
  3. Choose the correct port (COM3, /dev/ttyUSB0, /dev/cu.usbserial-*)
  4. Click OK — you should see the REPL prompt >>>
python
# Type this in the Thonny Shell (REPL) to test
print("Hello from ESP32!")
import machine
print(machine.freq())  # Should print 240000000 (240 MHz)

Option B: Arduino IDE (C/C++)

Step 1 — Install Arduino IDE 2

Download from arduino.cc/en/software.

Step 2 — Add ESP32 Board Support

  1. Open File → Preferences
  2. In "Additional boards manager URLs" add:
    https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  3. Open Tools → Board → Boards Manager
  4. Search "esp32" and install "esp32 by Espressif Systems"

Step 3 — Upload Your First Sketch

cpp
// Blink the built-in LED (GPIO 2 on most ESP32 boards)
void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);
  Serial.println("ESP32 ready!");
}

void loop() {
  digitalWrite(2, HIGH);   // LED on
  delay(1000);              // Wait 1 second
  digitalWrite(2, LOW);    // LED off
  delay(1000);
  Serial.println("Blink!");
}

Select Tools → Board → ESP32 Arduino → ESP32 Dev Module, then click Upload.


PlatformIO supports 1,000+ boards and both MicroPython and Arduino frameworks inside VSCode.

bash
# Install VSCode, then install the PlatformIO extension
# Create a new project: PIO Home → New Project

Your platformio.ini for an ESP32 Arduino project:

ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
  knolleary/PubSubClient @ ^2.8     ; MQTT
  adafruit/DHT sensor library @ ^1.4.4  ; DHT22 sensor

Option D: Raspberry Pi (Full Python 3)

If you have a Raspberry Pi, use Python 3 directly with the system's GPIO libraries.

bash
# Update your Pi
sudo apt update && sudo apt upgrade -y

# Install GPIO library
sudo apt install python3-rpi.gpio python3-pip -y

# Install common IoT libraries
pip3 install paho-mqtt requests adafruit-circuitpython-dht
python
# Test GPIO access (Python 3 on Raspberry Pi)
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)  # Set GPIO 18 as output
GPIO.output(18, GPIO.HIGH)  # Turn on

import time
time.sleep(1)

GPIO.output(18, GPIO.LOW)   # Turn off
GPIO.cleanup()
print("GPIO test complete")

Online Simulators (No Hardware Required)

You can start learning IoT without buying any hardware.

Wokwi — Best Online ESP32/Arduino Simulator

Visit wokwi.com:

  • Simulate ESP32, Arduino, Raspberry Pi Pico
  • Add virtual sensors (DHT22, PIR, LDR, LCD)
  • Use MicroPython or Arduino C/C++
  • Share projects via URL
python
# This MicroPython code runs in Wokwi without real hardware
from machine import Pin
import time

led = Pin(2, Pin.OUT)

while True:
    led.on()
    print("LED ON")
    time.sleep(0.5)
    led.off()
    print("LED OFF")
    time.sleep(0.5)

Tinkercad Circuits


Virtual Environment for PC Development

For cloud-side Python development (data pipelines, MQTT clients):

bash
# Create and activate a virtual environment
python -m venv iot-env

# Windows
iot-env\Scripts\activate

# macOS/Linux
source iot-env/bin/activate

# Install common IoT Python libraries
pip install paho-mqtt requests influxdb-client pandas matplotlib \
            flask fastapi uvicorn python-dotenv

Project Directory Structure

my-iot-project/
├── device/                 # Firmware (MicroPython or Arduino)
│   ├── main.py             # MicroPython entry point
│   ├── config.py           # WiFi credentials, MQTT settings
│   └── sensors/
│       └── dht22.py        # Sensor driver module
├── server/                 # Cloud/backend code (Python 3)
│   ├── subscriber.py       # MQTT subscriber
│   ├── api.py              # FastAPI endpoints
│   └── db.py               # InfluxDB client
├── dashboard/              # Grafana config or web UI
└── README.md

Summary

  • Thonny + MicroPython is the easiest path for ESP32 development
  • Arduino IDE is ideal for C/C++ sketches and the Arduino library ecosystem
  • PlatformIO is the professional choice for larger projects in VSCode
  • Raspberry Pi runs full Python 3 with direct GPIO access
  • Wokwi lets you simulate ESP32/Arduino projects without any hardware
  • Keep device firmware and cloud server code in separate directories

Next, we'll explore the microcontrollers and single-board computers that power IoT projects.