F22: Thunder Flash

From Embedded Systems Learning Academy
Revision as of 03:09, 12 December 2022 by 243 user5 (talk | contribs) (Scoring)

Jump to: navigation, search
Traditional Bow and Arrow Game on Windows


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.

Bow and Arrow

Abstract

Bow and arrow is a fun, aiming archery game. Our goal is to produce a similar version of ‘Bow and Arrow’ where the archer aims the arrow at the targets (balloons) using the bow. The game would have different levels and the archer would get 3 lives to score maximum points. As the level increases the challenges and speed of the game increase. In the later levels, there would be monsters coming onto the archer. In the later levels, there would be monsters coming onto the archer, and the archer should make sure he dodges those obstacles to save his life and hit the balloons to earn points. This is all displayed on the LED matrix acting as the screen.

Objectives & Introduction

The main objective of this project was to create the “Bow and Arrow” video game displayed on a 64X64 RGB LED matrix, with one SJ2 board as a graphics processor/matrix controller, and another SJ2 board as a controller. Other objectives are the following:

  • Design custom PCBs for both the gamepad and matrix controller SJ2 boards.
  • Use the FreeRTOS Real-Time Operating System on both SJ2 boards.
  • Establish UART communications through Xbee between the two SJ-Two Microcontrollers.
  • Create simple coding logic for displaying required characters and game objects.
  • Add background music to the game to enhance the gameplay experience.

Team Members & Technical Responsibilities

  • Shreya Kulkarni
    • Integrating of Graphics Driver
    • Game logic design
    • Joystick and button Implementation
  • Pinky Mathew
    • Interfacing of LED Matrix and driver design
    • Game logic design and implementation
    • Graphics driver design and implementation
    • Joystick Integration
  • Pushkar Deodhar
    • Zigbee module
    • Integrating MP3 module with the Game
    • Hardware Designing & PCB Integration
  • Noel Smith
    • MP3 Audio Encoder/Decoder
    • Integrating MP3 player with the Game
    • Hardware Designing & PCB Integration


Administrative Responsibilities

Administrative Roles
  • Finance Manager
Noel Smith
  • Git Repository Manager
Pinky Mathew
  • Wiki Report Manager
Shreya Kulkarni
  • Bill of Materials Manager
Pushkar Deodhar


Schedule

Week# Start Date End Date Task Status
1
  • 10/16/2022
  • 10/23/2022
  • Analyze previous projects, discussion and finalize game
  • Discuss and order components
  • Create a GitLab repository.
  • Completed
2
  • 10/24/2022
  • 10/29/2022
  • Discuss and plan down the project into modules and assign responsibilities
  • Familiarize with relevant hardware datasheets
  • Completed
3
  • 10/30/2022
  • 11/05/2022
  • Develop driver for joystick
  • Develop driver for LED display
  • Design game start, end, level screen
  • Finalize wiki schedule
  • Completed
4
  • 11/06/2022
  • 11/16/2022
  • Integration of joystick and character motion
  • Develop driver for MP3 Decoder
  • Game logic development
  • Completed
5
  • 11/17/2022
  • 11/20/2022
  • Order circuit boards components and complete the design for printing
  • circuit board and component assembly
  • Circuit board testing
  • Game logic development
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
6
  • 11/21/2022
  • 11/23/2022
  • Integration of circuit boards and microcontroller
  • Continue game logic development
  • Testing and debugging the game logic
  • Completed
  • Completed
  • Completed
7
  • 11/27/2022
  • 12/03/2022
  • Integrate game logic code with LED matrix
  • Integrate game sounds with game logic
  • Completed
  • Completed
8
  • 12/04/2022
  • 12/10/2022
  • Integrate subsystems
  • Update the wiki page.
  • Completed
  • Completed
  • Completed
9
  • 12/07/2022
  • 12/13/2022
  • Address bugs found during system integration
  • Test pause/play functionality
  • Completed
  • Completed
  • Completed
