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)
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:
- Switch between 6 different drawing modes
- Adjust animation speed
- Reset the artwork
- Save and browse your favorite patterns
This project combines:
- Generative art
- Mathematical visualization
- Interactive hardware design
It can be used as a desktop display or even adapted into a battery-powered wall art piece.
Supplies
Electronics
- ESP32 4.0" Touch Display (ST7796S, 320×480)
- USB-C cable (power + programming)
Optional (Recommended)
- Micro SD card (for saving gallery)
- 3.7V LiPo battery (2000–4000 mAh)
- JST PH 2.0 connector (if supported)
Tools
- Computer with Arduino IDE
- Tinkercad (for enclosure design)
- 3D printer (for case)
Install Arduino IDE and ESP32 Support
Install Arduino IDE (version 2.x recommended)
Open Arduino IDE
Go to:
- 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:
- Tools → Board → Boards Manager
Search for:
- ESP32
Install ESP32 by Espressif Systems
Install Required Library
- Go to:
- Tools → Manage Libraries
- Search for:
- TFT_eSPI
- Install it
⚠️ IMPORTANT:
Do NOT install vendor LCD libraries — they will conflict and cause errors.
Configure the Display (CRITICAL)
- Close Arduino IDE
- Navigate to:...... Documents → Arduino → libraries → TFT_eSPI
- Open...... User_Setup.h
- Press CTRL + A (select all)
- Delete everything
- Paste this EXACT configuration: (attached)
- Save and close the file
Downloads
Test the Display (DO NOT SKIP)
- Open Arduino IDE
- Create a new sketch
- Upload a simple color test
- Set:
- Board → ESP32 Dev Module
- Port → your device
- Click Upload
Expected Result:
- Screen turns RED → GREEN → BLUE → BLACK
- Displays text
👉 If this does not work, fix it before continuing.
Downloads
Fix Common Error
If you see this error:.... TFT_BL already defined
👉 Remove this line from your sketch:..... const int TFT_BL = 27;
Enable Touch Support
- Reopen:... User_Setup.h
- Make sure this line exists:.... #define TOUCH_CS 33
- Save and close
Calibrate the Touchscreen
- Upload a touch calibration sketch
- Follow the on-screen instructions
- Tap all corners carefully
- Open Serial Monitor (115200 baud)
- Copy your result... example: uint16_t calData[5] = { 325, 3521, 291, 3460, 7 };
Your values will be different — use YOUR values
Downloads
Upload the Final Project Code
- Upload the full working project code:
- Before uploading: Find this line:.... uint16_t calData[5] = { ... };
- Replace it with your calibration values.
Downloads
Understanding the 6 Drawing Modes
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
Bottom buttons:
- MODE → switch modes
- RESET → clear drawing
- FAV → save pattern
- GAL → open gallery
- SPEED → adjust animation
(Optional) SD Card Setup
- Insert micro SD card
- Ensure pins:
- CS → 5
- MOSI → 23
- MISO → 19
- SCK → 18
- Restart device
Power Options
Recommended
- USB-C power (desktop display)
Optional (Wall Art Mode)
Use:
- 3.7V LiPo battery (2000–4000 mAh)
Example:
- 4000mAh LiPo with JST PH 2.0 connector
⚠️ Always verify polarity before connecting
Design the Case in Tinkercad
- Measure Your Board
- Create Front Bezel
- Build Back Housing
- Add Openings
- Add Mounting Options
- Optional Battery Space
- Export & Print
Testing & Results
When working correctly:
- Patterns continuously evolve
- Touch controls respond instantly
- Each mode looks visually distinct
- 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
- Save full images instead of parameters
- Add Wi-Fi sharing
- Add animation playback mode
- Add brightness control
- 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:
- dynamic
- visual
- interactive
Instead of just reading π, you can now watch it unfold.