Difference between revisions of "F20: Bubble Shooter"

From Embedded Systems Learning Academy
Jump to: navigation, search
(LED Matrix Interfacing)
Line 396: Line 396:
  
 
=== LED Matrix Interfacing ===
 
=== LED Matrix Interfacing ===
[[File:LED Matrix Schematic.png|800x300px |thumb|right|LED Matrix Interfacing]]
+
 
[[File:LED Bubble Shooter.png|800x300px |thumb|left|Start Screen of the game]]
+
[[File:LED Matrix Schematic.png|800x300px|thumb|left|LED Matrix Interfacing]]
 +
[[File:LED Bubble Shooter.png|800x300px|thumb|center|Start Screen of the game]]
 +
 
 +
 
  
 
{| class="wikitable"
 
{| class="wikitable"

Revision as of 01:21, 18 December 2020

Abstract

Bubble shooter is an arcade game that has bubbles or balls present on the screen. The bubbles are of different colors and the goal is to clear them by forming a group of bubbles (3 or more) of the same color. Points are earned upon clearing the bubbles and increases with the number of bubbles cleared in a single shot. The player wins upon clearing the screen and loses when the bubbles touch the bottom of the screen.


Block Diagram of Bubble Shooter

Objectives & Introduction

The objective of this project is to develop a simple, single-player 2D game using LPC 4078 microcontroller on an LED matrix display. It focuses on integrating the micro-controller peripheral drivers, led drivers, MP3 player, button and joystick controller interface and the application software in FreeRTOS. The button controller interface consists of the joystick for moving the shooter left and right. The button is used to fire the ball.

Team Members

Technical Responsibilities

  • Game Logic Development
Hisaam Hashim, Amiraj Nigam, Anirudh Ashrit, Akshat Bhutiani
  • PCB Design
Anirudh Ashrit
  • LED Display Driver
Hisaam Hashim
  • Graphics Driver
Hisaam Hashim, Akshat Bhutiani
  • Mp3 Decoder Driver
Amiraj Nigam, Anirudh Ashrit
  • Joystick Integration
Akshat Bhutiani
  • Hardware Integration
Amiraj Nigam, Hisaam Hashim

Administrative Responsibilities

  • Team Leader
Hisaam Hashim
  • Git Repository Managers
Akshat Bhutiani & Anirudh Ashrit
  • Code Reviewer
Hisaam Hashim
  • Wiki Report Managers
Amiraj Nigam & Anirudh Ashrit
  • Bill of Materials Manager
Akshat Bhutiani


Schedule

Week# Start Date End Date Task Status
1
  • 10/12/2020
  • 10/16/2020
  • 10/18/2020
  • 10/18/2020
  • Literature Survey of Previous year Projects
  • Submission of Project Proposal
  • Completed
  • Completed
2
  • 10/18/2020
  • 10/20/2020
  • Gitlab Repository Created
  • Wiki Schedule page Created
  • Completed
  • Completed
3
  • 10/20/2020
  • 11/01/2020
  • Read and familiarize with LED Matrix Datasheet.
  • Finalize the Components and place the order
  • Completed
  • Completed
4
  • 11/01/2020
  • 11/10/2020
  • Understand the ball tracing logic
  • Understand the logic for ball queue
  • Completed
  • Completed
5
  • 11/09/2020
  • 11/09/2020
  • 11/09/2020
  • 11/09/2020
  • 11/10/2020
  • 11/15/2020
  • 11/15/2020
  • 11/15/2020
  • Finalize wiki schedule
  • LED Matrix Driver Development
  • MP3 Decoder Driver Development
  • Joystick driver development and interfacing
  • Game logic development
  • Completed
  • Completed
  • Completed
  • Completed
  • Completed
6
  • 11/16/2020
  • 11/22/2020
  • Designing of levels in the game
  • Testing trigger motions
  • Testing and debugging the game logic
  • PCB Designing
  • Completed
  • Completed
  • Completed
  • Completed
7
  • 11/23/2020
  • 11/29/2020
  • Integrate game logic code with LED matrix
  • Integrate game sounds with game logic
  • Completed
  • Completed
8
  • 11/30/2020
  • 12/06/2020
  • Integrate subsystem
  • Finalizing the video game
  • Update the wiki page.
  • Completed
  • Completed
  • Completed
9
  • 12/07/2020
  • 12/13/2020
  • Address bugs during testing of an integrated system
  • Test pause/play functionality
  • Completed
  • Completed
10
  • 12/16/2020
  • 12/14/2020
  • 12/14/2020
  • 12/14/2020
  • 12/16/2020
  • 12/16/2020
  • 12/16/2020
  • 12/16/2020
  • Final Demo
  • Update Gitlab repo with final code.
  • Update test video.
  • Update the wiki page.
  • Completed
  • Completed
  • In progress
  • in progress


Bill Of Materials

Item# Part Description Part Model & Vendor Quantity Cost
1 Microcontroller Boards SJ2 Boards (Purchased from Preet Kang) 1 $50.00
2 LED Matrix Display RGB LED Matrix Panel - 32X64 1 $55.00
3 Audio decoder Breakout Board MP3 PLayer Shield 1 $26.95
4 Analog 2-axis Thumb Joystick Analog 2-axis Joystick 1 $10.36
5 Power Supply 5V/3A Power Supply 1 $8.99


PCB Design

The board is designed to connect modules in the game directly. Autodesk's Eagle software is used to design the Schematics and Board layout. The board has 2 layers(Top and Bottom). JLCPCB is the manufacturer of the PCB board.


Schematic Design of PCB
PCB Board Layout
Design Overview of the PCB


Hardware Design & Implementation

Analog Joystick

An ADA512 2-axis Analog Joystick and Button is used for controlling the movement of the launcher and shooting the ball. The data from the joystick is read using the ADC pins of the SJTwo board. The button switch is detected using a digital pin on the board.

Breakout board layout
Soldered joystick


X values & Mapping Y values & Mapping
2297 (center) 2295 (center)
43 (left) 45 (up)
4095 (right) 4090 (down)

VS1053B MP3 Decoder Interfacing

Label Name Function Pin Connection
1 MP3-DREQ Decoder Data Request Pin 0.1
2 MP3-CS VS1053B Chip Select Pin 0.22
3 MP3-DCS VS1053B Data CS Pin 0.0
4 MP3-RST VS1053 Reset Pin 0.10
5 MOSI SPI Bus (Master Output Slave Input) Pin 0.18
6 MISO SPI Bus (Master Input Slave Output) Pin 0.17
7 SCK SPI Clock Pin 0.15
8 +5V +5V PCB Vout
9 GND GND GND







LED Matrix Interfacing

LED Matrix Interfacing
Start Screen of the game


LED Matrix Pins Connection to SJTwo board
R0 Pin 0.1
G0 Pin 1.1
B0 Pin 1.4
R1 Pin 4.28
B1 Pin 0.6
G1 Pin 0.8
A Pin 1.23
B Pin 1.29
C Pin 2.1
D Pin 2.4
CLK Pin 0.26
STB Pin 1.31
OE Pin 1.20
GND GND


We use a 32x64 LED matrix consisting of 2048 LEDs arranged in 32 rows and 64 columns each, with each led having a separate Red, Green and Blue LED chips assembled together as a single unit. This 32x64 LED matrix comprises of 2 of 16x32 led matrices placed vertically to each other. There are different drivers for controlling the corresponding rows and columns each. In order to illuminate a particular led, one needs to access and control the corresponding row and column (just like in coordinate-axis). To change the color of a particular led, each led must be controlled using the driver for that row and column.

The matrix pixels are controlled by 6 drivers, 3 for the top half of the matrix(R0,G0,B0) and 3 for the bottom half(R1,G1,B1). The three drivers for R, G and B share a SCLK, Latch and OE signal. The top half pixels of the matrix controlled by R0, G0,B0 are rows 0-15 and the second half controlled by R1,G1,B1 are rows 16-31. The display is multiplexed at a duty cycle of 1/16, this means that one row in the top half and one row in the bottom half will be illuminated at a time. In order to display an image, the row and column LEDs for that image must be turned “ON”, therefore, the entire panel must be scanned at a rate(speed) at which it appears that the image is being displayed without flickering. To display different colors and different brightness levels, the LED chips of corresponding row and column must be adjusted by varying the amount and time that each LED chip is turned on during each cycle.

LED Matrix Specifications:

5V regulated power input, 4A max (all LEDs on)

2.1 mm x 2.1 mm LED size

1/16 Scan Rate

Software Design & Implementation

Analog Joystick & Button Device Driver

The ADA512 joystick's device driver works on the principle that the ADC pin on the SJTwo is able to read the X and Y values.

void adc__initialize_alien(void)
{
Turn ON ADC peripheral;
make ADC operational;
set ADC clock;
Set Pin functions;
select ADC channels;
start burst mode;
} 
  
data get_data(adc_channel_e x_port, adc_channel_e y_port, gpio_s button_press) {
data s;
s.x_data = adc__get_adc_value(x_port);
s.y_data = adc__get_adc_value(y_port);
if (gpio__get(button_press)) {
s.switch_pressed = true;
} else {
s.switch_pressed = false;
}
return s;
} 


LED Matrix Device Driver

1. Initialize the LED matrix by configuring necessary pin directions.

2. Disable Output Enable (OE) GPIO before feeding matrix data.

3. Select the required row by setting bits on A, B, C, D GPIO pins.

4. Loop through the pixels (columns) in the selected row and set the pixel color on R, G, B GPIO pins.

5. Set zero on R, G, B GPIO pins to mask that particular pixel.

6. Set and Reset the clock for pushing the R, G, B bits for each column.

7. Issue latch to mark the row's completion and reset latch before going to next row.

8. Follow the steps 2 to 7 for other rows.

for (uint8_t row = 0; row < (MAX_ROW); row++) {
     disableOE();
     set_row(row);
     for (uint8_t col = 0; col < MAX_COL; col++) {
       LPC_GPIO0->PIN |= (1 << CLK);
       set_color_bottom(game_matrix[row + (MAX_ROW / 2)][col]);
       set_color_top(game_matrix[row][col]);
       LPC_GPIO0->PIN &= ~(1 << CLK);
     }
     LPC_GPIO0->PIN |= (1 << LAT);
     enableOE();
     LPC_GPIO0->PIN &= ~(1 << LAT);
     enableOE();
     vTaskDelay(1);
}

Graphics Driver

We have managed to program the graphics in a relatively simple way by looking at the ADAFruit gfx library that comes ready to use with Arduino. Our graphics driver can implement graphics and animations such as letters, numbers, ball appearance and ball disappearance etc.

void place_launcher(LedMatrixDisplay led_display, pixel_color rgb, gfx__cursor start_cursor, bool 
choose_back_frame) {
 
game_event object_property = BACKGROUND_OBJECT;
rgb.event = object_property;
draw_line(led_display, rgb, ROTATION_90, start_cursor, 9, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 0, start_cursor.y + 1, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 0, start_cursor.y + 2, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 1, start_cursor.y + 3, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 2, start_cursor.y + 4, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 3, start_cursor.y + 5, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 4, start_cursor.y + 5, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 5, start_cursor.y + 5, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 6, start_cursor.y + 4, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 7, start_cursor.y + 3, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 8, start_cursor.y + 1, choose_back_frame);
modify_pixel(led_display, rgb, start_cursor.x + 8, start_cursor.y + 2, choose_back_frame);
}
Game Level 1
Game Over Screen

















Testing & Technical Challenges

Describe the challenges of your project. What advice would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to the 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.

Conclusion

This project was a fun and strenuous application of our engineering and project management skills.

After completing the driver labs during CMPE 244, we felt confident that we could develop a driver, for the Adafruit LED matrix, without using any third party libraries. We researched the hardware operations of the LED matrix and how to drive the RGB LED's. Once we could control LED's one at a time, the project evolved from an engineering problem into more of a creative exercise.

Overall I think the biggest lessons that we learned is project management based. We spent a lot of time choosing between various game designs and it forced us to start our final iteration later than we would have liked. However, we bonded together and worked hard and managed to get the game working.


Project Video

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

Project Source Code

References

Acknowledgement

We would like to sincerely thank Professor Preetpal Kang for his allround guidance, feedback and support. His classroom lectures were significant in imparting knowledge on embedded systems. Further, we would like to thank the ISA team for their advice.

References Used