Skip to content
jef-surePublic

About

Spring-mass fish simulation on ESP32 + ILI9341 (Cheap Yellow Display)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

CYD Demo

An ESP-IDF demo for the Cheap Yellow Display that renders a fish-shaped spring-mass simulation on an ILI9341 TFT using the DGX graphics component.

The scene is built from 23 mass points connected by springs. Most of the springs are hidden structural braces; the visible springs and a few colored nodes form a fish silhouette. The fish nose is tethered to a moving anchor point, which keeps the whole shape in motion without any user input.

Fish on CYD

What it does

  • Initializes the CYD display over SPI.
  • Creates a virtual framebuffer the same size as the physical panel.
  • Builds a fish-like truss of balls and coils.
  • Simulates spring forces, damping, boundary bounces, and a moving anchor point.
  • Draws the result to the virtual screen and copies it to the TFT at about 60 FPS.

Physics model

Each coil behaves like a damped spring between two balls.

Along the spring axis, the force is based on Hooke's law plus velocity damping:

F = k * (length - rest_length) + c * (relative_velocity dot axis)

Where:

  • k is the spring stiffness.
  • rest_length is the spring length when the scene is constructed.
  • c is the damping coefficient.
  • axis is the unit vector from one ball to the other.

The simulation uses semi-implicit Euler integration:

  1. Accumulate forces from connected springs.
  2. Convert force to acceleration with a = F / m.
  3. Update velocity with v += a * dt.
  4. Update position with x += v * dt.

To keep the motion stable, the code also clamps speed, rejects non-finite positions, and bounces balls off the screen edges. A global drag constant exists in the source, but the actual drag step is currently commented out; the visible damping comes from the springs and the boundary logic.

Hardware and display wiring

The demo is configured for the CYD-style ILI9341 SPI panel with these pins:

  • MOSI: GPIO 13
  • MISO: GPIO 12
  • SCLK: GPIO 14
  • CS: GPIO 15
  • DC: GPIO 2
  • Backlight: GPIO 21
  • Reset: not connected

Build and flash

Use standard ESP-IDF commands from the project root:

idf.py set-target esp32
idf.py menuconfig
idf.py build
idf.py flash monitor

If you are using a different ESP32 target or a different CYD variant, adjust the target and pin mapping in main/main.c.

Project layout

Notes

  • The rendered fish is not interactive in the current version.
  • The nose is the only actively targeted ball; the anchor point is relocated when the nose gets too close.
  • Rendering uses DGX's virtual screen and ILI9341 driver rather than drawing directly to the panel.

Video

Gummi-Fish

About

Spring-mass fish simulation on ESP32 + ILI9341 (Cheap Yellow Display)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages