Touch Pi: a Pi Art Generator (ESP32 Touchscreen)

by The Debunker in Circuits > Electronics

1681 Views, 12 Favorites, 0 Comments

Touch Pi: a Pi Art Generator (ESP32 Touchscreen)

IMG_6495.JPG
4 of the modes.png
IMG_6494.JPG

Pi (π) is one of the most famous numbers in mathematics—an infinite, non-repeating sequence of digits that appears everywhere from geometry to physics.

But most of the time, we experience π as… just numbers.

In this project, I wanted to turn π into something visual, interactive, and alive.

I built a standalone touchscreen device using an ESP32 and a 4.0" display that transforms the digits of π into real-time generative art. Each digit influences motion, color, and geometry, creating evolving patterns that never repeat.

With a simple touch interface, you can:

  1. Switch between 6 different drawing modes
  2. Adjust animation speed
  3. Reset the artwork
  4. Save and browse your favorite patterns

This project combines:

  1. Generative art
  2. Mathematical visualization
  3. Interactive hardware design

It can be used as a desktop display or even adapted into a battery-powered wall art piece.

Supplies

IMG_6477.JPG

Electronics

  1. ESP32 4.0" Touch Display (ST7796S, 320×480)
  2. USB-C cable (power + programming)

Optional (Recommended)

  1. Micro SD card (for saving gallery)
  2. 3.7V LiPo battery (2000–4000 mAh)
  3. JST PH 2.0 connector (if supported)

Tools

  1. Computer with Arduino IDE
  2. Tinkercad (for enclosure design)
  3. 3D printer (for case)

Install Arduino IDE and ESP32 Support

Screenshot 2026-04-11 085158.png

Install Arduino IDE (version 2.x recommended)

Open Arduino IDE

Go to:

  1. File → Preferences

In “Additional Board Manager URLs”, paste:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Click OK


Go to:

  1. Tools → Board → Boards Manager

Search for:

  1. ESP32

Install ESP32 by Espressif Systems

Install Required Library

Screenshot 2026-04-07 181923.png
  1. Go to:
  2. Tools → Manage Libraries
  3. Search for:
  4. TFT_eSPI
  5. Install it

⚠️ IMPORTANT:

Do NOT install vendor LCD libraries — they will conflict and cause errors.

Configure the Display (CRITICAL)

Screenshot 2026-04-07 190407.png
  1. Close Arduino IDE
  2. Navigate to:...... Documents → Arduino → libraries → TFT_eSPI
  3. Open...... User_Setup.h
  4. Press CTRL + A (select all)
  5. Delete everything
  6. Paste this EXACT configuration: (attached)
  7. Save and close the file

Test the Display (DO NOT SKIP)

Screenshot 2026-04-07 190359.png
IMG_6447.JPG
  1. Open Arduino IDE
  2. Create a new sketch
  3. Upload a simple color test
  4. Set:
  5. Board → ESP32 Dev Module
  6. Port → your device
  7. Click Upload

Expected Result:

  1. Screen turns RED → GREEN → BLUE → BLACK
  2. Displays text

👉 If this does not work, fix it before continuing.

Fix Common Error

IMG_6446 (1).JPG

If you see this error:.... TFT_BL already defined

👉 Remove this line from your sketch:..... const int TFT_BL = 27;

Enable Touch Support

Screenshot 2026-04-11 085434.png
  1. Reopen:... User_Setup.h
  2. Make sure this line exists:.... #define TOUCH_CS 33
  3. Save and close

Calibrate the Touchscreen

  1. Upload a touch calibration sketch
  2. Follow the on-screen instructions
  3. Tap all corners carefully
  4. Open Serial Monitor (115200 baud)
  5. Copy your result... example: uint16_t calData[5] = { 325, 3521, 291, 3460, 7 };

Your values will be different — use YOUR values

Upload the Final Project Code

IMG_6478.JPG
IMG_6482.JPG
IMG_6481.JPG
  1. Upload the full working project code:
  2. Before uploading: Find this line:.... uint16_t calData[5] = { ... };
  3. Replace it with your calibration values.

Understanding the 6 Drawing Modes

IMG_6479.JPG
IMG_6480.JPG
IMG_6484.JPG
IMG_6449.JPG
IMG_6453.JPG
IMG_6452.JPG

This project includes six unique visualizations of π:

🥇 Pi Walker

Digits control direction → organic path drawing

🥈 Pi Chords

Connects points around a circle → geometric webs

🥉 Pi Bloom

Radial growth patterns → flower-like visuals

🏅 Pi Grid

Digit → color mapping → pixel-style fingerprint

🌀 Pi Spiral

Expanding spiral motion with variation

🌊 Pi Wave

Wave patterns driven by digit sequences

Touch Interface

IMG_6458.JPG

Bottom buttons:

  1. MODE → switch modes
  2. RESET → clear drawing
  3. FAV → save pattern
  4. GAL → open gallery
  5. SPEED → adjust animation


(Optional) SD Card Setup

IMG_6501.JPG
  1. Insert micro SD card
  2. Ensure pins:
  3. CS → 5
  4. MOSI → 23
  5. MISO → 19
  6. SCK → 18
  7. Restart device


Power Options

IMG_6445.JPG

Recommended

  1. USB-C power (desktop display)

Optional (Wall Art Mode)

Use:

  1. 3.7V LiPo battery (2000–4000 mAh)

Example:

  1. 4000mAh LiPo with JST PH 2.0 connector

⚠️ Always verify polarity before connecting

Design the Case in Tinkercad

IMG_6487.JPG
Screenshot 2026-04-10 091934.png
Screenshot 2026-04-10 104925.png
Screenshot 2026-04-10 104945.png
Screenshot 2026-04-10 105514.png
Screenshot 2026-04-10 110454.png
IMG_6493.JPG
IMG_6500.JPG
  1. Measure Your Board
  2. Create Front Bezel
  3. Build Back Housing
  4. Add Openings
  5. Add Mounting Options
  6. Optional Battery Space
  7. Export & Print



Testing & Results

IMG_6451.JPG
IMG_6450.JPG
IMG_6460.JPG
IMG_6483.JPG

When working correctly:

  1. Patterns continuously evolve
  2. Touch controls respond instantly
  3. Each mode looks visually distinct
  4. Saved patterns can be reloaded

👉 The best moment is watching patterns emerge from π in real time.

Challenges & Fixes

White Screen

✔ Fixed by correct pin configuration

Touch Not Working

✔ Fixed by calibration

Display Glitches

✔ Fixed by proper screen dimensions

Library Conflicts

✔ Solved by using only TFT_eSPI

Improvements / Future Ideas

  1. Save full images instead of parameters
  2. Add Wi-Fi sharing
  3. Add animation playback mode
  4. Add brightness control
  5. Create themed frames (wood, acrylic)

Final Thoughts

π is infinite—but we usually experience it in a very static way.

This project transforms it into something:

  1. dynamic
  2. visual
  3. interactive

Instead of just reading π, you can now watch it unfold.