10
  • 12/14/2022
  • 12/15/2022
  • Final Demo
  • Update Gitlab repo with final code
  • Add demo video
  • Update the wiki page
  • In progress
  • In progress
  • In progress
  • In progress


Bill Of Materials

Item# Part Description Part Model & Vendor Quantity Cost
1 Microcontroller Boards SJ2 Boards (Purchased from Preet Kang) 2 $100.00
2 LED Matrix Display Adafruit RGB LED Matrix Panel - 64x64 1 $87.95
3 PCB JLC PCB 5 $18.00
4 Electronics Fun Kit & Power Supply Module ELEGOO Upgraded Electronics Fun Kit 2 $7.56
5 MP3 Decoder HiLetgo YX5300 UART Control Serial MP3 Music Player Module 1 $6.99
6 Power Adapter for LED Matrix Belker 36W Adapter 1 $15.00
7 XBee Module XBee 2mW Wire Antenna - Series 2C (ZigBee Mesh) 2 $62.00
8 Joystick HiLetgo Game Joystick Sensor Game Controller 1 $4.89
9 Push Button Switch Anchor Electronics 1 $1.00
10 Jumper Cables Anchor Electronics 1 $7.00
11 Female headers for SJ2-PCB Connection Anchor Electronics 1 $2.50
12 Ribbon Cable Connector for LED Matrix-PCB Connection Anchor Electronics 1 $1.00
13 Soldering Wire & 18 Gauge Wire Anchor Electronics 1 $3.00
14 Copper Board for Game Controller Connections Anchor Electronics 1 $4.00
Total Cost 22 $317.89


Design & Implementation

PIN CONFIGURATION

  • Pin# SJ2 Main Board - LED Matrix Pin Configuration SJ-2 PIN
    R1 PIN for Red terminal of RGB LED for the upper half of LED Matrix P0_0
    G1 PIN for Green terminal of RGB LED for the upper half of LED Matrix P0_1
    B1 PIN for Blue terminal of RGB LED for the upper half of LED Matrix P2_2
    R2 PIN for Red terminal of RGB LED for the lower half of LED Matrix P2_4
    G2 PIN for Green terminal of RGB LED for the lower half of LED Matrix P2_5
    B2 PIN for Blue terminal of RGB LED for the 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_28
    LATCH Data Latch P1_29
    CLK Clock Signal P0_17
    MP3 Decoder
    RX UART Receive From MP3 Decoder P2_1
    TX UART Send Command from SJ-2 Main Board P2_0
    XBEE Module Receiver
    RX UART Receive From Game Controller P0_11
    VCC VCC Supply VCC 3.3
  • Pin# Controller Board Pin Configuration uC PIN
    XBEE Module Transmitter
    TX UART Transmit to Main Board P0_10
    VCC VCC Supply VCC 3.3
    Joystick
    VCC VCC 3.3V
    GND GND GND
    Vx X-axis ADC Reading for character movement P0_25
    Push Button
    I/0 Pin Arrow Shooting P1_29

RGB Led Matrix

The display in this project is a 64x64 RGB LED matrix panel with a scan rate of 1:32. The 4096 RGB LEDs in the LED matrix panel can each be individually controlled and addressed. The SJ-two board does not have enough GPIOs to support 4069 LEDs, so this LED Matrix uses just 13 digital GPIOs to provide complete control of each individual LED. The LED matrix does this by using a decoder to pick the rows and a 64-bit shift register to enable the desired color on the selected column. Data is placed into the shift register to choose the columns when the row selection is low. In this 64x64 LED matrix, which has six 64-bit shift registers for R1, G1, B1, R2, G2, and B2, each color of the LED is controlled by one bit of the shift register. The display can only display 8 colors because it uses daisy-chained shift registers, which prevents PWM from being used to individually control each LED. The 5:32 decoders are used to control the LED matrix's top (Rows 0-31) and bottom (Rows 32-63) halves, respectively, as shown in the diagram below. Each of the lines A, B, C, D, and E of these decoders, which are used for row selection, has a 5-bit input.

How to illuminate an LED in the matrix:

  1. Represent the color you want to appear on the board using three bits.
  2. Choose whether you want to light an LED that is on the board's UPPER or LOWER side, and then adjust RGB1 or RGB2 pins accordingly.
  3. To set the bits and clock them in with the other LEDs, toggle the CLK (You can set the other LEDs to be off by clocking in zero)
  4. Once a full row has been entered, disable Output and set Latch High.
  5. Using the A, B, C, D, and E pins, indicate which row your target LED is on.
  6. Reactivate the Output and lower the Latch's value.
LED selection


Elegoo Power Supply Module

We opt to use the Power supply Module that came with the ELEGOO Upgraded Electronics Fun Kit rather than independently powering the SJ-two board, led matrix, and MP3 decoder. This supply module takes input via a barrel jack from a battery, a 12V power source, or any other source, and outputs 5V to our circuit as needed. To power a solderless breadboard layout, this module offers a cheap and practical way to convert a 7-12V wall plug into 5V and 3.3V. 700mA is the maximum output current. One 5V connector will link to the SJ-two board's Vcc, and the 64x64 led matrix will be powered by 5V.

Power Module


LED Matrix and Controller Board Enclosure

From the boxes we had on hand, we created the enclosures for our controller board and LED matrix. We positioned our matrix at an angle to provide the player with the best possible immersive experience. The controller board is not linked to the matrix enclosure, allowing the player to sit back, relax, and play the arcade game relatively comfortably. The controller board has its own enclosure, and the XBee module is used to communicate between the boards.


MP3 Decoder

This module is a straightforward MP3 player that runs on the YX5300 high-quality MP3 audio chip. MP3 and WAV file formats with sampling rates of 8 kHz to 48 kHz are supported. The micro SD card used to store the audio files can be inserted because there is a TF card socket on the board. By sending commands to the module via the UART interface, the MCU can control the MP3 playback state by altering the volume, switching tracks, etc.

Serial MP3 Player

Hardware Design

The UART Tx, UART Rx, VCC, and GND pins are the 4 pins that the MP3 decoder module needs. The SJ2 board provided the module with the 3.3V it needed to start up. On the SJ2 board, UART1 pins have been set up so that commands can be sent to the decoder. This UART communication's baud rate is set at 9600 bps. Additionally, this decoder has a speaker-connected 3.5mm audio jack.

Connection diagram of MP3 decoder to SJ2 board.

Software Design

MP3 Initialization
MP3 Music


Controller Board and Main Board Communication

You may quickly configure XBees, test connections, and pass data between your computer and remote XBees by connecting an XBee Explorer between your computer and your XBee and using the X-CTU software. We utilize X-CTU, free software offered by Digi (the XBee maker), to set up, manage, and test XBee networks. An excellent step-by-step instruction for configuring the Xbees as a transmitter and receiver can be found on the SparkFun website at here. The Xbee module, button press, and joystick make up the controller board. A joystick is used to control character movement, while a button is used to activate the shoot arrow. Using ADC, the joystick reading is captured. We must enable burst mode on the ADC, which performs repeated conversion at 400 kHz, rather than reading a single value each time. Then, using Xbee, this information is transferred from the controller board to the mainboard (which houses the game logic and led drivers). Data is sent over UART after being received at the receiver end. The joystick ADC reading is represented by bits A0-A6 of the UART frame, whereas the button press data is represented by bit A7 of the frame. Blank data is sent if the button is not pressed. When an ISR is called after a UART interrupt, data is sent into the queue. The task that was dormant in the queue now awakens and, based on the data, moves the characters.

System Diagram


Game Controller reading data from joystick and sending to UART logic

void read_joystick_and_send(void *p) {
  while (1) {
    uint16_t joystick_reading = adc__get_channel_reading_with_burst_mode(ADC__CHANNEL_2);
    joystick_reading = (joystick_reading * 125) / 4095;
    if (!(LPC_GPIO1->PIN & (1 << 31)))
      joystick_reading |= 1 << 7;
    uart_lab__polled_put(2, joystick_reading);
    vTaskDelay(5);
  }
}


