Intro:
When deciding on a final project, all the team members agreed to do something with LEDs. The question was what did we want to do with them? Originally we wanted to simply use WS2812 LEDs to make cool color patterns. However, project requirements required us to use I2C communications between components. Due to the requirements, we decided to use an LED matrix that is controlled through I2C instead. From there, we started brainstorming and the topic of making a snake game was brought up. All the members in the group liked the idea of making a hand held game through with the LEDs and a joystick, and there is no better game for that than snake! And thus, "Snek" was born.
Block Diagram:The theory of operation for this project is to take in inputs from a joystick using analog to digital conversion on the MSP to read direction controls. These values are then used to control the virtual snake accordingly. The digital input button of the joystick will also be used to start the game from a start screen or a death screen.
With the actual game itself we planned on updating the snake position and apple position using a clock and updating that to the screen via a graphics driver.
Joystick:
The joystick works by implementing two potentiometers. Therefore, moving the joystick changes the resistance values accordingly, creating different voltage values for analog reading. To read these values, we had to write an ADC driver file that interprets the position of the thumb-stick. To do this we simply took the raw x and y position from the joystick breakout board and mapped the values to 4 different directions: Up, Down, Left, and Right.
Matrix:
The LED matrix is controlled using I2C communication. Therefore, we wrote an I2C driver that can communicate to the matrix and specifies which LEDs need to be turned on/off. Our graphics driver is used to specify which LEDs need to be lit depending on the joysticks input.
MSP Pin Map:The table above shows the physical hardware connections we made between our breakout boards (LED matrix and Joystick) and the MSP432 controller. The pins on the left are the output/input pins associated with the MSP, while the right table describes the pins functionality for our overall board/shield interface.
Wiring Diagram:The main chunk of this project was dedicated to software testing. It required lots of patience and practice with Texas Instruments' Code Composer Studio and c programming. However, we did test our LED Matrix with default Arduino code to ensure the matrix worked ahead of time, as well as, test the ability to read ADC values with the MSP from the joystick. Again, this allowed us to validate the functionality of the component before designing a finalized custom PCB shield.
Designing the PCB:The first step in designing a PCB is creating a schematic. A schematic can be thought of as a map of how all of our components are connected. The picture above is a screenshot of our MSP432 shield PCB schematic. It includes 2 sets of pin headers for plugging our shield into the back of the MSP, 5 through holes for the joystick we intend to use as our controller, and 4 through holes for the LED matrix that will be used to display our “Snake” game. Also included, is the PCA9306 voltage converter that is used to translate our SCL and SDA lines back and forth from 3.3V and 5V in order to effectively communicate between the MSP and LED matrix. There are multiple resistors throughout the schematic that help regulate voltage and prevent shorts. We added pullup resistors for the I2C lines on the 5V side of the converter and plan to configure the MSP internal pullups for the 3.3V side coming from the MSP.
After designing and wiring up our schematic, the next step in PCB design is to layout the physical PCB. This means placing the footprints of every part where you want them and making sure dimensions are correct. Above is a photo of the PCB layout generated from our schematic with the routing completed. It is crucial that the dimensions for the pin headers are the same as the female headers on the back of the MSP or else the PCB shield will not fit in the back of the MSP.
Once the layout of the PCB was finalized and correct, the PCB gerber files were sent to a fabrication house and manufactured. Above is a photo of the manufactured PCB without soldered components.
The last step in PCB design is assembly. We spent a few hours in the lab soldering the pin headers, logic converter, LED matrix, Joystick, resistors and capacitors onto the board. Once these components were soldered we could plug the shield into the MSP432 and start running code. Above is a photo of our completed shield connected to the MSP and another photo showing our death screen animation.
Challenges:The main challenges that our project encountered was on the software end of things. Specifically our main problem was i2c communications. Simply setting up the communications was tough to do. We made our driver file for the i2c communication, however upon launch we were not able to communicate with the board. After looking back at the code and making tweaks, we were still unsuccessful in establishing communications. So, what we decided to do was leverage the class provided i2c driver and then edit it to our needs. From there, we were able to establish communications and a photo of the pattern displayed is shown below.
Overall, the project was a success. We were able to create a working snake game on the LED matrix. However, that doesn't mean that our project was perfect, there was a significant bug that need to be fixed. The main bug had to do with the joystick. When trying to play the game, the inputs to the joystick aren't always taken in by the game, making the game a little laggy. T
his is likely due to the range we set for user inputs and the ADC clock. If we adjust those two values we will most likely have much better response from the system. Other than that, there are a few other small bugs that will be addressed alongside that of the joystick.
Comments