Difference between revisions of "F19: Smacman"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Issues, Challenges and solutions to get past them)
(Parts List & Cost)
Line 208: Line 208:
 
|}
 
|}
  
== Parts List & Cost ==
+
== Pin Configuration ==
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| Item#
+
! scope="col"| PIN#
! scope="col"| Part Desciption
+
! scope="col"| Pin Desciption
! scope="col"| Vendor
+
! scope="col"| uC PIN
! scope="col"| Qty
 
! scope="col"| Cost
 
 
|-
 
|-
! scope="row"| 1
+
! scope="row"| R1
| SJTwo Boards
+
| PIN for Red terminal of RGB LED for upper half of LED Matrix
| Purchased from Preet
+
| P2_0
| 4
 
| $200.00
 
 
|-
 
|-
! scope="row"| 2
+
! scope="row"| G1
| 64x64 RGB LED Matrix
+
| PIN for Green terminal of RGB LED for upper half of LED Matrix
| [https://www.sparkfun.com/products/14824 Sparkfun]
+
| P2_1
| 1
 
| $75.00
 
 
|-
 
|-
! scope="row"| 3
+
! scope="row"| B1
| Wiring Components and  Cable
+
| PIN for Blue terminal of RGB LED for upper half of LED Matrix
| [https://www.amazon.com/XBee-USB-Adapter-Communication-Connectivity/dp/B017KGBP6Y Waveshare]
+
| P2_2
| 1
 
| $20.00
 
 
|-
 
|-
! scope="row"| 4
+
! scope="row"| R2
| 3D printer filament spool(s)
+
| PIN for Red terminal of RGB LED for lower half of LED Matrix
| [https://www.hatchbox3d.com/ HATCHBOX]
+
| P2_4
| 2
 
| $40.00
 
 
|-
 
|-
! scope="row"| 5
+
! scope="row"| G2
| XBEE Modules
+
| PIN for Green terminal of RGB LED for lower half of LED Matrix
| From Preet and [https://www.adafruit.com/product/128 Adafruit]
+
| P2_5
| 3
 
| $27.00
 
 
|-
 
|-
! scope="row"| 6
+
! scope="row"| B2
| Batteries
+
| PIN for Blue terminal of RGB LED for lower half of LED Matrix
| Local
+
| P2_6
| 2
 
| $4.00
 
 
|-
 
|-
! scope="row"| 7
+
! scope="row"| A
| I2C 7-seg screens
+
|  Mux pin for row selection
| [https://www.adafruit.com/product/879 Adafruit]
+
| P2_7
| 2
+
|-
| $18.00
+
! scope="row"| B
 +
|  Mux pin for row selection
 +
| P2_8
 +
|-
 +
! scope="row"| C
 +
|  Mux pin for row selection
 +
| P2_9
 +
|-
 +
! scope="row"| D
 +
|  Mux pin for row selection
 +
| P0_16
 +
|-
 +
! scope="row"| E
 +
|  Mux pin for row selection
 +
| P0_15
 +
|-
 +
! scope="row"| OE
 +
|  Output Enable
 +
| P1_20
 +
|-
 +
! scope="row"| LATCH
 +
|  Latching Data
 +
| P1_23
 +
|-
 +
! scope="row"| CLK
 +
|  CLock signal to understand one bit has been detected
 +
| P1_28
 +
|-
 +
 
 +
! scope="row"| VCC
 +
| VCC Supply
 +
| VCC
 +
|-
 +
! scope="row"| GND
 +
| Ground
 +
| GND
 +
|-
 +
! scope="row"| TX_3
 +
|  UART Transmit for XBEE
 +
| P4_28
 +
|-
 +
! scope="row"| RX_3
 +
|  UART Receive for XBEE
 +
| P4_29
 +
|-
 +
! scope="row"| SCK_2
 +
|  CLOCK for SPI bus for MP3 Decoder
 +
| P1_0
 +
|-
 +
! scope="row"| MOSI_2
 +
|  MOSI for SPI bus for MP3 Decoder
 +
| P1_1
 +
|-
 +
! scope="row"| MISO_2
 +
|  MISO for SPI bus for MP3 Decoder
 +
| P1_4
 +
|-
 +
! scope="row"| SDA_2
 +
|  I2C Data line for 7 Segment
 +
| P0_10
 +
|-
 +
! scope="row"| SCL_2
 +
I2C Clock line for 7 Segment
 +
| P0_11
 +
|-
 +
! scope="row"| Switch
 +
| Switch GPIO
 +
| P0_1
 
|-
 
|-
! scope="row"| 8
 
| XBee Programmer Boards
 
|  [https://www.amazon.com/XBee-USB-Adapter-Communication-Connectivity/dp/B017KGBP6Y Waveshare]
 
| 3
 
| $35.00
 
 
|}
 
|}
  

Revision as of 19:57, 18 December 2019

Grading Criteria

  • How well is Software & Hardware Design described?
  • How well can this report be used to reproduce this project?
  • Code Quality
  • Overall Report Quality:
    • Software Block Diagrams
    • Hardware Block Diagrams
      Schematic Quality
    • Quality of technical challenges and solutions adopted.

SMACMAN

Smacman

Abstract

Our team has created a unique 2 player game involving a central screen of 64x64 LED matrix and two auxiliary controllers. The two opponents will face one another and will have a paddle on their side. A ball will travel between players which they have to deflect away. Additionally, each player will have a “monster” that will continuously move towards the ball and try to eat the ball. If a monster eats the ball, that opponent of the owner of the monster will lose. Therefore, it is beneficial for a player to try to place the ball closer to their monster and further away from the opponent’s monster in order to score. Additionally, if the ball contacts the side of the screen behind the player’s paddle, they will also lose. As the game progresses, the speed of the ball will increase and eventually, there will be variation in the movement of monster. The controllers(xBee--XB24-AWI) will be wireless and communicate with the master board which runs the game and drives the 64x64 LED matrix.The MP3 module(VS 1053) reads music files from an SD card and plays the music through a speaker interfaced with the board in the background.

Objectives

The main objective of the project is to develop a 2D two player Smacman game. Other milestones to achieve are as below:

  • Change the direction and speed of the monster differently at different levels, depending on the direction of the ball on LED Matrix in real time.
  • The controller which does wireless transfer of accelerometer values is used to control the movement of the ball
  • Play music in the background and game sounds using MP3 Decoder.
  • Design PCB for Master and the Controller which will interface all the peripheral devices to the SJ-two boards.

Introduction

The project is broadly divided into three nodes:

1. Master Node: The master node (one SJ2 board) receives the data from the controller nodes via XBee module which is used to control the paddle movement which will eventually control the game. It recursively polls to receive control packets from the controller nodes and updates the paddle movements as per user's input. The master node also controls visual display on the LED Matrix and the game logic.

2. Controller Node: The controller node (two SJ2 boards) consist of the XBee modules which transmits control packets to the master node using fault-tolerant broadcast wireless UART protocol.

3. Music Node: The music node (one SJ2 board) provides background music to the game which enhances the experience of the game.

About the game

  • Both Players should try to hit the ball with the paddle placed on their side.
  • Press switch on the controller SJ-Two board to start the game.
  • Tilt the controller left or right to move the paddle.
  • Hit the ball with your paddle before the monster eats it to get a score.
  • To manipulate the speed and the direction of the ball move the paddle in the same or in the opposite direction of the ball.
  • Avoid the monster of opposite player to eat the ball in your side, if this happens then the game is over, else the ball continues to move between the paddles.
  • The speed of the monster increases when the ball will move in opposite direction to catch the ball.
  • Level 1 has the monster of opposite player moving at your side along the edges. If any player exceeds a score of 33 then me move to Level 2.
  • Level 2 has the monster of opposite player moving along x-axis at your side. If any player exceeds a score of 66 then me move to Level 3.
  • Level 3 has the monster of opposite player moving along x-axis and y-axis at your side. If any player reaches a score of 100 then that player wins the game.
  • Both the Players can play and pause the game anytime and resume from where the game was paused.

Team Members & Responsibilities

  • Nick Schiffer
    • XBEE, Controller Functionality, Communication Architecture, Game Logic Development, Enclosures, PCB Designing.
  • Mohit Ingale
    • LED Driver, Game Logic Development, Enclosures, PCB Designing.
  • Ayesha Siddiqua
    • Graphic Driver, Game Logic Development.
  • Shreya Patankar
    • Splash Screen Graphics Driver, Game Logic Development, MP3 Decoder, Wikimedia Update.

Delivery Schedule

Project Repository Link: Github Project

Week# Date Task Status Actual Completion Date
1 10/1/2019
  • Submission of Project Proposal.
  • Complete
  • 10/1/2019
2 10/15/2019
  • Create GitLab Repository.
  • Go through the projects and research about components.
  • Distributing the roles among team members.
  • Research Required Components.
  • Submit Schedule and Components List.
  • Complete
  • 10/14/2019
3 10/22/2019
  • Familiarize with 64x64 LED Matrix Datasheet.
  • Familiarize with xbee & accelerometer datasheet.
  • Familiarize with Mp3 Decoder VS-1053 datasheet.
  • Complete
  • 11/8/2019
4 10/29/2019
  • Make Gitlab Repository for individual tasks for all modules
  • Introduce Naming Convention
  • Develop Graphics Drivers and Implementation of displaying basic monster on LED Matrix
  • Calibrating Accelerometer values for 2 Players
  • Complete
  • 11/8/2019
5 11/5/2019
  • Develop code to send Accelerometer values to move the paddle for both the players
  • Basic LED Display testing for boundary conditions.
  • Develop game specific APIs to draw objects like monster, paddle, ball of led driver
  • Project report update on the wiki.
  • Complete
  • 11/12/2019
6 11/12/2019
  • Develop Algorithm Design for Game Logic for all 3 levels of game
  • Transmission of Accelerometer values for 2 players from their respective controllers to the master
  • Code for the splash screen(Intro screen)
  • Complete
  • 11/19/2019
7 11/19/2019
  • Code for MP3 Decoder for the background music
  • 7 segment display for players score from controller
  • Code to display the score on matrix
  • Code Integration for the moving of paddle on basis of accelerometer values from controllers for both the players
  • Complete
  • 11/26/2019
8 11/26/2019
  • Develop Play/Pause/Stop functionality
  • Debug and Test the Play/Pause/Stop functionality
  • Complete
  • 11/30/2019
9 12/3/2019
  • Design PCB for Controller & master and generate Gerber files, finalize PCB manufacture
  • Integrating calibrated accelerometer, push-button functionalities and wireless transfer from controller boards
  • Complete
  • 12/10/2019
10 12/10/2019
  • Integration of subsystems
  • 3-D Printing of enclosures for matrix and the player's controller
  • Fixing the bugs during testing
  • Complete
  • 12/15/2019
11 12/17/2019
  • Final bug fixes and troubleshooting.
  • Complete wiki report and final demo.
  • In-Progress
  • 12/17/2019

Pin Configuration

PIN# Pin Desciption uC PIN
R1 PIN for Red terminal of RGB LED for upper half of LED Matrix P2_0
G1 PIN for Green terminal of RGB LED for upper half of LED Matrix P2_1
B1 PIN for Blue terminal of RGB LED for upper half of LED Matrix P2_2
R2 PIN for Red terminal of RGB LED for lower half of LED Matrix P2_4
G2 PIN for Green terminal of RGB LED for lower half of LED Matrix P2_5
B2 PIN for Blue terminal of RGB LED for lower half of LED Matrix P2_6
A Mux pin for row selection P2_7
B Mux pin for row selection P2_8
C Mux pin for row selection P2_9
D Mux pin for row selection P0_16
E Mux pin for row selection P0_15
OE Output Enable P1_20
LATCH Latching Data P1_23
CLK CLock signal to understand one bit has been detected P1_28
VCC VCC Supply VCC
GND Ground GND
TX_3 UART Transmit for XBEE P4_28
RX_3 UART Receive for XBEE P4_29
SCK_2 CLOCK for SPI bus for MP3 Decoder P1_0
MOSI_2 MOSI for SPI bus for MP3 Decoder P1_1
MISO_2 MISO for SPI bus for MP3 Decoder P1_4
SDA_2 I2C Data line for 7 Segment P0_10
SCL_2 I2C Clock line for 7 Segment P0_11
Switch Switch GPIO P0_1

Design & Implementation

Hardware and PCB Design

Pin Configuration

PIN# Pin Desciption uC PIN
R1 PIN for Red terminal of RGB LED for upper half of LED Matrix P2_0
G1 PIN for Green terminal of RGB LED for upper half of LED Matrix P2_1
B1 PIN for Blue terminal of RGB LED for upper half of LED Matrix P2_2
R2 PIN for Red terminal of RGB LED for lower half of LED Matrix P2_4
G2 PIN for Green terminal of RGB LED for lower half of LED Matrix P2_5
B2 PIN for Blue terminal of RGB LED for lower half of LED Matrix P2_6
A Mux pin for row selection P2_7
B Mux pin for row selection P2_8
C Mux pin for row selection P2_9
D Mux pin for row selection P0_16
E Mux pin for row selection P0_15
OE Output Enable P1_20
LATCH Latching Data P1_23
CLK CLock signal to understand one bit has been detected P1_28

Game Casing

Smacman is a two Player game. It is quiet inconvinient to play the game with all the wires and components lying around. So to facilitate this we 3D printed a basic enclosure for the two players controller as well as the Led matrix, which is big enough to accommodate zigbee module, MP3 Decoder and speakers, Master Board. We needed to put together all components in a single enclosure. The enclosure includes the spacing for SJTWO board with PCB mounted on top and the MP3 Decoder along with speakers.

Case Design
Casing
Circuit Along with all the components
Entire Game Casing

Testing & Technical Challenges

Issues, Challenges and solutions to get past them

1. RGB LED Matrix Display driver

a) Setting up the LED Matrix was a bit of a challenge. Started with glowing a single row and column. Getting the initial hold on the exact row and column position was a bit tricky as one can easily get confuse on the starting and ending row and column. Once we got over it we moved on to design game objects separately.

b) Flickering of led matrix was solved by doing the following:

  • The frequency of refreshing the led matrix was increased to show smooth transition from one frame to another.
  • Led matrix is very sensitive to the inputs provided to it. Initially the flickering was thought to be because of the data lines and row selection lines. But later with further diagnoses it was discovered that the power supply line was creating issues. Changing the adapter eliminated the flickering.

c) As the game consists of many objects that exist simultaneously on the screen clearing the trail of each object was bit of a problem.

  • Initially clearing the LED matrix from time to time assigned to one task. But later each object dealt with its own clearance, which eliminated the effect of clearance of one object with the display of other objects.

d) Pacman and Ball detection of the bounadry:

  • Pacman object detecting the boundary and making the decision of moving left or right was a bit tricky. Started with one boundary condition and then proceeded with the rest boundary conditions.