Configuring Xbee

You will most probably have to configure your XBee with XCTU softwarelink and using the board link, before interfacing XBee with SJ2. Refer to this video link to initially configure XBee. You will have to connect XBee with the board to your PC for configuration.

Game Logic

write game logic here --> "pinky"

The game begins at level 1. In level one, until the player earns enough points or runs out of lives, the balloon creation task produces successive sets of balloons. The task detects the collision when the arrow's starting coordinate strikes the balloon's top-most coordinate, at which point the balloon hit occurs meaning it gets to turn into the black by the program. The same reasoning holds true for other balloon collisions. Only one person can begin level 2 once they have earned enough points in level 1. The game's complexity has been raised in level 2. In addition to randomizing balloon placement, we've also introduced rock-shaped impediments as a further challenge. Therefore, as the player strikes the rock, the life count drops. Additionally, a player's score rises as they hit the balloons. A player alone wins the game if the score reaches a certain threshold of points. We've limited the number of arrows to 10 to make the game more enjoyable.

Game Logic


For level 2 as we have added rocks, the rock hit logic is implemented (if the rock start row is lesser than equal to the arrowhead coordinates which is also less than the rock start row plus rock height, and the rock start column is lesser than equal to arrowhead coordinates which is also lesser than rock start column plus rock width) --> rock collided is detected and lives count is reduced by one out of three. If the rock collision is detected rock disappear function is called and as the live count is reduced, the make life disappears function is also function will also get executed.

Collision Logic for Rock


We have implemented the collision logic for the balloon by the condition i.e. (if the arrows head coordinates are lesser than equal to than balloon's start row plus the balloon's height and arrowhead coordinates are lesser than equal to the balloon start column plus the balloon width), balloon collision is detected and player's score is increased by 5 points per each balloon. So if the balloon_is_collided condition is true then the balloon disappear function gets called making the balloon color black. Concurrently game score task is called and the score gets increased by 5 points.

Collision Logic of Ballon


In our Bow and Arrow project, the command we use to play the songs is by navigating to its index on the SD card. In our code, the function that sends this command is referred to as playing music at the index. We must first send the command [Select device] before we can send the instruction to play music at a specific index. The datasheet specifies that you should send "7E FF 06 09 00 00 02 EF" since Serial MP3 Player only accepts micro SD cards. Additionally, the function UART polled put on UART1 is being used to transmit the commands.

Scoring

LEVEL 1 score logic
LEVEL 2 score logic

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? 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

Discuss the issue and resolution.

1. Along with the LED matrix and MP3 decoder, we have also wired the Xbee receiver directly to SJ2 using a pin-to-pin connection. The LED matrix screen would occasionally not turn on, but if we detached and reconnected the GND wire of the Xbee receiver, it would.

Conclusion

This project was a huge success and a valuable teaching tool. Every module used for the project was effectively integrated, and we were able to reproduce our original game concept. The LED matrix was able to play the noises for each of the game components while loading our character moving, jumping, and separating balls. We also demonstrated our life and score tracking logic during the event. We encountered a number of challenges while working on the project, including issues starting the LED matrix driver, figuring out how to incorporate ballon and arrow collision detection, creating multiple ballons and creating randomly positioned balloons in level 2, designing and maintaining our complex game logic state machine, and much more. We were able to understand the real-world use of FreeRTOS while working on our project. We came to the conclusion that defining weekly goals and exceeding them could assist compartmentalize the project and eventually meet the desired outcome. This project improved our proficiency with embedded software and consolidated our command of it.


Project Video

Upload a video of your project and post the link here.

Project Source Code

  • github repository link[1]

Acknowledgement

We would like to thank Professor Preetpal Kang for sharing his knowledge and insights with us during the course of the project. 

References Used

  1. Serial MP3 Player Datasheet
  2. Binary code pattern generator for LED Matrix
  3. Everything You Didn't Want to Know About RGB Matrix Panels



Appendix

You can list the references you used.