Digital Connect 4 - V1

By Jamal Bouajjaj

Introduction:

This project is a Connect 4 game designed in a circuit board. There is a 7x6 LED matrix for the "board" of the game. Each column has a button right on top of it, simulating dropping a disk in a column. There is another LED and 2 buttons for other purposes, such as restarting the game and indicating who's turn is it.

Warnings/Issues:

Project's folder:

Click the GitHub folder below to access the project's files, which include the KiCad PCB files, the Gerber files, and the Autodesk Inventor CAD files.

GitHub Repository Link

Pictures:

Image 1 Image 2 Image 3

PCB Parts:

Here are the parts you will need to solder this project

SW1 and R1 are completely optional, as they are used for the in-board reset button for the ST microcontroller

PCB Reference Part Description/ValuesPackage Size Quantity per Board
C1Decoupling Cap (0.1 -> 10uF)08051
D1-D435mm RGB LED5mm43
J1Programming Header5-pin 0.1" male header1
J2USB MicroMolex 473461
J3Power2-pin 0.1" header or Wire1
R11kΩ Resistor08051
R2-R25Resistors | 100Ω for Red, 56Ω for Green and Blue080524
SW1Minature Tactile SwitchPTS8101
SW2-SW10Tactile Switches4-pin 6mm tactile switch9
U1AMS1117-3.3 Voltage RegulatorSOT-223-31
U2ULN2003 Darlington ArraySOP-161
U3STM32F103RCTxLQFP-641

Theory of Operation:

The circuit is based on an STM32F103 microcontroller. The microcontroller directly drives all LED individually by supplying power to their anodes. There is a Darlington array IC (ULN2003) which pull all LED's cathodes in a row to GND. The ULN2003 is also controlled by the microcontroller. This setup results in the game's LED matrix capable of being multiplexed to display any combination on the matrix while reducing power consumption. Other than that, there is a USB input connector, an optional reset switch for the microcontroller, a programming header, and a 3.3V regulator.
The complexity of the project mainly arises in the software. The software is programmed in the AC6 Workbench for STM32 environment. When the board is initialized, the STM32 starts by initializing the GPIO peripherals to set each pin to an input or output depending on what that pin is hooked up to. Then, Timer 7 is initialized to trigger every 1ms. When triggered, the timer will interrupt the program to a function titled "TIM6_IRQHandler", which drives the matrix's LEDs depending on the value of a global LED array which stores which colors on each LED of the matrix that will be lit-up. The LEDs are multiplexed, so the function cycles thru all rows one at a time. There is another array, called "players", that stores the "chips" on the board and who "placed" each one. There is functional called "playerToLed" that converts the information in this array to the global LED array to be displayed. This function is called upon during the game's loop when it wants to update the display. During the main game loop, when Timer 7 has not interrupted the program, the loop waits for one of the buttons to be pressed. When pressed, if the button is the left-most button at the top of the PCB, the game will reset itself. If the button pressed is one of the columns, it will find the row that isn't occupied by another "chip". Once found, it stores the player's ID (1 or 2) into the mentioned "players" array. The game then checks if there is a winner by the "checkForWinner" function, which checks the "players" array for 4 "chips" dropped by the same player 4 times in a row diagonally, horizontally, and vertically. If there is a winner, the game will stop and indicate which one. If both cases where there is a player or the game was manually reset, the right-most button on the top of the PCB(right below the indicator LED) can be pressed to restart the game loop.

Schematic:

Here is the PCB's schematic:

Schematic of Project

Technical Diagrams:

Comming Soon!

Case:

The PCB has 4 M3 mounting holes to be screwed on to a case. I have designed a case for this board in Fusion360. The STEP and STL files will be released soon in the page's GitHub repository.

Programming:

The PCB is designed to be programed by using the pin headers at the top of the board (J1). The pinout for the connector can be found in the schematic. You could use any STM32 programmer, including the popular ST-Link 2, to program the board.

The programming software used (AC6 for STM32 Workbench) can be found here!