Close
0%
0%

Electronic Mancala Board

A simplistic, electronic implementation of the ancient board game

Similar projects worth following
364 views
0 followers
I had some leftover PIC18F2420 microcontrollers from my graduate school project and decided to put one to use in this electronic implementation of mancala. I didn't see any prior art concerning electronic mancala projects - and not any that use the same mechanics as this simplistic take on mancala.

As a proof of concept, I set out to use the most basic components as possible to minimize the BOM. I didn't want to have to Charlieplex the LEDs (and refresh them @ 60 Hz), so I bit the bullet and used an I2C LED driver here. This driver has some advantages: individual PWM control for each LED, constant-current drive for all LEDs (no biasing resistors required), and the I2C interface lets me use the PIC18F2420 despite a lack of pins.

The user interface is simple. 16 LEDs indicate the game state, while user input goes through a 4x4 button matrix. The rules of this electronic mancala game are the same as the actual board game.

Self-assembly, PCB fabrication by JLCPCB. 2-layer PCB, lead-free HASL finish. C program for PIC18F2420 compiled with xc8. PICkit 3 used for programming and debugging.

More info:

This project uses a PIC18F2420 clocked at 4 MHz using the internal RC oscillator. I didn't want to have to spend money on an off-chip oscillator and determined that one was unnecessary anyway; I2C plays nicely with uncalibrated clocks thanks to its synchronous nature and nothing happening here is particularly time-sensitive. Timer0 is used here with a 1/256 prescaler to generate a 1.024 ms system tick. This system tick is used for everything time-related in this circuit, from scan rotation, to debouncing, and LED animations.

I used a 4x4 button matrix here for user input. The board layout is wild to accomodate the spacing and placement of the buttons, but it's such a low-speed circuit that I don't really care. It works pretty well: I used some nice tactile buttons with inline 1N4148 diodes to prevent ghosting and wired up 4 scan lines and 4 read lines to the PIC. The routine I wrote to handle user input works pretty well: every ~20 or so ms, the scan line changes (handled by interrupt) and the buttons read changes. I've found that this works very well combined with the debouncing routine I work that does a 5ms block after a button is pressed. To play nice with the interrupt-driven scan rotation, the user must depress the button for input to be registered.

A latched I2C constant-current LED driver is used for this project. Again, I didn't want to have to deal with Charlieplexing or driving the 16 LEDs with individual I/O ports. The PWM on the PIC18F2420 isn't great and I figured that I would rather have something that 1) can latch the current LED state and 2) give me variable brightness w/ PWM on every chip. This component (TLC59116) is very easy to use and works exceeding well - also lets me reduce the number of on-board resistors as biasing resistors are not required for this device (save for a 931 ohm resistor required to set a reference current). A 100 kHz I2C clock is used here. I set up two buttons on the button matrix to increase the duty cycle of the PWM brightness configuration using I2C commands. An LED refresh command is used to send I2C commands to update the LED state every time the game state changes.

Power input is through a microUSB AB jack. The LEDs would have made running this board off a battery very annoying as I'd go through many of them given the draw of these LEDs, so I made it convenient for prototyping/test as we have plenty of microUSB cords laying around.

The game state is probably not handled that efficiently, but I did my best to implement the game rules. So far, I've found no bugs worth noting.

Game implementation and miscellaneous notes:

There are silkscreen errors that I must fix but this is only a prototype/fun project.

LEDs without any "stones" in their pot will be off. LEDs with stones will be illuminated. The number of LEDs in each pot can be determined by pressing the button in front of each LED and counting the number of blinks. Pressing the previously-selected button again will move those rocks - but only if it is on the side of the current player's turn. Pressing a button on the other player's turn will only tell you how many rocks are in those pits.

Global LED brightness can be adjusted by SW15 and SW16 on the PCB.

The reset circuit is activated by pressing SW17. Normally, the RESET pins on both the PIC18F2420 and TLC59116 are pulled to power through a 4.7K ohm resistor. Pushing SW17 will reset both chips and reset the game state.

The game is over when one player clears their side. The player who clears their side gets all outstanding rocks on the table placed in their mancala and the game is then decided by counting the number of stones in each mancala. At the end of the game, the player 1/2 LEDs will blink to indicate the winner. If there is a tie, both LEDs will blink. The reset button...

Read more »

main-12-23-2024.c

PIC18F2420 source file, updated 12/23/2024 (C)

C Source File - 16.79 kB - 12/23/2024 at 19:16

Download

Electronic Mancala Schematic.pdf

New version of schematic that properly annotates the drawing. Changes are formatting only - changes to circuitry.

Adobe Portable Document Format - 488.60 kB - 11/24/2024 at 16:05

Preview

main-10-11-2024.c

PIC18F2420 source file, updated 10/11/2024 (C)

C Source File - 16.55 kB - 10/15/2024 at 20:13

Download

main.c

PIC18F2420 source file (C)

C Source File - 14.68 kB - 10/06/2024 at 21:12

Download

gerbers.zip

Gerber and drill files for PCB design

Zip Archive - 213.50 kB - 09/21/2024 at 18:00

Download

  • 1 × PIC18LF2420-I/SP 8-bit PIC18 microcontroller
  • 16 × 1N4148 DO-35 fast switching diode
  • 16 × OVLFR3C7‎ 5mm red LED
  • 16 × ‎PTS 647 SM38 SMTR2 LFS‎ SPST-NO pushbutton
  • 2 × ‎4605X-101-472LF‎ 5-SIP, 4.7K resistor pack

View all 11 components

  • Update: Bug fix, game rule update, new PCB revision

    Zachary Murtishi12/23/2024 at 19:15 0 comments

    I discovered a bug in the program while playing electronic mancala today. After debugging for a bit, I discovered that the byte storing the data for player 2 was improper and did not contain the right sum at the end of the game. I determined that this was due to an uninitialized local variable in the sum function that tallies up the final score. I set this sum variable to zero and the code now seems to be working as intended.

    The initial program was designed with a game rule that I discovered was just a house rule that I've always played with i.e. captures do not remove your own piece, only capturing the opponent's pieces. The game rules have now been updated to reflect the traditional mancala rules.

    I'm planning to re-spin the PCB to change out the PIC18LF2420 microcontroller with an ATSAMD21 in the future. This new PCB revision will also include a small digital display for better displaying game data. I plan on starting this in the new year.

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates