Build a handheld gaming device powered by an ESP32 microcontroller, 2.8-inch capacitive touchscreen, and analog joystick. This portable console includes SD card storage for game assets, Class-D amplified audio output through a speaker, and rechargeable 18650 battery power with integrated charging and boost circuitry. The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions to integrate all components into a 3D-printed enclosure.
The firmware demonstrates core functionality including display rendering, joystick input handling, tactile button debouncing, and I2S audio synthesis. Builders will learn how to interface multiple peripherals over SPI and I2C, manage power delivery from a single-cell lithium battery, and structure a game loop that responds to user input while generating audio feedback. All code and hardware specifications are included to get the console running immediately after assembly.
Wiring diagram

Gather all the parts
Assemble it in 5 steps
1. Wire the 3.3 V screen and storage
Drive GPIO17 into LCD_BL only on the specified Waveshare board with its onboard backlight transistor. Follow the wiring diagram for the Waveshare V2 13-pin header and Adafruit 3 V-only SD breakout. Share clock and MOSI; leave the screen MISO and all touch lines disconnected. Install the two chip-select pull-ups and place both SD capacitors near the socket. Insert a FAT32-formatted card with power off.
2. Install the joystick and buttons
Feed the joystick 3.3 V even though its header says +5V. Identify the two switch contact groups on each tactile button with a continuity meter; use one leg from each group. Fit the external pull-ups on Select and joystick click.
3. Wire the amplifier and speaker
Match SPK+ to speaker + and SPK- to speaker -. Neither speaker wire is ground. Leave SD and GAIN at the Adafruit breakout defaults. Install the ceramic and electrolytic bypass capacitors near the amp and ESP32 supply pins; the electrolytic stripe faces ground.
4. Assemble and test the charging circuit separately
Use the documented T6845-C V1.0 with micro-USB input and USB-A output. Check holder polarity before installing the protected cell. Connect holder positive to B+ and negative to B-. Take regulated power from a USB-A power lead using VBUS and ground only; verify the lead with a meter rather than relying on wire colors. Disconnect the service feed when charging or plugging USB into the ESP32. Charge from a 5 V USB wall supply rated 2 A. Check module temperature, both rail voltages and current during startup, SD writes and tones, with a full and partly discharged cell. Check for idle auto-off. Do not qualify full-volume audio based on the quiet demo.
- Do not charge while playing. Never join the charger output and the ESP32 USB supply. Do not use an unprotected cell or a board with different terminals.
5. Fit the tested parts into a printed enclosure
Lay out the screen in the center, joystick on the left, A and B on the right, and Start and Select below the screen. Measure actual board outlines, connector clearances and hole centers before making the print. Use insulated standoffs, a retained cell holder, ventilation over the charger, a speaker grille, and access to the SD card and service connector. Provide a service opening for the removable power feed and arrange a mechanical access cover so the ESP32 USB cannot be plugged in until the service feed is removed. Leave plastic clearance around the antenna and strain-relieve the wires.
Review all connections
1. Connections between "lcd" and "ESP32"
2. Connections between "sd" and "ESP32"
3. Connections between "stick" and "ESP32"
4. Connections between "a" and "ESP32"
5. Connections between "b" and "ESP32"
6. Connections between "start" and "ESP32"
7. Connections between "select" and "ESP32"
8. Connections between "r_tft" and "ESP32"
9. Connections between "r_sd" and "ESP32"
10. Connections between "r_select" and "ESP32"
11. Connections between "r_sw" and "ESP32"
12. Connections between "amp" and "ESP32"
13. Connections between "holder" and "ESP32"
14. Connections between "cell" and "ESP32"
15. Connections between "charger" and "ESP32"
16. Connections between "disconnect" and "ESP32"
17. Connections between "cer_esp" and "ESP32"
18. Connections between "bulk_esp" and "ESP32"
19. Connections between "cer_amp" and "ESP32"
20. Connections between "bulk_amp" and "ESP32"
21. Connections between "cer_sd" and "ESP32"
22. Connections between "bulk_sd" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_ST7789.h>
#include <driver/i2s.h>
constexpr int TFT_CS=21, SD_CS=13, TFT_BL=17, STICK_SW=4;
constexpr int16_t DEMO_TONE_LEVEL=2200; // Keep demo tones well below full scale.
Adafruit_ST7789 lcd(&SPI,TFT_CS,22,16);
struct Key { int pin; bool raw=false, stable=false; uint32_t since=0; };
Key keys[]={{27},{14},{32},{36},{39}};
bool mounted=false,audio=false; int x=160,y=120,cx,cy; unsigned score=0;
void beep(int hz) {
if(!audio)return;
int16_t samples[256]; unsigned phase=0;
for(int j=0;j<10;j++) {
for(int i=0;i<256;i+=2){phase=(phase+hz)%16000; samples[i]=samples[i+1]=j==9?0:(phase<8000?DEMO_TONE_LEVEL:-DEMO_TONE_LEVEL);}
size_t written=0; if(i2s_write(I2S_NUM_0,samples,sizeof(samples),&written,pdMS_TO_TICKS(30))!=ESP_OK)break;
}
}
void initAudio(){
i2s_config_t c={}; c.mode=(i2s_mode_t)(I2S_MODE_MASTER|I2S_MODE_TX); c.sample_rate=16000;
c.bits_per_sample=I2S_BITS_PER_SAMPLE_16BIT;c.channel_format=I2S_CHANNEL_FMT_RIGHT_LEFT;
c.communication_format=I2S_COMM_FORMAT_STAND_I2S;c.dma_buf_count=4;c.dma_buf_len=128;c.tx_desc_auto_clear=true;
i2s_pin_config_t p={};p.mck_io_num=I2S_PIN_NO_CHANGE;p.bck_io_num=26;p.ws_io_num=25;p.data_out_num=33;p.data_in_num=I2S_PIN_NO_CHANGE;
audio=i2s_driver_install(I2S_NUM_0,&c,0,nullptr)==ESP_OK && i2s_set_pin(I2S_NUM_0,&p)==ESP_OK;
}
void status(const char* msg){lcd.fillRect(0,0,320,62,ST77XX_BLACK);lcd.setCursor(6,5);lcd.setTextColor(ST77XX_WHITE);lcd.setTextSize(2);lcd.println("ESP32 Handheld");lcd.printf(" Score %u | SD %s\n",score,mounted?"OK":"--");lcd.setTextSize(1);lcd.printf(" %s\n A:+ B:reset Start:save Select:load",msg);}
void load(){if(!mounted){status("No SD card");return;}File f=SD.open("/save.txt");if(!f){status("No save yet");return;}long n=f.parseInt();f.close();if(n>=0 && n<=999999){score=n;status("Loaded");}}
void setup(){
Serial.begin(115200);
for(int i=0;i<5;i++)pinMode(keys[i].pin,i<3?INPUT_PULLUP:INPUT);
pinMode(TFT_BL,OUTPUT);digitalWrite(TFT_BL,LOW);
for(int pin:{TFT_CS,SD_CS}){pinMode(pin,OUTPUT);digitalWrite(pin,HIGH);}
SPI.begin(18,19,23,SD_CS);lcd.init(240,320);lcd.setSPISpeed(16000000);lcd.setRotation(1);lcd.fillScreen(ST77XX_BLACK);digitalWrite(TFT_BL,HIGH);
mounted=SD.begin(SD_CS,SPI,4000000);initAudio();
for(int i=0;i<16;i++){cx+=analogRead(34);cy+=analogRead(35);}cx/=16;cy/=16;
status("Move the stick");
if(mounted){File f=SD.open("/level.txt");if(f){int a=f.parseInt(),b=f.parseInt();f.close();if(a>=6 && a<=313 && b>=69 && b<=233){x=a;y=b;}}}
lcd.fillCircle(x,y,5,ST77XX_GREEN);beep(440);
}
void loop(){
static uint32_t last=0;uint32_t now=millis();if(now-last<16)return;last=now;
for(int i=0;i<5;i++){auto &k=keys[i];bool down=!digitalRead(k.pin);
if(down!=k.raw){k.raw=down;k.since=now;}if(k.raw==k.stable || now-k.since<25)continue;k.stable=k.raw;if(!k.stable)continue;
switch(i){case 0:if(score<999999)score++;status("A pressed");break;case 1:score=0;status("B pressed");break;
case 2:if(mounted){File f=SD.open("/save.txt",FILE_WRITE);bool ok=false;if(f){ok=f.println(score)>0;f.close();}status(ok?"Saved":"Save failed");}else status("No SD card");break;
case 3:load();break;case 4:status("Stick clicked");break;}beep(520+i*100);}
int dx=analogRead(34)-cx,dy=analogRead(35)-cy;
int nx=constrain(x+(dx>380?3:dx< -380?-3:0),6,313),ny=constrain(y+(dy>380?3:dy< -380?-3:0),69,233);
if(nx!=x||ny!=y){lcd.fillCircle(x,y,5,ST77XX_BLACK);x=nx;y=ny;lcd.fillCircle(x,y,5,ST77XX_GREEN);}
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




