Difference between revisions of "F24: Ball Balancing Game"
Proj user11 (talk | contribs) |
Proj user11 (talk | contribs) (→Administrative Responsibilities) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 53: | Line 53: | ||
|- | |- | ||
! style="text-align: left;" | | ! style="text-align: left;" | | ||
− | * | + | * Resitive Table Driver |
| Chaitanya Battula | | Chaitanya Battula | ||
|- | |- | ||
Line 62: | Line 62: | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== '''Schedule''' == | == '''Schedule''' == | ||
Line 225: | Line 202: | ||
|- | |- | ||
− | + | * Resistive Pad Power Module and Dc female power jack | |
| | | | ||
* [https://www.adafruit.com/product/2279?gclid=CjwKCAiA9qKbBhAzEiwAS4yeDYSKVkDu50XPdtCaJTeRJYj02YJb-ABAjVX1WBGGtEr2jHvQRfvufhoCA-QQAvD_BwE 64x32 RGB LED Matrix Panel] | * [https://www.adafruit.com/product/2279?gclid=CjwKCAiA9qKbBhAzEiwAS4yeDYSKVkDu50XPdtCaJTeRJYj02YJb-ABAjVX1WBGGtEr2jHvQRfvufhoCA-QQAvD_BwE 64x32 RGB LED Matrix Panel] | ||
Line 231: | Line 208: | ||
* 1 | * 1 | ||
| | | | ||
− | * | + | * |
|- | |- | ||
| | | | ||
− | * | + | * Power Module and Dc female power jack |
| | | | ||
* [https://www.adafruit.com/product/2279?gclid=CjwKCAiA9qKbBhAzEiwAS4yeDYSKVkDu50XPdtCaJTeRJYj02YJb-ABAjVX1WBGGtEr2jHvQRfvufhoCA-QQAvD_BwE 64x32 RGB LED Matrix Panel] | * [https://www.adafruit.com/product/2279?gclid=CjwKCAiA9qKbBhAzEiwAS4yeDYSKVkDu50XPdtCaJTeRJYj02YJb-ABAjVX1WBGGtEr2jHvQRfvufhoCA-QQAvD_BwE 64x32 RGB LED Matrix Panel] | ||
Line 241: | Line 218: | ||
* 1 | * 1 | ||
| | | | ||
− | * | + | * |
|- | |- | ||
Line 254: | Line 231: | ||
|- | |- | ||
| | | | ||
− | * | + | * Servo Motors |
| | | | ||
* [https://www.amazon.com/gp/product/B08NB8S42K/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 IDC Socket Male] | * [https://www.amazon.com/gp/product/B08NB8S42K/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 IDC Socket Male] | ||
Line 263: | Line 240: | ||
|- | |- | ||
| | | | ||
− | * HC-05 Bluetooth | + | * Steel Balls (5 pack) |
+ | | | ||
+ | * [https://www.amazon.com/DSD-TECH-HC-05-Pass-through-Communication/dp/B01G9KSAF6/ref=mp_s_a_1_3?adgrpid=57552031393&dplnkId=fa65647f-fc92-41f1-a50c-4ac9bfec67f3&gclid=Cj0KCQiAmaibBhCAARIsAKUlaKSJHxYgLW7SP5wMd94uqHWtJ7IlGGyw2zsTxZFHoU3KT5dqm0vMzJcaAjntEALw_wcB&hvadid=609115864507&hvdev=m&hvlocphy=9032166&hvnetw=g&hvqmt=e&hvrand=14587583350658056883&hvtargid=kwd-298511473808&hydadcr=20105_13388467&keywords=hc+05+bluetooth+module&nodl=1&qid=1667939624&sr=8-3 HC-05 Bluetooth] | ||
+ | | | ||
+ | * 2 | ||
+ | | | ||
+ | * 10 | ||
+ | |- | ||
+ | | | ||
+ | * MP3 Decoder | ||
| | | | ||
* [https://www.amazon.com/DSD-TECH-HC-05-Pass-through-Communication/dp/B01G9KSAF6/ref=mp_s_a_1_3?adgrpid=57552031393&dplnkId=fa65647f-fc92-41f1-a50c-4ac9bfec67f3&gclid=Cj0KCQiAmaibBhCAARIsAKUlaKSJHxYgLW7SP5wMd94uqHWtJ7IlGGyw2zsTxZFHoU3KT5dqm0vMzJcaAjntEALw_wcB&hvadid=609115864507&hvdev=m&hvlocphy=9032166&hvnetw=g&hvqmt=e&hvrand=14587583350658056883&hvtargid=kwd-298511473808&hydadcr=20105_13388467&keywords=hc+05+bluetooth+module&nodl=1&qid=1667939624&sr=8-3 HC-05 Bluetooth] | * [https://www.amazon.com/DSD-TECH-HC-05-Pass-through-Communication/dp/B01G9KSAF6/ref=mp_s_a_1_3?adgrpid=57552031393&dplnkId=fa65647f-fc92-41f1-a50c-4ac9bfec67f3&gclid=Cj0KCQiAmaibBhCAARIsAKUlaKSJHxYgLW7SP5wMd94uqHWtJ7IlGGyw2zsTxZFHoU3KT5dqm0vMzJcaAjntEALw_wcB&hvadid=609115864507&hvdev=m&hvlocphy=9032166&hvnetw=g&hvqmt=e&hvrand=14587583350658056883&hvtargid=kwd-298511473808&hydadcr=20105_13388467&keywords=hc+05+bluetooth+module&nodl=1&qid=1667939624&sr=8-3 HC-05 Bluetooth] | ||
Line 355: | Line 341: | ||
| scope="row" align="center"|R1 | | scope="row" align="center"|R1 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P1_14 |
|- | |- | ||
| scope="row" align="center"|G1 | | scope="row" align="center"|G1 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P4_29 |
|- | |- | ||
| scope="row" align="center"|B1 | | scope="row" align="center"|B1 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P0_7 |
|- | |- | ||
| scope="row" align="center"|R2 | | scope="row" align="center"|R2 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P0_9 |
|- | |- | ||
| scope="row" align="center"|G2 | | scope="row" align="center"|G2 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P0_25 |
|- | |- | ||
| scope="row" align="center"|B2 | | scope="row" align="center"|B2 | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P1_30 |
|- | |- | ||
| scope="row" align="center"|A | | scope="row" align="center"|A | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P1_23 |
|- | |- | ||
| scope="row" align="center"|B | | scope="row" align="center"|B | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P1_29 |
|- | |- | ||
| scope="row" align="center"|C | | scope="row" align="center"|C | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P2_4 |
|- | |- | ||
| scope="row" align="center"|D | | scope="row" align="center"|D | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P2_6 |
|- | |- | ||
| scope="row" align="center"|CLK | | scope="row" align="center"|CLK | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P2_8 |
|- | |- | ||
| scope="row" align="center"|LAT | | scope="row" align="center"|LAT | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P0_17 |
|- | |- | ||
| scope="row" align="center"|OE | | scope="row" align="center"|OE | ||
| scope="row" align="center"|GPIO | | scope="row" align="center"|GPIO | ||
− | | scope="row" align="center"| | + | | scope="row" align="center"|P0_16 |
|- | |- | ||
| scope="row" align="center"|VCC | | scope="row" align="center"|VCC |
Revision as of 08:43, 20 December 2024
Contents
Ball Balancing Game
Abstract
The project aims to create an interactive game where players balance a physical ball on a table by manipulating its tilt with a joystick. The setup involves servo motors that adjust the table's angle in response to joystick movements, striving to prevent the ball from rolling off the edges. The game's interface features an LED matrix display that visualizes the ball's real-time position and provides dynamic feedback through score tracking, a game timer, and animations for various game states such as winning or losing.
Key components include a joystick module, servo motors, and an LED matrix display, alongside a ball, tilt platform, power supply, and a resistive touch screen for enhanced interaction. The system is powered by an SJ2 microcontroller, which coordinates the input from the joystick and the output to the servo motors, ensuring responsive and precise control. This setup challenges players with increasing levels of difficulty, marked by heightened joystick sensitivity.
Objectives & Introduction
Technical Responsibilities
Technical Roles | ||||
---|---|---|---|---|
|
Faaris Khilji,
Chaitanya Battula, Sneha Odugoudar | |||
|
Sneha Odugoudar | |||
|
Faaris Khilji | |||
|
Sneha Odugoudar | |||
|
Chaitanya Battula | |||
|
Faaris Khilji |
Schedule
Week# | Start Date | End Date | Task | Status |
---|---|---|---|---|
1 |
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
4 |
|
|
|
|
5 |
|
|
|
|
6 |
|
|
|
|
7 |
|
|
|
|
8 |
|
|
|
|
Bill of Materials (General Parts)
Part Name | Part Model & Source | Quantity | Cost Per Unit (USD) |
---|---|---|---|
|
|
|
|
|
|
| |
|
| ||
|
|
| |
|
|
| |
|
|
| |
|
|
| |
|
|
| |
|
|
|
Overall Design
Hardware Design
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.
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:
|
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:
|
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:
|
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 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
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
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
- 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
- 1. LPC40xx_FreeRtos Github: https://gitlab.com/sjtwo-c-dev/sjtwo-c
- 2. FreeRTOS: https://www.freertos.org/a00116.html