#500 RFID Concentration Game
Play a game of Concentration/Pairs with a stack of MIFARE Classic cards.
Here’s a quick demo..
You may have played Concentration - the simple card game where the objective is to pickup as many matching pairs of cards as possible.
I have a stack of RFID cards that I got with a reader, so attempting a version of Concentration was the first and most obvious thing that popped into my head!
I decided to keep the interaction as simple as possible, and in particular avoid the need for a text display unit, so I designed the game-play around:
- an 8x8 matrix to display the card identity and flash various effects
- a buzzer and LEDs for feedback
- and the cards themselves for all input
|gameRunning||off||off||off||Fast Flash||in game mode, waiting for a card..|
|initializing||off||Flashing||Flashing||Flashing||in card initialisation mode|
|CardInitialized||Beep||off||ON||Flashing||card initialized, ready for a new one|
|CardInitializeFail||Beep||ON||off||Flash ON||card initialize failed|
|cardAccepted||Beep||off||Flashing||off||first card accepted, present another..|
|cardMatch||Happy Beep||off||ON||off||second card match. Win!|
|cardMismatch||Sad beep||Flash ON||off||off||second card mis-match. Fail!|
The Doxygen documentation for the code is available here.
Additional libraries used in the Arduino code:
- MFRC522 RFID Library - for reading/writing the cards
- FlexiTimer2 - for async triggering
- LedControl - LED matrix control
The RFID cards need to be initialized before they can be used.
- if a recognised card is scanned, we assume you’re starting a game using the card set retrieved from EEPROM.
- if an unrecognised card is scanned, we assume you’re setting up a new stack of cards:
- the card set is initialised
- the card is added to a new card set in memory (grouped into pairs), and the card ID is written back to the card
- positive feedback (a “good” beep and green LED)
- keeps initialising any other cards that are presented until max card limit reached, or an already-initialised card is presented (which triggers game mode)
- after first card is presented, provides a neutral beep and red/green LEDs flash
- when a second card is presented:
- if it matches, plays a happy tune and green LED is on
- if it does not match, plays a sad tune and red LED is on
- game is over when all pairs have been successfully matched
- it won’t bother to warn on repeated presentations of the same pairs - assume players are policing the rules themselves!
- there’s no score-keeping, that’s up to players, as it doesn’t know who or how many players are in the game
For simplicity, uses value blocks for a game ID and card ID.
Data is stored in sector 1. That is, block 4 to block 7:
- block 4: the game ID value block
- block 5: the card ID value block
- block 6: unused
- block 7: sector trailer
Each card is given a sequential number starting from 1. Pairs are the adjacent cards i.e. 1+2, 3+4 etc. That’s not random, as it assumes the players will use the age old technique of shuffling the cards before starting the game.
Circuit Design and Breadboard Prototype
Power: the MFRC522 is 3.3V device, and officially tolerant up to around 4V. So, running it with the 5V Uno is not strictly legit. Power is supplied correctly at 3.3V, but data lines will stray up to 5V. I haven’t included level shifters. But it does seem to work, as many have proven before, though I wouldn’t do it this way for anything requiring long term reliability.
Some decisions for the final build:
- I replaced the 3 LEDs with the LEAP#269 Boldport Cordwood for the final build (because it’s purdy).
- stuck with an Arduino Uno as the base board (as it has the 3.3V and 5V supply already taken care of)
- still left out the level shifters for the MFRC522 data lines. So far, so good (fingers crossed)
The Boldport Cordwood gets some copper wiring so it can stand proud:
Wiring and testing the modules before mounting:
I used some balsa wood with a clear varnish for the custom case. Mounting the modules:
The final build in action: