Skip to content

About

ESP32 Minecraft - can we do it?

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ESPcraft

ESP-IDF: ESP32-S3 ILI9341 + XPT2046 Touch Test

This repository also contains a minimal ESP-IDF project (native C, no Arduino, no GUI framework) that tests an ILI9341 display (SPI2) and an XPT2046 touchscreen (SPI3) simultaneously on an ESP32-S3 N16R8. Files: CMakeLists.txt, sdkconfig.defaults, Kconfig.projbuild, main/.

Hardware wiring

ILI9341 (SPI2_HOST) GPIO XPT2046 (SPI3_HOST) GPIO
CS 10 T_CS 17
RESET 8 T_CLK 18
DC 9 T_DIN (MOSI) 16
MOSI / SDI 11 T_DO (MISO) 15
SCK 12 T_IRQ 14
MISO / SDO 13

The two SPI controllers are genuine independent peripherals (SPI2 vs SPI3) with independent chip-select lines, both configured at 40 MHz initially.

Build & flash

# Source the ESP-IDF environment (adjust IDF_PATH as needed)
export IDF_PATH=/home/superuser/esp-idf
. $IDF_PATH/export.sh

cd /home/superuser/esp32craft-project
idf.py set-target esp32s3
idf.py build
idf.py -p /dev/ttyUSB0 flash monitor

Use idf.py menuconfig to adjust GPIOs, SPI clocks, screen size and touch calibration (see the "ESP32-S3 ILI9341 + XPT2046 Test" menu). Pins default to the values in the table above.

Touch calibration

The XPT2046 returns raw 12-bit ADC values that must be mapped to display pixels. Enable TOUCH_DEBUG in menuconfig and open the serial console (115200 baud); touch the four corners and note the raw X/Y values, then set:

  • CAL_X_MIN / CAL_X_MAX — raw X at the left/right display edges
  • CAL_Y_MIN / CAL_Y_MAX — raw Y at the top/bottom display edges
  • CAL_SWAP_AXES — enable if horizontal finger motion moves the crosshair vertically (panel mounted rotated 90°)
  • CAL_INVERT_X / CAL_INVERT_Y — mirror an axis if left/right or top/bottom are reversed

Defaults (200 / 3800 for both axes) are placeholders; you must measure your own panel. A crosshair (white by default) is drawn at the calibrated touch position and follows the finger; it is erased (redrawn in black) when the position changes or when the finger is lifted.

Behaviour

  • Display initialises with a black background (RGB565, 320×240 landscape).
  • Touch is polled via T_IRQ (active low) at 50 Hz.
  • A crosshair is drawn under the finger and tracks movement.
  • DMA is used on the display SPI bus; no full framebuffer is allocated.
  • LVGL / GUI frameworks are not used.

A work-in-progress Minecraft-like voxel game/client for ESP32, redesigned as a new voxel engine targeting ESP32-S3 and the new ESP32-S31 (dual-core 320 MHz RISC-V, 512 KB SRAM, 250 MHz DDR PSRAM, 60 GPIO, Wi-Fi 6 / BT 5.4 / Ethernet).

Hardware

Target platforms:

  • ESP32-S3 (current dev)
  • ESP32-S31 (next-gen, announced 2026; 320 MHz dual-core RISC-V, 512 KB SRAM, 8-bit 250 MHz DDR PSRAM)
  • TFT display using TFT_eSPI
  • Development board: any ESP32-S3 / ESP32-S31 with PSRAM and TFT

Repository

  • espcraft.ino — new voxel engine (replaces legacy prototype)
  • spritesheet.bmp — programmer-art spritesheet (8×8 tiles, 16×16 px each, 24-bit BMP)
  • spritesheet.h — embedded RGB565 atlas array (PROGMEM), includes black/purple fallback
  • 3d_render/ — legacy/prototype wireframe renderer (archival reference only)
  • generation_lut/ — legacy LUT generator (archival reference only)
  • ESP32-S31 hardware reference assets (from espressif/kicad-libraries#233, created by blobcoder21):
    • footprints/Espressif.pretty/ESP32-S31-QFN.kicad_mod (QFN package footprint)
    • symbols/Espressif.kicad_sym (symbol library, includes ESP32-S31 reference)
    • 3dmodels/espressif.3dshapes/ESP32-S31-QFN.STEP (3D model, 1.8 MB, FreeCAD 7.9, QFN 80 0.35 mm pitch 8×8 mm) These are authoritative reference assets for the ESP32-S31 QFN package and should not be regenerated from descriptions.

New Engine Features

  • Configurable sprite atlas: ATLAS_TILE_PX, BLOCK_TILE_W, BLOCK_TILE_H, ATLAS_TILES_W, ATLAS_TILES_H are fully configurable. Changing them does not require rewriting the renderer.
  • Built-in spritesheet loader: spritesheet.h provides an embedded PROGMEM array with basic programmer-art textures (solid colors + one checkered tile). A real spritesheet can replace this array or be loaded from external storage.
  • Classic black/purple fallback: missing or out-of-bounds texture references return FALLBACK_BLACK (0x0000) and FALLBACK_PURPLE (0xF81F).
  • Pre-baked Perlin continuous terrain: generateWorld() creates layered stone/dirt/grass terrain with decorative trees at startup.
  • Chunk-based voxel world: CHUNK_SIZE 8, expandable to multi-chunk.
  • Filled voxel rendering with basic face shading (lighter top, darker bottom, medium sides) and black edge outlines.
  • Camera: yaw/pitch rotation, perspective projection (FOV 64, NEAR_CLIP 0.25).
  • AABB collision (checkVoxelCollision, resolveCollision).
  • Block interaction hooks: interactBreak() (raycast), interactPlace() (distance check).
  • Serial input (w/a/s/d move, b break, p place, q/e yaw, r/f pitch).
  • GPIO stub (handleGPIOInputStub) for ESP32-S3 / ESP32-S31 device-specific buttons.

Texture System Design

The renderer is designed so that textures can be added without rewriting it:

  • BlockDef defines flatColor (fallback), texTileX, and texTileY (atlas reference).
  • getFaceColor() samples from the atlas array using the block's texture reference.
  • Each block texture spans BLOCK_TILE_W × BLOCK_TILE_H tiles in the atlas.
  • The atlas dimensions and tile dimensions are pure configuration (#define).

To upgrade to real textures:

  1. Replace or extend SPRITESHEET_DATA in spritesheet.h, or load from SD/PSRAM at runtime.
  2. Adjust BlockDef::texTileX / texTileY to point to the new texture region.
  3. Optionally replace getFaceColor() with per-pixel atlas sampling for full textured faces.

Status

Experimental / actively redesigned. The legacy renderer in 3d_render/ is preserved only as reference architecture. The new espcraft.ino is the primary development target.

About

ESP32 Minecraft - can we do it?

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages