Difference between revisions of "F22: Embedded Gamers"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Bill of Materials (General Parts))
(Game Logic)
 
(67 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Grading Criteria ===
+
== '''Guardians of the Galaxy''' ==
<font color="green">
+
<center>
*  How well is Software & Hardware Design described?
+
<table>
*  How well can this report be used to reproduce this project?
+
<tr>
*  Code Quality
+
<td>
*  Overall Report Quality:
+
[[File:F22-EG-Begin-Screen.png|500px|thumb|left|Start Screen]]
**  Software Block Diagrams
+
</td>
**  Hardware Block Diagrams
+
<td>
**: Schematic Quality
+
</td>
**  Quality of technical challenges and solutions adopted.
+
<td>
</font>
+
[[File:F22-EG-Game-Play.png|500px|thumb|center|Game Play]]
 
+
</td>
== '''Project Title''' ==
+
<td>
Guardians of the Galaxy
+
</td>
 +
<td>
 +
[[File:F22-EG-End-Screen.png|500px|thumb|right|End Screen]]
 +
</td>
 +
</tr>
 +
</table>
 +
</center>
  
 
== '''Abstract''' ==
 
== '''Abstract''' ==
Line 24: Line 30:
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
! colspan="5"| Administrative Roles   
+
! colspan="5"| Technical Roles   
 
|-
 
|-
 
! style="text-align: left;" |   
 
! style="text-align: left;" |   
Line 36: Line 42:
 
! style="text-align: left;" |  
 
! style="text-align: left;" |  
 
* Joystick Controller Driver
 
* Joystick Controller Driver
| Ritu Patil
+
| Bruce Jiang
 
|-
 
|-
 
! style="text-align: left;" |  
 
! style="text-align: left;" |  
 
* MP3 Decoder
 
* MP3 Decoder
| Bruce Jiang
+
| Phil Bloxom
 +
|-
 +
! style="text-align: left;" |
 +
* Bluetooth
 +
| Ritu Patil
 
|-
 
|-
 
! style="text-align: left;" |  
 
! style="text-align: left;" |  
 
* Enclosure
 
* Enclosure
| Bruce Jiang & Ritu Patil
+
| Phil Bloxom
 
|-
 
|-
 
! style="text-align: left;" |  
 
! style="text-align: left;" |  
Line 96: Line 106:
 
* 10/8/2022
 
* 10/8/2022
 
|
 
|
* Read previous projects, gather information and discuss among the group members.
+
* Read previous projects, gather information and discuss among the group member
 
* Create GitLab repository for project
 
* Create GitLab repository for project
 
|  
 
|  
Line 142: Line 152:
 
* Finalize wiki schedule
 
* Finalize wiki schedule
 
* Display objects on screen  
 
* Display objects on screen  
* Develop ADC driver for joystick interfacing control dynamic movement of player spaceship.
+
* Develop ADC driver for joystick interfacing control dynamic movement of player spaceship
 
* Create screen scenes in 32x64 matrices
 
* Create screen scenes in 32x64 matrices
 
|
 
|
 
* <span style="color:green">Completed</span>
 
* <span style="color:green">Completed</span>
 
* <span style="color:green">Completed</span>
 
* <span style="color:green">Completed</span>
* <span style="color:orange">In Progress</span>
+
* <span style="color:green">Completed</span>
* <span style="color:orange">In Progress</span>
+
* <span style="color:green">Completed</span>
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
Line 159: Line 169:
 
* Develop enemy spaceships game algorithm
 
* Develop enemy spaceships game algorithm
 
* Control dynamic movement of player spaceship.
 
* Control dynamic movement of player spaceship.
 +
* Create MP3 Driver
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
 +
* <span style="color:green">Completed</span>
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
Line 170: Line 182:
 
* 11/26/2022
 
* 11/26/2022
 
|
 
|
* Integrate game logic code with LED matrix
+
* Integrate game logic flow from start to end
 
* Develop missile collision and player life algorithm
 
* Develop missile collision and player life algorithm
 
* Integrate game sounds with game logic  
 
* Integrate game sounds with game logic  
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
 
|-
 
|-
 
! scope="row"| 8
 
! scope="row"| 8
Line 189: Line 201:
 
* Update the wiki page
 
* Update the wiki page
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
Line 202: Line 214:
 
* Test pause/play functionality
 
* Test pause/play functionality
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
 
|-
 
|-
 
! scope="row"| 10
 
! scope="row"| 10
Line 217: Line 229:
 
*Update the wiki page
 
*Update the wiki page
 
|
 
|
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
* <span style="color:red">Not started</span>
+
* <span style="color:green">Completed</span>
 
|-
 
|-
 
|}
 
|}
Line 290: Line 302:
 
|}
 
|}
  
== '''Example Template''' ==
+
== '''Overall Design''' ==
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design here.  Show detailed schematics, and the interface here.
+
 
 +
[[File:F22_EG_Overall_Design_Diagram_11_18_2022.png|800px|thumb|center|LED Matrix Rear]]
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
In this section, you can describe how your hardware communicates, such as which BUSes used.  You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
+
* LED Matrix Display: 13 GPIO channel on SJ2 (1)
 +
* Joystick connection: 2 ADC channel on SJ2 (1)
 +
* Bluetooth sender connection: 1 set UART, RX and TX on SJ2 (1)
 +
* Bluetooth receiver connection: 1 set UART, RX and TX on SJ2 (2)
 +
* MP3 Decoder connection: SPI communication, MOSI, CS, SCK, on SJ2 (2)
 +
* Speaker connection: AUX cord
  
 
=== Software Design ===
 
=== Software Design ===
Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
* LED Matrix:
 +
**1. Initialized LED matrix connected pins to board IOs.
 +
**2. Designed matrix driver for screen display by reading an matrix.
 +
 
 +
* Joystick:
 +
**1. Initialized 2 ADC channels for taking the x reading and y reading from joystick.
 +
**2. Decoded voltage readings into joystick movement commands.
 +
 
 +
* Buttons:
 +
**1. Initialized several gpio for taking binary command from button pressed.
 +
**2. Enabled interrupts for each botton pressed.
 +
 
 +
* Mp3 Player:
 +
**1. Initialize using UART3.
 +
**2. Set device with selected sd card and volume.
  
 
=== Implementation ===
 
=== Implementation ===
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
+
* LED Matrix driver functions:
 +
**1. display_update: reload matrix display for refreshing the changes from the backend matrix.
 +
**2. display_clear: erase all matrix values, and sets them to zeros.
 +
**3. overwrite_pattern_to_screen: overite a given pattern onto the existing matrix
 +
**4. append_pattern_to_screen: append a given pattern onto the existing matrix
 +
**5. clear_pattern_on_screen: clear the pattern from screen by giving the pattern's current location and width and height.
 +
 
 +
* Joystick driver:
 +
**1. joystick_running: run ADC capture on joystick continuesly to monitor user inputs.
 +
 
 +
* Buttons driver:
 +
**1. Green button: starts a game, shots a missile, and start the game all over.
 +
 
 +
* Mp3 Player:
 +
**1. Play a song.
 +
**2. Play a song in single cycle.
 +
**3. Play a song from a folder.
 +
**4. Pause on play.
 +
**5. Resume playback.
  
 
== '''RGB LED Matrix''' ==
 
== '''RGB LED Matrix''' ==
Line 311: Line 361:
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
+
The 32x64 LED matrix is from Adafruit, with [https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview user mannual]. It is composed of two upper and lower sectional LED pannels. Each pannel has R, G, B led channels and A, B, C, and D row control registers. Addtionally, column shift is controlled by Latch bit, clock is controled by CLK, and OE turns LED off when switching rows.
 +
 
 +
<center>
 +
<table>
 +
<tr>
 +
<td>
 +
Connectivity Table LED Matrix to Sj2 Board:
 +
{| class="wikitable"
 +
|-
 +
! align="center"|RGB LED Matrix
 +
! align="center"|Pin Description
 +
! align="center"|SJ2 Board
 +
|-
 +
| scope="row" align="center"|R1
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_0
 +
|-
 +
| scope="row" align="center"|G1
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_2
 +
|-
 +
| scope="row" align="center"|B1
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_5
 +
|-
 +
| scope="row" align="center"|R2
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_1
 +
|-
 +
| scope="row" align="center"|G2
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_4
 +
|-
 +
| scope="row" align="center"|B2
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_6
 +
|-
 +
| scope="row" align="center"|A
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P0_6
 +
|-
 +
| scope="row" align="center"|B
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P0_26
 +
|-
 +
| scope="row" align="center"|C
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P0_16
 +
|-
 +
| scope="row" align="center"|D
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P0_22
 +
|-
 +
| scope="row" align="center"|CLK
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P2_9
 +
|-
 +
| scope="row" align="center"|LAT
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P1_20
 +
|-
 +
| scope="row" align="center"|OE
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P1_28
 +
|-
 +
| scope="row" align="center"|VCC
 +
| scope="row" align="center"|5VIN
 +
| scope="row" align="center"|External Power Supply
 +
|-
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|On Board
 +
|-
 +
|}
 +
</td>
 +
<td>
 +
[[File:F22_EG_WelcomeScreen.jpg|500px|thumb|left|LED Matrix Front]]
 +
</td>
 +
<td>
 +
</td>
 +
<td>
 +
[[File:F22_EG_LED_Rear.jpg|500px|thumb|right|LED Matrix Rear]]
 +
</td>
 +
</tr>
 +
</table>
 +
</center>
  
 
=== Software Design ===
 
=== Software Design ===
Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
LED matrix io and driver is developed for communication between boards and LED matrix. IO driver consists of pin inialization by using gpio.h for each rgb channels, row selection register, CLK, LAT, and OE pins. By using "led_matrix_io.h" developers can using public function led_matrix_io_init and other basic controller functions. <br>
 +
For LED matrix driver, it is based on the previous IO driver to provide LED screen update, clean, init, and draw functionalities.
  
 
=== Implementation ===
 
=== Implementation ===
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
+
Rtos Tasks:
 +
*Updating Display: for display to continuously updating screen, a task is assigned for running the display_update function from the driver every 500 milliseconds.
 +
 
 +
== '''Joystick and Buttons''' ==
 +
 
 +
=== Hardware Interface and Connections===
 +
 
 +
<center>
 +
<table>
 +
<tr>
 +
<td>
 +
Connectivity Table LED Matrix to Sj2 Board:
 +
{| class="wikitable"
 +
|-
 +
! align="center"|Joystick
 +
! align="center"|Pin Description
 +
! align="center"|SJ2 Board
 +
|-
 +
| scope="row" align="center"|Vcc
 +
| scope="row" align="center"|Voltage
 +
| scope="row" align="center"|+3.3V
 +
|-
 +
| scope="row" align="center"|Xout
 +
| scope="row" align="center"|Analog X Channel
 +
| scope="row" align="center"|P0_25
 +
|-
 +
| scope="row" align="center"|Yout
 +
| scope="row" align="center"|Analog Y Channel
 +
| scope="row" align="center"|P1_30
 +
|-
 +
| scope="row" align="center"|Button
 +
| scope="row" align="center"|GPIO
 +
| scope="row" align="center"|P1_14
 +
|-
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|GND
 +
|-
 +
|}
 +
</td>
 +
<td>
 +
[[File:F22_EG_Analog_Joystick.png|200px|thumb|right|[https://www.adafruit.com/product/512?gclid=Cj0KCQiA99ybBhD9ARIsALvZavVtFSwQejbcb1pB1_3x5x2FsKY89WqOIHKEsKq_jxfXcSg3rY-AsWQaAlnREALw_wcB Analog Joystick ]]]
 +
</td>
 +
<td>
 +
</td>
 +
</tr>
 +
</table>
 +
</center>
 +
 
 +
=== Software Design ===
 +
Joystick with voltage input produces two analog channels of outputs from the x and y axises of the joystick. Designed a driver to convert these two analog outputs and convert them into digital signals, then decoded as user movment such as move up, move down, move left, move right, move right up, move right down, move left up, and move left down.
 +
 
 +
=== Implementation ===
 +
Rtos Tasks:
 +
*JoyStick Running: Keep recieving two channels of analog signals and decode them into agent moves corresponding to right, left, up, down, right up, right left, left up, and left down.
 +
 
 +
== '''Mp3 Decoder''' ==
 +
 
 +
=== Hardware Interface and Connections===
 +
 
 +
<center>
 +
<table>
 +
<tr>
 +
<td>
 +
Connectivity Table Mp3 Player to Sj2 Board:
 +
{| class="wikitable"
 +
|-
 +
! align="center"|Mp3 Decoder
 +
! align="center"|Pin Description
 +
! align="center"|SJ2 Board
 +
|-
 +
| scope="row" align="center"|Vcc
 +
| scope="row" align="center"|Voltage
 +
| scope="row" align="center"|+3.3V
 +
|-
 +
| scope="row" align="center"|Rx
 +
| scope="row" align="center"|UART3
 +
| scope="row" align="center"|P4_28
 +
|-
 +
| scope="row" align="center"|Tx
 +
| scope="row" align="center"|UART3
 +
| scope="row" align="center"|P4_29
 +
|-
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|GND
 +
| scope="row" align="center"|GND
 +
|-
 +
|}
 +
</td>
 +
<td>
 +
[[File:F22_EG_mp3_encoder.png|200px|thumb|right|[https://www.aliexpress.us/item/3256803093988130.html?pdp_npi=2%40dis%21USD%21US%20%241.67%21%240.99%21%21%21%21%21%40210312ea16702784601312016e68e7%2112000024999658900%21btf&_t=pvid%3Ac6785b98-0d8f-441e-8be9-feb74c7b1693&afTraceInfo=1005003280302882__pc__pcBridgePPC__xxxxxx__1670278460&spm=a2g0o.ppclist.product.mainProduct&gatewayAdapt=glo2usa&_randl_shipto=US Mp3 Player]]]
 +
</td>
 +
<td>
 +
</td>
 +
</tr>
 +
</table>
 +
</center>
 +
 
 +
=== Software Design ===
 +
Mp3 player driver was created. It initialized UART3 and configured IO connections of RX and Tx. To send command for adust volume, play songs by number, play songs by folder name, and set play songs in cycle, please find the user manual here: [https://usermanual.wiki/Pdf/Serial20MP320Player20v10120Manual.2117229468/view mp3 player user manual]
 +
 
 +
=== Implementation ===
 +
Public Tasks:
 +
*Initialize device: Select the sd card which has songs on the player
 +
*Cycle play mode: play a song in single cycle
 +
*Pause a song
 +
*Resume playback
 +
 
 +
== '''Game Logic''' ==
 +
 
 +
=== Game States ===
 +
*1. Start Up
 +
*2. Game Running
 +
*3. Game Over
 +
 
 +
=== Player Task===
 +
Game state: start up
 +
*1. Display start up screen once per starting
 +
*2. Reset game parameters
 +
 
 +
Game state: game running
 +
*1. Display player and health bar on screen
 +
*2. Capture and move player location by joystick signals
 +
*3. Check health and switch to game over state when player's health reaches zero
 +
*4. Check collision in collision mutex
 +
 
 +
Game state: game over
 +
*1. Display game over screen
 +
 
 +
=== Enemy Task===
 +
Game state: game running
 +
*1. Spawn enemy according to a timer for different game levels
 +
*2. Checking enemy collision in collision mutex
 +
*3. Remove collided enemy within a list of enemy objects
 +
 
 +
=== Button Task===
 +
Game state: start up
 +
*1. Play the back ground music in single cycle
 +
*2. If the green button is pressed, advanced to game running stage
 +
 
 +
Game state: game running
 +
*1. Play the back groud music in single cycle
 +
*2. If the green button is pressed, generate missile on screen and play a laser sound
 +
 
 +
Game state: game over
 +
*1. Play the game over music in single cycle
 +
*2. If the green button is pressed, return the state over all back to start up
 +
 
 +
=== Missile Task ===
 +
Game state: game running
 +
*1. Check missile collision with enemy, player, and the boundary of the screen
 +
*2. Append missiles in array
 +
 
 +
=== Score Task ===
 +
Game state: game running
 +
*1. If a missile hit an enemy, score plus two
 +
*2. If an enemy hit the bottom white line, which is our home base, score minus two
 +
*3. According to the number of score, increase enemy speed and spawn rate by a fix proportion
  
 
== '''Testing & Technical Challenges''' ==
 
== '''Testing & Technical Challenges''' ==
Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again?
+
Most of the challenges for our project are bluetooth paring and game logic. For bluetooth to work between two boards, the configuration driver was wrote from scratch, which enable the device, and select paring bluetooth's physical address. For game logic, the problems are making sure the collision happened between mutiple objects with different moving speed.  
Make a smooth transition to testing section and described what it took to test your project.
 
  
Include sub-sections that list out a problem and solution, such as:
+
=== Bug/Issue Name ===
 
+
{| class="wikitable"
=== <Bug/issue name> ===
+
|-
Discuss the issue and resolution.
+
! scope="col" | Bug Number
 +
! scope="col" | Description
 +
! scope="col" | Solution
 +
|-
 +
|
 +
* 1
 +
|
 +
* Two bluetooth device are not talking to each others automatically.
 +
|
 +
* Used SJ2 board to configure the bluetooth through UART with AT commands
 +
|-
 +
|
 +
* 2
 +
|
 +
* When a missile hit an enemy on the screen, sometimes, the missile will disapear first but not the enemy, and sometimes, the other way around.
 +
|
 +
* Used mutex and pair locks to make sure when collision happened, only erase both objects by receiving both acknowledgments from enemy and missile.
 +
|-
 +
|
 +
* 3
 +
|
 +
* Button debounce issue.  
 +
|
 +
* The button interrupt from ISR was not performing ideally. By using Preet's suggestion, a simple task of reading the button input solved this problem. 
 +
|-
 +
|
 +
* 4
 +
|
 +
* Player animation conflicts with moving missile.
 +
|
 +
* Disabled missile generation while before playing the animation. 
 +
|}
  
 
== '''Conclusion''' ==
 
== '''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?
+
Coding a complicated Atari game on a microcontroller is a bit more complicated than we thought before starting. We went through writing our own base line driver for controlling other electronic components. Then, figured out FreeRTOS task API to move each character pixels on the led matrix. During development, we faced all different kind of issues such as button debounce, priority conflicts, parallel logic in sequential programming, and etc. In the end, we truly learned that nothing is for granted, as an embedded engineers we have to do everthing ourselves. This project can be further improved on score system and joystick movements.   
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
https://youtu.be/QRE9pQ7dBBg
  
 
=== Project Source Code ===
 
=== Project Source Code ===
 +
https://gitlab.com/runfeng.jiang/cmpe-244-space-invader-game/-/tree/main
  
 
== '''References''' ==
 
== '''References''' ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
Special thanks to Mr. Preet Kang for his lessons and detailed-documentation website on microcontrollers.
  
 
=== References Used ===
 
=== References Used ===
List any references used in project.
+
*1. Mp3 user manual: https://usermanual.wiki/Pdf/Serial20MP320Player20v10120Manual.2117229468/view
 +
*2. LPC40xx_FreeRtos Github: https://gitlab.com/sjtwo-c-dev/sjtwo-c
 +
*3. Adafruit LED matrix user manual: https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/
  
 
=== Appendix ===
 
=== Appendix ===
You can list the references you used.
+
*1. LPC40xx_FreeRtos Github: https://gitlab.com/sjtwo-c-dev/sjtwo-c
 +
*2. FreeRTOS: https://www.freertos.org/a00116.html

Latest revision as of 23:03, 14 December 2022

Guardians of the Galaxy

Start Screen
Game Play
End Screen

Abstract

A horizontal type of space invader game. Players can control the spaceship on the screen composed of an LED matrix in a rectangular shape. The spaceship can shoot horizontally from left to right in order to destroy its enemies. The entire map will flow in the opposite direction of where the spaceship is flying. The speed of the map flow and the number of enemies will increase at higher difficulty levels. The spaceship takes damage from colliding with enemies themselves or their bullets. The game will end when the health of the controlled spaceship is depleted.

Objectives & Introduction

Technical Responsibilities

Technical Roles
  • Game Logic Development
Bruce Jiang
  • LED Display Driver
Bruce Jiang
  • Joystick Controller Driver
Bruce Jiang
  • MP3 Decoder
Phil Bloxom
  • Bluetooth
Ritu Patil
  • Enclosure
Phil Bloxom
  • Hardware Integration
Bruce Jiang & Phil Bloxom

Administrative Responsibilities

Administrative Roles
  • Team Leader
Ritu Patil
  • Git Repository Managers
Bruce Jiang
  • Code Reviewers
Phil Bloxom
  • Wiki Report Manager
Bruce Jiang
  • Bill of Materials Manager
Ritu Patil

Schedule

Week# Start Date End Date Task Status
1
  • 10/03/2022
  • 10/8/2022
  • Read previous projects, gather information and discuss among the group member
  • Create GitLab repository for project
  • Completed
  • Completed
2
  • 10/10/2022
  • 10/15/2022
  • Order necessary parts
  • Completed
3
  • 10/17/2022
  • 10/22/2022
  • Read and familiarize with LED Matrix Datasheet
  • Completed
4
  • 10/31/2022
  • 11/05/2022
  • Develop graphics driver for LED matrix and implement initial game objects
  • Research how to create objects pattern for display from PNG
  • Completed
  • Completed
5
  • 11/07/2022
  • 11/12/2022
  • Finalize wiki schedule
  • Display objects on screen
  • Develop ADC driver for joystick interfacing control dynamic movement of player spaceship
  • Create screen scenes in 32x64 matrices
  • Completed
  • Completed
  • Completed
  • Completed
6
  • 11/14/2022
  • 11/19/2022
  • Integration of circuit boards and microcontroller
  • Develop enemy spaceships game algorithm
  • Control dynamic movement of player spaceship.
  • Create MP3 Driver
  • Completed
  • Completed
  • Completed
  • Completed
7
  • 11/21/2022
  • 11/26/2022
  • Integrate game logic flow from start to end
  • Develop missile collision and player life algorithm
  • Integrate game sounds with game logic
  • Completed
  • Completed
  • Completed
8
  • 11/28/2022
  • 12/03/2022
  • Integrate subsystem
  • Finalizing the video game
  • Update the wiki page
  • Completed
  • Completed
  • Completed
9
  • 12/05/2022
  • 12/10/2022
  • Address bugs during testing of integrated system
  • Test pause/play functionality
  • Completed
  • Completed
10
  • 12/11/2022
  • 12/11/2022
  • Final Demo
  • Update Gitlab repo with final code
  • Update test video
  • Update the wiki page
  • Completed
  • Completed
  • Completed
  • Completed

Bill of Materials (General Parts)

Part Name Part Model & Source Quantity Cost Per Unit (USD)
  • Micro-Controller SJ2 Board
  • SJ2 Board (Purchased from Preet Kang)
  • 1
  • 50.00
  • RGB LED Matrix
  • 1
  • 44.95
  • Power Supply
  • 1
  • 15.98
  • IDC Socket Male
  • 1
  • 0.3
  • HC-05 Bluetooth
  • 2
  • 10
  • Analog Joystick
  • 1
  • 6

Overall Design

Hardware Design

LED Matrix Rear

Hardware Interface

  • LED Matrix Display: 13 GPIO channel on SJ2 (1)
  • Joystick connection: 2 ADC channel on SJ2 (1)
  • Bluetooth sender connection: 1 set UART, RX and TX on SJ2 (1)
  • Bluetooth receiver connection: 1 set UART, RX and TX on SJ2 (2)
  • MP3 Decoder connection: SPI communication, MOSI, CS, SCK, on SJ2 (2)
  • Speaker connection: AUX cord

Software Design

  • LED Matrix:
    • 1. Initialized LED matrix connected pins to board IOs.
    • 2. Designed matrix driver for screen display by reading an matrix.
  • Joystick:
    • 1. Initialized 2 ADC channels for taking the x reading and y reading from joystick.
    • 2. Decoded voltage readings into joystick movement commands.
  • Buttons:
    • 1. Initialized several gpio for taking binary command from button pressed.
    • 2. Enabled interrupts for each botton pressed.
  • Mp3 Player:
    • 1. Initialize using UART3.
    • 2. Set device with selected sd card and volume.

Implementation

  • LED Matrix driver functions:
    • 1. display_update: reload matrix display for refreshing the changes from the backend matrix.
    • 2. display_clear: erase all matrix values, and sets them to zeros.
    • 3. overwrite_pattern_to_screen: overite a given pattern onto the existing matrix
    • 4. append_pattern_to_screen: append a given pattern onto the existing matrix
    • 5. clear_pattern_on_screen: clear the pattern from screen by giving the pattern's current location and width and height.
  • Joystick driver:
    • 1. joystick_running: run ADC capture on joystick continuesly to monitor user inputs.
  • Buttons driver:
    • 1. Green button: starts a game, shots a missile, and start the game all over.
  • Mp3 Player:
    • 1. Play a song.
    • 2. Play a song in single cycle.
    • 3. Play a song from a folder.
    • 4. Pause on play.
    • 5. Resume playback.

RGB LED Matrix

Hardware Design

Below are symbol and footprint for custom component-part in EasyEDA tool. These parts would be used in future PCB design.

LED Matrix and SJ2 Board Connections Schematics
LED Matrix and SJ2 Board Connections PCB



Hardware Interface

The 32x64 LED matrix is from Adafruit, with user mannual. It is composed of two upper and lower sectional LED pannels. Each pannel has R, G, B led channels and A, B, C, and D row control registers. Addtionally, column shift is controlled by Latch bit, clock is controled by CLK, and OE turns LED off when switching rows.

Connectivity Table LED Matrix to Sj2 Board:

RGB LED Matrix Pin Description SJ2 Board
R1 GPIO P2_0
G1 GPIO P2_2
B1 GPIO P2_5
R2 GPIO P2_1
G2 GPIO P2_4
B2 GPIO P2_6
A GPIO P0_6
B GPIO P0_26
C GPIO P0_16
D GPIO P0_22
CLK GPIO P2_9
LAT GPIO P1_20
OE GPIO P1_28
VCC 5VIN External Power Supply
GND GND On Board
LED Matrix Front
LED Matrix Rear

Software Design

LED matrix io and driver is developed for communication between boards and LED matrix. IO driver consists of pin inialization by using gpio.h for each rgb channels, row selection register, CLK, LAT, and OE pins. By using "led_matrix_io.h" developers can using public function led_matrix_io_init and other basic controller functions.
For LED matrix driver, it is based on the previous IO driver to provide LED screen update, clean, init, and draw functionalities.

Implementation

Rtos Tasks:

  • Updating Display: for display to continuously updating screen, a task is assigned for running the display_update function from the driver every 500 milliseconds.

Joystick and Buttons

Hardware Interface and Connections

Connectivity Table LED Matrix to Sj2 Board:

Joystick Pin Description SJ2 Board
Vcc Voltage +3.3V
Xout Analog X Channel P0_25
Yout Analog Y Channel P1_30
Button GPIO P1_14
GND GND GND

Software Design

Joystick with voltage input produces two analog channels of outputs from the x and y axises of the joystick. Designed a driver to convert these two analog outputs and convert them into digital signals, then decoded as user movment such as move up, move down, move left, move right, move right up, move right down, move left up, and move left down.

Implementation

Rtos Tasks:

  • JoyStick Running: Keep recieving two channels of analog signals and decode them into agent moves corresponding to right, left, up, down, right up, right left, left up, and left down.

Mp3 Decoder

Hardware Interface and Connections

Connectivity Table Mp3 Player to Sj2 Board:

Mp3 Decoder Pin Description SJ2 Board
Vcc Voltage +3.3V
Rx UART3 P4_28
Tx UART3 P4_29
GND GND GND

Software Design

Mp3 player driver was created. It initialized UART3 and configured IO connections of RX and Tx. To send command for adust volume, play songs by number, play songs by folder name, and set play songs in cycle, please find the user manual here: mp3 player user manual

Implementation

Public Tasks:

  • Initialize device: Select the sd card which has songs on the player
  • Cycle play mode: play a song in single cycle
  • Pause a song
  • Resume playback

Game Logic

Game States

  • 1. Start Up
  • 2. Game Running
  • 3. Game Over

Player Task

Game state: start up

  • 1. Display start up screen once per starting
  • 2. Reset game parameters

Game state: game running

  • 1. Display player and health bar on screen
  • 2. Capture and move player location by joystick signals
  • 3. Check health and switch to game over state when player's health reaches zero
  • 4. Check collision in collision mutex

Game state: game over

  • 1. Display game over screen

Enemy Task

Game state: game running

  • 1. Spawn enemy according to a timer for different game levels
  • 2. Checking enemy collision in collision mutex
  • 3. Remove collided enemy within a list of enemy objects

Button Task

Game state: start up

  • 1. Play the back ground music in single cycle
  • 2. If the green button is pressed, advanced to game running stage

Game state: game running

  • 1. Play the back groud music in single cycle
  • 2. If the green button is pressed, generate missile on screen and play a laser sound

Game state: game over

  • 1. Play the game over music in single cycle
  • 2. If the green button is pressed, return the state over all back to start up

Missile Task

Game state: game running

  • 1. Check missile collision with enemy, player, and the boundary of the screen
  • 2. Append missiles in array

Score Task

Game state: game running

  • 1. If a missile hit an enemy, score plus two
  • 2. If an enemy hit the bottom white line, which is our home base, score minus two
  • 3. According to the number of score, increase enemy speed and spawn rate by a fix proportion

Testing & Technical Challenges

Most of the challenges for our project are bluetooth paring and game logic. For bluetooth to work between two boards, the configuration driver was wrote from scratch, which enable the device, and select paring bluetooth's physical address. For game logic, the problems are making sure the collision happened between mutiple objects with different moving speed.

Bug/Issue Name

Bug Number Description Solution
  • 1
  • Two bluetooth device are not talking to each others automatically.
  • Used SJ2 board to configure the bluetooth through UART with AT commands
  • 2
  • When a missile hit an enemy on the screen, sometimes, the missile will disapear first but not the enemy, and sometimes, the other way around.
  • Used mutex and pair locks to make sure when collision happened, only erase both objects by receiving both acknowledgments from enemy and missile.
  • 3
  • Button debounce issue.
  • The button interrupt from ISR was not performing ideally. By using Preet's suggestion, a simple task of reading the button input solved this problem.
  • 4
  • Player animation conflicts with moving missile.
  • Disabled missile generation while before playing the animation.

Conclusion

Coding a complicated Atari game on a microcontroller is a bit more complicated than we thought before starting. We went through writing our own base line driver for controlling other electronic components. Then, figured out FreeRTOS task API to move each character pixels on the led matrix. During development, we faced all different kind of issues such as button debounce, priority conflicts, parallel logic in sequential programming, and etc. In the end, we truly learned that nothing is for granted, as an embedded engineers we have to do everthing ourselves. This project can be further improved on score system and joystick movements.

Project Video

https://youtu.be/QRE9pQ7dBBg

Project Source Code

https://gitlab.com/runfeng.jiang/cmpe-244-space-invader-game/-/tree/main

References

Acknowledgement

Special thanks to Mr. Preet Kang for his lessons and detailed-documentation website on microcontrollers.

References Used

Appendix