e) Updating the movement of each object on the LED matrix was clumsy in the beginning as individual objects where updated as soon as a movement was detected in the object.

  • But when the frequency of refreshing rate was increased the update of the LED matrix was moved to one task which led to the smooth movement of the objects on the screen.

e) The varying Pacman velocity with the ball movement in the lower and the upper half of the matrix was difficult.

  • Set and get functions are used to get the updated position of the ball for each movement.
Game Frame
Score


2. Challenges in the designing of the controller modules for the paddle movement and to get score from the master

a) SJ2 UART frames were corrupted while sending over XBEE.

  • The XBEE firmware parameters had to be carefully calibrated to match the SJ2 as well as using a 38400 bps bit rate. The SJ2 UART driver had to be slightly modified match as well.

b) UART is not meant to be a broadcast protocol.

  • A custom wireless broadcast/multi-node wireless protocol and driver had to be designed to be robust with dropped frames and packets being handled gracefully. (Described above)

3. Designing the MP3 Decoder

a) Earlier we used the ssp2 Driver written by Preet for SPI interfacing to write the data to MP3 Decoder. but somehow we were not able to detect the slave properly because of which we could not communicate with the decoder.

  • Resolution : We wrote our own simple SPI driver which sends the data to the MP3 Decoder for playing the music in background.

