Skip to content

About

Real-time fluid (water) simulation on ESP32-C3 + OLED + MPU6050 accelerometer, FLIP method. Web simulator generates the Arduino sketch.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

ESP32 fluid simulation on an OLED screen (FLIP, MPU6050)

English · Français

Real-time water / liquid simulation for ESP32-C3 + I2C OLED + MPU6050 accelerometer: tilt the board and the fluid flows. A web page runs the same simulation in your browser, lets you tune every parameter and generates the Arduino sketch, ready to upload.

Live demo: https://fluide.pierref.eu (gravity follows your mouse).

Web simulator and sketch generator

  • Web page: same simulation as on the ESP32, live. Sliders for screen size, matrix size, render area, physics, colours, pins. Fullscreen mode.
  • Firmware: Arduino sketch in fixed-point math (the C3 has no FPU), tested on PC.
  • One settings source: firmware/settings.json, read by the web page and the Python tools.
  • Free, MIT license, no dependency beyond Python 3 for the tools.

Quick start

git clone https://github.com/evaspace/esp32-fluid-simulation.git
cd esp32-fluid-simulation
make serve            # http://localhost:8000

Without make: python3 tools/serve.py.

Upload to the ESP32

Arduino IDE: tune the simulation in the page, click Copy the sketch, paste it in the IDE. Board ESP32C3 Dev Module, USB CDC On Boot: Enabled, then Upload. Needs Espressif's esp32 board package and the U8g2 library.

Command line (arduino-cli):

make setup                       # once: ESP32 support + U8g2
make flash                       # default settings
make flash CONFIG=config.json    # settings exported from the page
make monitor                     # fps and compute time

The USB port is detected automatically. Force it with make flash DEVICE=/dev/ttyACM0.

Hardware

Part Default
Board ESP32-C3 (SuperMini or similar)
Screen Any U8g2 I2C OLED: SSD1306, SH1106, SSD1309, SH1107, SSD1327… (128×64, 128×32, 72×40, 64×48, 128×128)
Accelerometer MPU6050 (I2C, address 0x68 or 0x69)
Wiring OLED and MPU6050 on the same bus. SDA 8, SCL 9 on the C3 SuperMini; SDA 5, SCL 6 on the C3 with built-in 0.42" OLED

If the water goes the wrong way, use the "invert X/Y axis" or "swap axes" boxes.

How the simulation works

FLIP method (FLuid-Implicit-Particle): particles carry the fluid, a staggered MAC grid keeps it incompressible. Each step: gravity from the accelerometer, particle separation with a spatial hash, wall collisions, particles to grid, Gauss-Seidel pressure solve with over-relaxation and drift compensation, grid to particles (FLIP/PIC blend), then the density is interpolated per OLED pixel and thresholded for a smooth surface (dithered mode available).

Commands

Command Does
make serve Web page on http://localhost:8000
make bundle dist/fluide.html: the page as one file, no server
make configure CONFIG=… Generate the sketch in build/fluide_esp32/
make compile / make flash Compile / upload with arduino-cli
make test Build the firmware on PC with fake Arduino headers and check the fluid on several screens
make docker-build / make docker-run Web page served by Caddy in Docker on http://localhost:8080

Details (Docker, file tree): see README.fr.md.

License

MIT

About

Real-time fluid (water) simulation on ESP32-C3 + OLED + MPU6050 accelerometer, FLIP method. Web simulator generates the Arduino sketch.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages