MCU Simulator Robotic and Embedded System Laboratory
← Open the simulator
Documentation

Arduino functions and libraries

What a sketch can use: GPIO, timing, serial ports, I2C, SPI, Wi-Fi, MQTT, HTTP, storage, camera, and the libraries.

A sketch uses the Arduino functions and libraries it would use on a real board, with the API of its board's core (arduino-esp32, ESP8266, Arduino AVR, arduino-pico, stm32duino; see Boards). Most of them are the real libraries compiled for the simulator; the parts of the chip that a browser does not have (radio, flash, timers) are imitated.

Arduino basics

AreaFunctions
Digital pinspinMode (INPUT, OUTPUT, INPUT_PULLUP, INPUT_PULLDOWN), digitalWrite, digitalRead, attachInterrupt / detachInterrupt
AnaloganalogRead, analogWrite (PWM), LEDC (ledcAttach, ledcWrite, …), analogWriteRange (ESP8266)
Timemillis, micros, delay, delayMicroseconds; the clock with configTime (NTP) and time() / getLocalTime(), set from your computer's clock
PulsespulseIn, shiftOut, shiftIn, tone / noTone
TextString, Serial.print / println / printf, Serial.read, readStringUntil, …
ChipESP.restart(), ESP.getChipId() (ESP8266), ESP.deepSleep() (waits, then starts again), temperatureRead() (about 50 °C), MAC address from Settings

Serial ports, I2C and SPI

  • Serial is the serial monitor. Serial1 / Serial2 (begin(baud, SERIAL_8N1, rx, tx)) and SoftwareSerial talk to UART parts (GPS, energy meter, CO₂ sensor) wired to those pins. A baud rate that does not match the part gives a warning (on a real board: garbage).
  • Wire (I2C) with real ACK/NACK, so an I2C scanner finds the parts you added (example i2c_scanner.ino).
  • SPI sends bytes to the part whose CS pin is LOW (RFID reader, TFT displays, SD card).

Wi-Fi, MQTT and HTTP

  • WiFi.begin() connects at once to a simulated network (any SSID and password); WiFi.status(), localIP(), RSSI() and macAddress() work.
  • PubSubClient connects to MQTT brokers through WebSocket, with the real buffer of 256 bytes (setBufferSize() to change it) and publishing at QoS 0. WiFiClientSecure gives TLS (setInsecure(), setCACert()).
  • HTTPClient GET / POST / PUT goes through the simulator server to allowed hosts only.

See Network: MQTT and HTTP for how and to where.

Storing data

  • Preferences (NVS), EEPROM, SPIFFS and LittleFS: kept with the project, so they survive ESP.restart(), Stop / Run and reloading the page. Flash size in the simulator: 256 KB. Erase flash in the board panel clears them.
  • SD: a microSD card module (512 KB card); its files are listed on the part, can be downloaded, and the card can be emptied.

Camera (ESP32-CAM)

esp_camera.h: esp_camera_init, esp_camera_fb_get / fb_return, esp_camera_sensor_get with frame size, quality, mirror, flip, brightness and more. Every picture is a real JPEG of the chosen size and quality, from a test pattern or your computer's camera. PIXFORMAT_JPEG only. On a board without a camera, esp_camera_init() fails with 0x105, like a real ESP32.

Libraries

These Arduino libraries are compiled as they are (pinned versions) and can be #included:

LibraryVersion
ArduinoJson7.4.2
Adafruit BusIO1.17.2
Adafruit GFX1.12.4
Adafruit SSD13062.5.15
LiquidCrystal I2C1.1.3
Adafruit Sensor1.1.14
Adafruit BMP2802.6.8
Adafruit MPU60502.2.6
BH17501.3.0
Keypad3.1.1
U8g22.37.1
Adafruit BME2802.3.0
Adafruit AHTX02.0.6
Adafruit SHT312.2.2
Adafruit INA2192.1.0
Adafruit ADS1X152.6.2
HX7110.7.5
TM1637Display1.2.0
TinyGPSPlus1.0.3a
PZEM004Tv301.2.1
MH-Z191.5.4
MFRC5221.4.12
Adafruit ST77351.12.0
Adafruit ILI93411.7.0

Also available, imitated because the real ones drive the chip directly: Adafruit_NeoPixel, OneWire and DallasTemperature, Stepper, DHT, ESP32Servo / Servo.

Not supported

  • OTA updates: Update.begin() and httpUpdate.update() always fail with a clear message; a sketch that uses them still compiles and handles the failure.
  • CoAP and UDP: a browser cannot send UDP.
  • Web servers on the board (WebServer, ESP8266WebServer): nothing could connect to them.
  • Bit timing of serial and SPI lines: bytes arrive whole.