b) While reading data from the SD Card sometimes we faced few issues like hardware error occured in disk i/o and physical drive cannot work.

  • Resolution : The default driver was using mount later option for SD Card we changed it to mount immediately and the issue got resolved.

4. Dimensions of power pins for the PCB design

a) Accommodate the exact dimensions of the 5V Power pin on the PCB design.

  • Since there is no datasheet available for the 64x64 RGB LED Matrix, hence it was a difficult task. We used a basic approximation to determine the pin dimensions that would fit inside the PCB design such that it works just fine.


4. Integration Issues a) Controller Logic and Game Logic were developed independently.

  • Careful time and consideration had to be taken to ensure that the APIs were able to be stitched together. This actually ended up going smoother than we had anticipated. The Inter-board communication driver was designed to handle almost everything regarding the controllers, providing very abstract and simple APIs. This allowed for relatively smooth integration.

b) After game and controller logic, the main SJ2 did not have enough processing power to adequately driver the music functionality.

  • A standalone SJ2 board was used for the game soundtrack. This eased the load on our main board which was starting to effect our gameplay.

Conclusion

At the start, the concepts that we aimed to implement were not trivial but if accomplished, would lead to an awesome project. We realized early on that each one of us had particular strengths and that it would be critical for us to leverage these effectively. We effectively parallelized our tasks and made sure to regularly synchronize to avoid accruing too much technical debt. In the end, we were able to accomplish more features than we had initially devised. This project has helped us to gain more practical exposure to building a real time embedded systems and decompose and solve new problems that don't come from a textbook. We are thankful to Preet, who motivated and guided us through out the course work. This is surely going to help us for our interview preparation and in grabbing an internship.

Project Video

Project Testing Video

Project Video Link

Project Source Code

Acknowledgement

We would like to thank our Professor Preetpal Kang for all his awesome lectures and explanations of the embedded system topics, they could not have been explained any better than this! Not only did we enjoy working on this project but it also gave us an overall learning experience and precious life lessons. The extra knowledge in Preet's Class is surely going to help us to prepare for our interview preparations. We would also like to thank the ISA members for always being around and ready for helping whenever required.

References

WIRELESS CONTROLLER
MP3 DECODER
RGB LED Matrix Interfacing and Designing
General/Miscellaneous