This shows you the differences between two versions of the page.
|
pm:prj2026:bianca.popa1106:cristian.stefan1712 [2026/05/18 16:44] cristian.stefan1712 |
pm:prj2026:bianca.popa1106:cristian.stefan1712 [2026/05/25 07:04] (current) cristian.stefan1712 [Results Obtained] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Project Name: Game Console (Game Boy Replica) ====== | + | ====== Game Console (Game Boy Replica) ====== |
| ===== Introduction ===== | ===== Introduction ===== | ||
| === What it does: === | === What it does: === | ||
| - | This project is a portable video game console featuring a minimalist hardware architecture. It allows users to play 8-bit style games loaded directly from a MicroSD card, which acts as a game cartridge. | + | This project is a portable video game console featuring a minimalist hardware architecture. It allows users to play 8-bit style games loaded directly into the flash memory. |
| === Purpose: === | === Purpose: === | ||
| Line 18: | Line 18: | ||
| The user interacts with the console via an analog XY joystick and 2 standard buttons. The microcontroller reads these inputs (using ADC for the joystick and GPIO for the buttons) and applies software debouncing. | The user interacts with the console via an analog XY joystick and 2 standard buttons. The microcontroller reads these inputs (using ADC for the joystick and GPIO for the buttons) and applies software debouncing. | ||
| - | The core of the system relies on a shared SPI bus. Because the microcontroller has limited RAM, the game logic and graphical assets are stored on the MicroSD card. The system uses a strict Chip Select multiplexing routine to read game data sectors from the SD card, process them, and immediately push the resulting pixel framebuffer to the Nokia 5110 LCD over the same SPI lines. Audio is handled concurrently via a hardware timer generating variable PWM signals sent to a passive piezo buzzer. | + | The core of the system relies on a high-speed SPI bus dedicated solely to driving the display. Because the ATmega328P microcontroller has very limited RAM (2KB), all game state machines, physics algorithms, and graphical assets—such as sprites and custom fonts—are highly optimized using bitmapped hexadecimal integers and stored directly in the microcontroller's internal flash memory. |
| - | ^ Component Name ^ Qty ^ Role ^ | + | During the execution of the main loop, the CPU calculates the game physics and updates a single 504-byte internal pixel framebuffer in the SRAM. Once a frame is fully calculated, the entire buffer is blasted to the Nokia 5110 LCD over the SPI lines through a high-speed bi-directional logic level shifter (TXS0108E), ensuring a seamless, tear-free graphical update. Audio is handled concurrently via a hardware timer, which generates variable PWM signals sent to a passive piezo buzzer without interrupting the game logic. |
| - | | AVR Development Board (ATmega328P) | 1 | Main microcontroller, handles game logic and shared SPI bus | | + | |
| - | | Nokia 5110 LCD Display | 1 | Renders game graphics via SPI | | + | |
| - | | MicroSD Card Adapter Module | 1 | Acts as the cartridge reader for raw game binaries | | + | |
| - | | Logic Level Converter (3.3V to 5V) | 1 | Protects the 3.3V display from 5V logic signals | | + | |
| - | | XY Analog Joystick Module | 1 | Provides directional movement input (D-pad) | | + | |
| - | | 16mm Tactile Push Buttons | 2 | Action inputs (A and B) | | + | |
| - | | Passive Piezo Buzzer Module | 1 | Synthesizes 8-bit sound effects using PWM | | + | |
| - | | Breadboard & Jumper Wires | 1 set | Used for prototyping and physical hardware connections | | + | |
| - | {{:pm:prj2026:bianca.popa1106:schema_bloc_stefan_cristian.png?600|}} | + | ===== Hardware Design ===== |
| - | That is a perfect correction! The Arduino IDE is the absolute classic tool for this, and it actually makes managing libraries a lot easier for a project like this. | + | ^ Component Name ^ Qty ^ Role ^ Datasheet ^ |
| + | | Arduino UNO R3 | 1 | Main microcontroller, handles game logic and SPI bus | [[https://docs.arduino.cc/resources/datasheets/A000066-datasheet.pdf]] | | ||
| + | | Nokia 5110 LCD Display | 1 | Renders game graphics via SPI | [[https://cdn.sparkfun.com/assets/b/1/b/e/f/Nokia5110.pdf]] | | ||
| + | | TXS0108E 8-Ch Logic Level Converter Module | 1 | Protects the 3.3V display from 5V logic signals | [[https://www.ti.com/lit/ds/symlink/txs0108e.pdf]] | | ||
| + | | XY Analog Joystick Module | 1 | Provides directional movement input (D-pad) | | | ||
| + | | 16mm Tactile Push Buttons | 2 | Action inputs (A and B) | | | ||
| + | | Passive Piezo Buzzer Module | 1 | Synthesizes 8-bit sound effects using PWM | | | ||
| + | | Breadboard & Jumper Wires | 1 set | Used for prototyping and physical hardware connections | | | ||
| - | Here is the updated documentation with the Development Environment section completely rewritten to reflect the Arduino IDE, how it handles files (like .ino), and how it manages dependencies. | + | === Simulation + Schematics === |
| - | + | [[https://wokwi.com/projects/464486701286656001]] | |
| - | You can copy and paste this directly into your documentation! | + | {{:pm:prj2026:bianca.popa1106:schema_block_stefan_cristian2.png?600|}} |
| + | {{:pm:prj2026:bianca.popa1106:schematic_cristian_stefan.pdf|}} | ||
| ===== Software Design (Firmware) ===== | ===== Software Design (Firmware) ===== | ||
| Line 48: | Line 48: | ||
| To avoid reinventing the wheel for low-level hardware protocols while maintaining performance, the following libraries (installed via the Arduino Library Manager) are utilized: | To avoid reinventing the wheel for low-level hardware protocols while maintaining performance, the following libraries (installed via the Arduino Library Manager) are utilized: | ||
| - | SPI.h (Standard AVR Library): Used for managing the hardware SPI bus. This is the backbone of the console, handling high-speed communication between the ATmega328P, the MicroSD card, and the Nokia 5110 LCD. | + | SPI.h (Standard AVR Library): Used for managing the hardware SPI bus. This is the backbone of the console, handling high-speed communication between the Arduino and the Nokia 5110 LCD. |
| - | + | ||
| - | SD.h / SdFat.h: Used to interface with the MicroSD card adapter. ''SdFat'' is preferred for its smaller memory footprint and faster read speeds, allowing the console to pull game levels, sprites, and high scores efficiently. | + | |
| - | + | ||
| - | Adafruit_GFX.h & Adafruit_PCD8544.h: These libraries handle the low-level communication with the Nokia 5110 display. They provide primitive drawing functions (pixels, lines, rectangles) and text rendering, which saves significant development time on the graphical engine. | + | |
| ==== Algorithms and Data Structures ==== | ==== Algorithms and Data Structures ==== | ||
| Line 60: | Line 56: | ||
| === 2. The Framebuffer (Graphics Architecture) === | === 2. The Framebuffer (Graphics Architecture) === | ||
| - | Because the Nokia 5110 LCD does not allow reading data back from its screen memory, the console uses an internal Framebuffer. This is a 504-byte array (84x48 pixels) stored in the ATmega328P's SRAM. | + | Because the Nokia 5110 LCD does not allow reading data back from its screen memory, the console uses an internal Framebuffer. This is a 504-byte array (84x48 pixels) stored in the Arduino's SRAM. |
| Algorithm: During a frame, all graphic updates (moving characters, drawing walls, rotating Tetris blocks) are written to this RAM array mathematically using bitwise operations. Once the frame is fully calculated, the entire 504-byte array is blasted over the SPI bus to the screen in one continuous burst. This prevents "screen tearing" and flickering. | Algorithm: During a frame, all graphic updates (moving characters, drawing walls, rotating Tetris blocks) are written to this RAM array mathematically using bitwise operations. Once the frame is fully calculated, the entire 504-byte array is blasted over the SPI bus to the screen in one continuous burst. This prevents "screen tearing" and flickering. | ||
| Line 69: | Line 65: | ||
| Algorithm: Button presses and joystick movements are handled using a non-blocking debouncing algorithm based on the ''millis()'' timer. The system records the timestamp of a physical voltage change on the GPIO pin and ignores further changes for a short window (e.g., ~120ms for Tetris movement) to prevent "phantom double-clicks" or excessively fast piece movement. | Algorithm: Button presses and joystick movements are handled using a non-blocking debouncing algorithm based on the ''millis()'' timer. The system records the timestamp of a physical voltage change on the GPIO pin and ignores further changes for a short window (e.g., ~120ms for Tetris movement) to prevent "phantom double-clicks" or excessively fast piece movement. | ||
| - | === 4. SPI Bus Multiplexing === | + | === 4. Collision Detection === |
| - | Since both the LCD and the SD card share the exact same SCK, MOSI, and MISO wires, an algorithm controls the Chip Select (CS) pins. Before the microcontroller reads a level from the SD card, it forces the LCD's CS pin HIGH (deactivating it) and the SD card's CS pin LOW (activating it). It reverses this process to draw to the screen. | + | |
| - | + | ||
| - | === 5. Collision Detection === | + | |
| For game physics, two distinct algorithms are used depending on the game state: | For game physics, two distinct algorithms are used depending on the game state: | ||
| Line 92: | Line 85: | ||
| | ''void tone()'' | Synthesizes retro audio using the Arduino's built-in hardware timer commands to generate a square wave PWM signal on the buzzer pin at specific frequencies. | | | ''void tone()'' | Synthesizes retro audio using the Arduino's built-in hardware timer commands to generate a square wave PWM signal on the buzzer pin at specific frequencies. | | ||
| | ''void checkTetrisLines()'' | Scans the 10x20 Tetris array for completed rows, shifts the above rows down in memory to simulate gravity, and increments the score multiplier. | | | ''void checkTetrisLines()'' | Scans the 10x20 Tetris array for completed rows, shifts the above rows down in memory to simulate gravity, and increments the score multiplier. | | ||
| + | |||
| + | === Github Repository === | ||
| + | [[https://github.com/itsirc17/Game-Console]] | ||
| + | |||
| + | ===== Results Obtained ===== | ||
| + | Following the hardware and software integration, the final result is a fully functional, stable, retro arcade-style game console. I successfully implemented three distinct games (Snake, Tetris, and Space Invaders) on a single Arduino microcontroller. | ||
| + | |||
| + | The system runs smoothly with no noticeable latency, thanks to strict memory optimizations (using bitmapped hexadecimal arrays to store graphics) and an internal framebuffer architecture. Logic voltages were successfully stabilized using a bi-directional logic level shifter (TXS0108E), which ensured clean and safe 3.3V SPI communication between the development board and the screen. The audio (PWM) and button debouncing logic run perfectly in parallel with the graphics engine, driven entirely by non-blocking, timer-based algorithms rather than ''delay()'' functions. | ||
| + | |||
| + | {{:pm:prj2026:bianca.popa1106:consola1.jpeg?200|}} | ||
| + | {{:pm:prj2026:bianca.popa1106:consola2.jpeg?200|}} | ||
| + | {{:pm:prj2026:bianca.popa1106:consola4.jpeg?200|}} | ||
| + | {{:pm:prj2026:bianca.popa1106:consola3.jpeg?200|}} | ||
| + | |||
| + | ===== Conclusions ===== | ||
| + | Building this project was a massive lesson in bare-metal hardware engineering and practical, real-world debugging. The most critical takeaways from this development process are: | ||
| + | |||
| + | The Reliability of "Clone" Components: I learned firsthand that mass-produced Nokia 5110 LCD modules are incredibly fragile and highly prone to mechanical defects, specifically regarding the elastomeric connector (Zebra Strip). Even brand-new screens straight out of the box required "surgical" manual intervention—disassembling the metal bezel, carefully cleaning the contacts to eliminate parasitic resistance, and mechanically re-crimping the metal frame to ensure firm, even pressure between the glass and the PCB. | ||
| + | |||
| + | Misleading Documentation (Datasheets): A crucial lesson is that online tutorials and schematic diagrams cannot always be taken as absolute truth, as underlying hardware revisions frequently change. For example, most standard documentation indicated that the backlight pin (LED/BL) should be connected to VCC (3.3V) through a resistor. In reality, because my specific module utilized a different internal transistor for backlight control, the pin had to be tied to GND for the LEDs to function correctly. | ||
| + | |||
| + | The Satisfaction of the Build: Despite the hours spent diagnosing floating pins, SPI initialization timing, and faulty LCD contrast, the final result was entirely worth the effort. The satisfaction of holding a physical console, pressing the mechanical buttons, and playing games programmed entirely from scratch is immense. This project bridged the gap between simply "writing code" and deeply understanding how software physically manipulates hardware. | ||
| + | |||
| + | |||