Skip to main content

RUST TICTACTOE (+Wireless Control)

info

Author: Petrec Matei-Teodor
GitHub Project Link: https://github.com/UPB-FILS-MA/project-Petrecm

Description

This project presents the classic game of Tic-Tac-Toe by embedding it into an interactive hardware platform using a Raspberry Pi Pico. The game is displayed on a physical 3x3 matrix on an LCD screen, where players use an analog joystick either their Phone connected to wifi to navigate and confirm their moves. The objective of Tic-Tac-Toe is simple: each of the two players takes turns to mark the spaces in a 3×3 grid with their own symbols (X&O). The winner is the first player to achieve a row, column, or diagonal of three consecutive marks.

Motivation

I chose to work on the Tic-Tac-Toe project because it perfectly combines my love for classic games with my growing interest in technology and programming. The project, powered by the Raspberry Pi Pico, allows me to explore the complexity of electronic components and software design in a hands-on manner. I’m particularly excited about the challenge of integrating a joystick, wifi module of the pico W and a display, which adds a physical interaction element to the digital game. This test is not just about recreating a game I enjoy and I thought about because I like Ancient Egypt, it's about pushing my abilities in software and hardware design to new limits and crafting an enjoyable experience that enhances my rust skills and provides a tangible, fun product to bring people together.

Architecture

Architecture photo

The diagram shows the setup of the Interactive Tic-Tac-Toe Game System, built with the Raspberry Pi Pico W. This is a list with all the components and their functionality presented in the representation:

  1. Raspberry Pi Pico W: The central controller for the Tic-Tac-Toe game. | Manages input and output operations and processes game logic. It initializes the game by setting up the LCD display and configuring initial states for LEDs and the joystick/phone control.

  2. Joystick: Serves as the primary input device for the player. | Connected directly to the Raspberry Pi Pico W, allowing the user to navigate the game interface. | Has the functionality when pressed to confirm selected move on the screen.

  3. Phone (via CYW43439): Connects to the Raspberry Pi Pico W through the CYW43439 WiFi chip. The inclusion of the CYW43439 allows the game to have connectivity feature to transmit game input control from phone (←↑↓→)

  4. 240x240 IPS LCD: Displays the game state and user interface. | Connected to the Raspberry Pi Pico W via SPI (Serial Peripheral Interface), facilitating fast data transfer for real-time display updates. |

  5. Buzzer: Provides auditory feedback for game events, such as invalid moves or game conclusions. | Triggered by specific game conditions programmed into the Raspberry Pi Pico W.

  6. LEDs: Indicate various game states and functions, such as player turns or game outcomes. | Controlled directly by the Raspberry Pi Pico W to reflect real-time game changes.

Log

Week 6 - 12 May

  • I ordered all components for the hardware prototype, I needed a joystick and a couple of resistors.
  • Started the Kicad Schematic, did some research on the joystick voltage use, since it was using a pin for 5V, I had to come up with an idea to power it separately from the rest of the componenets which were using 3.3V.

Week 7 - 19 May

  • I managed to make the hardware part more cleaner, rearranging the components on the breadboard and pico explorer and simplify the wiring of the connections.
  • I began to code the software for the tictactoe game, work still in progress but making small achievements along the way testing each component individually to see if it works.
  • I solved the issue with the power supply of the joystick by connecting a battery trough a mini power supply (HW-131) such that I can power up it up at 5V, also added some voltage dividers for the VRX, VRY, SW pins of the joystick to connect to the pico explorer base at the overall voltage of the circuit (3.3V).

Week 20 - 26 May

  • I finished the code in fully and tested it intensively.
  • I made the hardware part more cleaner for a better view of the components and their connections.

Hardware

Raspberry Pi Pico W: Manages all game operations and processes inputs and outputs. Joystick: User input device for navigating and selecting positions on the game grid. LCD IPS Module Screen: Displays the game grid and player moves. Buzzer: Emits sound signals for alerts and notifications during gameplay. LEDs: Indicate game status, player turns, and outcomes. Breadboard: Platform for assembling and connecting electronic components. Wires: Conduct electrical connections between components (Female-to-Male, Female-to-Female, and Male-to-Male). Resistors: Control and limit the flow of electrical current to other components, protecting them from damage (10KΩ joystick / 220Ω LEDs). Micro USB Cable: Connects the Raspberry Pi Pico W to a power supply.

Schematic

Schematic

Schematic

Schematics

Schematic

Bill of Materials

DeviceUsagePrice
Rapspberry Pi Pico WThe microcontroller with Wi-Fi connectivity35 RON
LCD ModuleDisplay71.59 RON
[Joystick] (https://www.atrinelec.com/download/datasheet/joystick_module(Atrinelec.com).pdf)Bi-axial module for movement and confirming action5,35 RON
LEDs (different colors)Using different color LEDs we state player row and game winner0.5 RON per LED
BuzzerGoes off when a wrong movement is detected and when game is finished4 RON
Female-to-Female WiresFor connections3 lei per pack
Male-to-Male WiresFor connections9 lei for 3 packs
Female-to-Male WiresFor connections5 lei per pack
BreadboardTo assembly and connect different components on it10 RON
Micro USB CableTo power the Raspberry Pi Pico W3 lei
10KΩ ResistorsFor the Joystick0.5 lei for 2
220Ω ResistorsFor the LEDs1 lei for 3

Software

LibraryDescriptionUsage
st7789Display driver for ST7789Used for the display for the Pico Explorer Base
embedded-graphics2D graphics libraryUsed for drawing to the display
embassy_executorProvides an executor for running asynchronous tasks concurrentlyExecute asynchronous tasks concurrently
pwmPulse-width modulationUsed for controlling the buzzer's sound intensity
embassy-timeTime management libraryUsed for time-based operations such as delays
embassy-rpPeripheral access libraryUsed for initializing and interacting with peripherals
gpioFor general-purpose input/output pin manipulationThis is fundamental for interfacing with buttons, LEDs, and potentially the joystick.
  1. Youtube
  2. Youtube
  3. Youtube
  4. OCW.CS.PUB.RO
  5. [Github] (https://github.com/cristiancristea00/tic-tac-toe)