F20: Tom & Jerry

From Embedded Systems Learning Academy
Revision as of 19:05, 17 December 2020 by Proj user8 (talk | contribs) (ACKNOWLEDGEMENT)

Jump to: navigation, search
Tj1.jpg

INTRODUCTION

The classic Tom and Jerry cartoons has been a part of our lives since a decade now. Surely, you wouldn't have forgotten their chasings and fun moments inside the house. Play this game and relive the 90's era. The game is designed using RGB LED Matrix and microcontroller LPC 4058.

ABSTRACT

The idea is to relive the childhood days using this game with the characters as Tom and Jerry. Jerry will run inside the maze which will be displayed on the RGB matrix. The route for the mouse will be selected from the pre-defined path at initial state in runtime. Tom (player) will chase this mouse by tilting the board left and right. We are using the SoC accelerometer in SJ2 board for sensing the motion. The cat must catch the mouse before mouse reaches its destination hole. If cat get attracted to drink milk (this is an obstacle), then it must halt for some time, and this will waste it’s time for a while at the same place. The mouse will start running first and then after a delay, the cat will start its motion. The score will be displayed on the LCD which is optional display.

OBJECTIVE

The game objectives are as follows:

    • Interfacing the RGB LED Matrix with SJTwo Microcontroller
    • Coding simple to use display functions for displaying characters at any given position
    • Implement code logic to play three levels for the player to win
    • Tasks that can move Tom depending on the user:
    • Interrupt to be generated on press of button to start game/Pause the game and switch between displays
    • Introduce three lives for Tom
    • Have multiple display screens
    • MP3 driver for playing multiple audio depending on game stage

ABOUT THE GAME

Jerry has yet again successfully annoyed Tom. The whole house has turned into a disrupted maze and Jerry has to run for his life before Tom can catch up with him! Help an annoyed Tom to catch Jerry in this classic cat-vs-mouse maze game! Look out for ways through the maze to catch-up with Jerry before he can reach home.

Additional Features :

  • The motive is to catch jerry in the disrupted house before he can reach home.
  • Game has Pause and Play feature implemented.
  • Tom has 3 lives before he can give up.
  • Every win will take tom to next level.
  • At the end of third level the player can win the game
  • Every stage has its own audio which will give the player a nostalgic feeling of the classic cartoon

GAME SCREENSHOTS

TEAM MEMBERS AND RESPONSIBILITIES

  • Sarika Natu
    • Writing code for MP3 Decoder Driver
    • Responsible to write driver to play multiple musics at various game stages
    • Game Architecture
    • Git Repository
  • Shivani Pradeep Tambatkar
    • Wiki Page Updates.
    • Writing code for Accelerometer Driver
    • PCB and Hardware Design
    • PCB Design Verification and component assembly
    • Integrating all the subsystems
    • Maze Design and Graphic designing
    • Game Architecture and Testing
    • Game Packaging
    • Wiki Page Updates.
  • Soumya Sahu
    • Writing initial APIs for RGB Matrix
    • Integrating all the subsystems
    • PCB Design Verification and component assembly
    • Game Architecture and Testing
    • Finance Manager

SCHEDULE

Week# Start Date End Date Task Status
1
  • 09/22/2020
  • 09/29/2020
  • 09/28/2020
  • 09/29/2020
  • Literature Survey of Previous year Projects
  • Submission of Project Proposal
  • Completed
  • Completed
2
  • 10/16/2020
  • 10/20/2020
  • Created GitLab Repository post project proposal approval
  • Create Wiki page for our project
  • Create Wiki Schedule
  • Completed
  • Completed
  • Completed
3
  • 10/20/2020
  • 10/27/2020
  • Read and familiarize with LED Matrix Datasheet
  • Read and familiarize with Accelerometer MMA8452Q datasheet.
  • Completed
  • Completed
4
  • 10/27/2020
  • 11/03/2020
  • Finalize Components and place the order for the required parts
  • Completed
5
  • 11/03/2020
  • 11/10/2020
  • Write multiple lines on LED Matrix successfully (Soumya)
  • Finalize the wiki schedule
  • Modifying code to detect all four directions from accelerometer (Shivani)
  • Reading MP3 datasheet and started writing driver (Sarika)
  • Completed
  • Completed
  • Completed
  • Completed
6
  • 11/10/2020
  • 11/17/2020
  • Drawing basic maze module on LED matrix(Soumya)
  • PCB Layout Design on Eagle (Shivani - 11/27/2020)
  • Read song from MP3 list and execute on hardware (Sarika)
  • Completed
  • Completed
  • Completed
7
  • 11/18/2020
  • 11/24/2020
  • Finalize game logic and game architecture (2/12/2020)
  • Integrate game logic code with LED matrix(Soumya & Shivani)
  • Resolving MP3 bugs (Sarika)
  • Setting up git (Sarika & Soumya)
  • Basic integration for controlling characters on maze (Soumya & Shivani - 11/27/2020)
  • Complete
  • Complete
  • Complete
  • Complete
  • Complete
