Work Home lab & side projects

An Arduino Nano that draws endless random fractals

I started with a digital pet on an Arduino Nano and OLED, then changed it into a fractal generator. It picks a new type, zoom, rotation and filter every few seconds and rejects mostly blank images.

Arduino Nano
Arduino Nano Photo: MakeMagazinDE, CC BY-SA 4.0

Results

2 KBof RAM to work with
4fractal types, picked at random
5 sbetween new images, with no buttons

The problem

The Nano has very little memory and the 2.42-inch, 128×64 OLED shows one color. Over I2C the display stayed blank or flashed random pixels. And at this size many random fractals come out as an all-white or all-black screen.

What I did

  • Found a working setup in the library examples: 4-wire software SPI with the SSD1306 driver, after I2C and the SSD1309 constructors showed nothing or failed to compile.
  • A digital pet first: hunger and happiness stats, full-screen faces, blinking and heart animations, driven by three buttons.
  • A fractal generator with Mandelbrot, Julia, Burning Ship and Tricorn sets, random zoom, offset and rotation, and invert, XOR and threshold filters.
  • A fill check that rejects images with 1% or less, or 99% or more, of pixels lit, plus a retry guard after it got stuck re-rendering one rejected image.
  • Serial debug output listing each image's type, filter, seed, fill ratio, zoom, offset and rotation.
Fractal generator render loop Each cycle the Arduino Nano picks a random fractal type, filter, seed, zoom, offset and rotation, renders it at 128 by 64 pixels, and checks how many pixels are lit. An image that is almost empty or almost full is rejected and the loop tries a new seed. A good image stays on screen until the timer starts the next one. Randomize type, filter, zoom Render 128 × 64 pixels Fill check count lit pixels Show until the timer almost empty or almost full: new seed next image Random fractal render loop
Each cycle picks random settings, renders, and throws away blank or solid screens.

What I took from it

The diagonal-wipe transition would not fit in the Nano program. I tried reducing debug output, then dropped the transition and kept the fractal generator working within the available memory.

Privacy