8
  • 11/25/2020
  • 12/01/2020
  • RGB matrix integration with accelerometer and fixing the bugs (Shivani & Soumya)
  • Designing initial maze frames (Shivani)
  • Integrating MP3 code with master (Sarika)
  • Establish complete connection on PCB and perform Continuity check (Soumya) - 12/5/2020
  • Update the wiki page (Shivani)
  • Complete
  • Complete
  • Complete
  • Complete
9
  • 12/02/2020
  • 12/08/2020
  • Designing multiple Maze based on initial Maze logic (Shivani)
  • Design and developing logic for game animation and display (Shivani)
  • Developing code logic for character movement (Shivani & Soumya)
  • Address bugs during testing maze and character movement (Shivani)
  • Developing game logic to restrict character movement on boundaries (Soumya)
  • Designing and developing game state machine logic to support Led Matrix, background sounds and Accelerometer(Sarika, Soumya, Shivani)
  • Developing logic to play background sounds for corresponding game states (Sarika)
  • Update the wiki page (Shivani)
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
10
  • 12/09/2020
  • 12/14/2020
  • Integration of all subsystems (LED Matrix,Accelerometer and MP3) (Shivani & Soumya)
  • Designing game display at various stages of the game such as initial display, scoreboard and intermediate displays (Shivani)
  • Designing enclosures for matrix and the player's controller
  • Fixing the bugs during final integration testing
  • Code cleanup and updating Gitlab repo with final code.
  • Update test video.
  • Final wiki page update.
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
  • Not started
  • In Progress
11
  • 12/16/2020
  • Final Demo
  • Not started


BILL OF MATERIALS

Part # Cost Source
SJ2 Board 1 $50.00 Preet
Sparkfun RGB (32x64) LED Matrix Display 1 $65.72 Amazon
PCB Fabrication 1 $25.00 JLC PCB
5V/4A Power Adapter 1 $8.99 Amazon
12v DC Power Jack Adapter Connector 1 $3.90 Amazon
Jumper Wires 1 $6.99 Amazon
Total Cost $160.6

GAME DESIGN

The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.

RGB MATRIX

Visuals play huge role in any game design so to achieve this goal we have used 32x64 RGB LED matrix panel. This matrix panel is the heart of the game as no game is complete without graphics. Thorough understanding of the RGB matrix is important to operate the control pins and get the desired output. This section focuses on details related to RGB Matrix and its control ports.

HW Interface

The 32x64 RGB matrix panel is divided into two horizontal sections i.e. 2 16x64 RGB matrix. The upper matrix LEDs are individually accessible, and each LED can display 3 primary colors RED, BLUE, GREEN. The combination of these three primary colors can give access to CYAN, YELLOW,PINK, WHITE colors. The control pins A, B,C, D act as multiplexer of 4:16. Using this concept one can access 1 pixel of upper (R1,G1,B1) and lower matrix (R2,G2,B2) simultaneously. The RGB control pin are shift registers of size equivalent to the width of the RGB matrix panel. In our case, there are 64 columns and therefore, the shift register can store 64-bit data. The bits are fed into this shift register bit-by-bit using the clock pin present in the RGB connection port. The data is shifted for every clock pulse i.e. every time when the clock pulse shifts from logic 0 to logic 1 or vice versa. Once all the bits are present in this shift register, the LAT pin is set to high and the register values are latched to display on the panel. Now, OE pin (active low) is set low to display the combination on the matrix. We will need DATA_IN only if we are using 1 matrix panel.

SPECIFICATIONS:

Pin Number Pin Name Pin Function
1 R1 Upper matrix shift register for red color
2 G1 Upper matrix shift register for green color
3 B1 Upper matrix shift register for blue color
4 R2 Lower matrix shift register for red color
5 G2 Lower matrix shift register for green color
6 B2 Lower matrix shift register for blue color
7 A Row selection mux
8 B Row selection mux
9 C Row selection mux
10 D Row selection mux
10 E This pin is ground
12 Clock Clock in data into the shift registers
13 Latch Latch the values in RGB shift registers
14 Output Enable (OE) Display the shift register values on the RGB matrix panel
15 Ground Ground
16 Ground Ground
  • SW Interface
  • SW Design
  • Jerry Movement
  • Tom Movement
  • Collision Detection

MP3 Decoder

  • HW Interface
MP3 HW.png Schematic.png
  • SW Interface
  • SW Design
  • Flow Chart Logic to Play Multiple Sound

Accelerometer

  • HW Interface
  • SW Interface

Game Logic

  • - Board Design
  • - Game states

IMPLEMENTATION

(Code snippets and explanation)

MP3 Decoder

Psuedo code for reading the music

  1. Each game state has its corresponding mp3 music
  2. Sound flags are checked to find the game state
  3. Find the respective file
  4. Open the mp3 file
  5. Read the contents of the file by protecting it with a mutex
  6. Send the data over queue to the play task
  if ((sound.scorecard) && (current_state != SCORECARD)) {
     result = f_close(&file);
     result = f_findfirst(&dj, &fno, "", "5.mp3");
     result = f_open(&file, fno.fname, FA_OPEN_EXISTING | FA_READ);
     sound.scorecard = false;
     current_state = SCORECARD;
   }
   else if ((sound.catchfail) && (current_state != CATCHFAIL)) {
     result = f_close(&file);
     result = f_findfirst(&dj, &fno, "", "4.mp3");
     result = f_open(&file, fno.fname, FA_OPEN_EXISTING | FA_READ);
     sound.catchfail = false;
     current_state = CATCHFAIL;
   }
   else if ((sound.catchsuccess) && (current_state != CATCHSUCCESS)) {
     result = f_close(&file);
     result = f_findfirst(&dj, &fno, "", "3.mp3");
     result = f_open(&file, fno.fname, FA_OPEN_EXISTING | FA_READ);
     sound.catchsuccess = false;
     current_state = CATCHSUCCESS;
   }
   else if ((sound.game) && (current_state != GAME)) {
     result = f_close(&file);
     result = f_findfirst(&dj, &fno, "", "2.mp3");
     result = f_open(&file, fno.fname, FA_OPEN_EXISTING | FA_READ);
     sound.game = false;
     current_state = GAME;
   }
   else if ((sound.entry) && (current_state != DEFAULT)) {
     result = f_close(&file);
     result = f_findfirst(&dj, &fno, "", "1.mp3");
     result = f_open(&file, fno.fname, FA_OPEN_EXISTING | FA_READ);
     sound.entry = false;
     current_state = DEFAULT;
   }
   xSemaphoreTake(mp3_mutex, portMAX_DELAY);
   result = f_read(&file, &bytes_to_read[0], READ_BYTES_FROM_FILE, &bytes_read);
   }
   xSemaphoreGive(mp3_mutex);
   xQueueSend(mp3_queue, &bytes_to_read[0], portMAX_DELAY);

Psuedo code for playing the music

  1. Mp3 data is received over the queue
  2. Mp3 data is send to the decoder by keeping a counter of 32 bytes and incrementing it for each cycle till complete data is sent.
  3. The shared resource which is mp3 data is protected using the mutex, which is further send to the decoder using SPI
static uint8_t bytes_to_read[READ_BYTES_FROM_FILE];
 static uint8_t current_count = 0;
 uint32_t start_index = 0;
 while (1) {
   if (current_count == 0) {
     xQueueReceive(mp3_queue, &bytes_to_read[0], portMAX_DELAY);
   }
   start_index = (current_count * MAX_BYTES_TX);
   while (!mp3_dreq_get_status()) {
     vTaskDelay(2);
   }
   if (xSemaphoreTake(mp3_mutex, portMAX_DELAY)) {
     send_bytes_to_decoder(start_index, &bytes_to_read[0]);
     xSemaphoreGive(mp3_mutex);
     if (current_count == (READ_BYTES_FROM_FILE / MAX_BYTES_TX) - 1) {
       current_count = 0;
     } else {
       current_count += 1;
     }
   }
 }

RGB Matrix

  • - Jerry Movement
  • - Tom Movement
  • - Collision Detection

Accelerometer

  • - Code snippets and explanation

PCB DESIGN

We have designed and developed a PCB in order to supply power for SJTwo board and RGB LED Matrix which is able to provide 5V supply efficiently. The PCB Layout is designed using the Easy EDA Online Software Tool. The Power Supply circuit board used contains IC7805 voltage regulator IC and a voltage divider to fulfill the specific power requirements. IC7805 is a linear voltage regulator which has a variable output voltage ranging from 4.8 V to 5.2 V and is suitable for our application. We have used a 5V adapter in order to power our board. This serves for both the current requirements.

Fabrication

PCB was sent to fabrication to JLCPCB China which provided PCB with MOQ 2 layers of PCB.

DRC elements (in mils):

  • Track Width = 12
  • Clearance = 10
  • Via Diameter = 24
  • Via Drill Diameter = 12

INTEGRATION AND TESTING

TECHNICAL CHALLENGES

LED Matrix

The OE pin when low, it switches off the LEDs before transition to next row) and LAT (when high) it latches the output pin with current row value). Before transitioning new row value it is important to follow the above instructions, otherwise you will see ghosting effect in the LEDs.

PCB

  • Auto-routing gave lot of challenges and sometimes the wires are barely connected which throws DRC errors very frequently. Even local routing had lot of issues. So design requires careful attention and time.
  • The PCB went through a lot of internal revisions even before placing order which was time-consuming.

CONCLUSION

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

ACKNOWLEDGEMENT

Firstly we would like to express our gratitude to Professor Preetpal Kang for his guidance throughout the semester and providing us with this opportunity. We would also like to thank the TA Vidhushi Jain for being available whenever in need and guiding us to complete the project.

REFERENCES

APPENDIX

Project Video

Project Source Code

Project Presentation