We aimed to recreate the game Beat Saber for our ELEC 327 final project. This website showcases the work we did.
So, what exactly were we doing?
Beat Saber is a VR rhythm game. In Beat Saber, the player listens to a song while holding two lightsaber-esque objects. As the song plays, shiny cubes approach the player to the rhythm of the song. The player's goal is to strike the cubes accurately and with good timing, so that they can score points and do well on the song.
What we tried to do was recreate a game like Beat Saber. We wanted to include all of the functionality of the game, covering the player's experience of everything between them starting up and leaving a play session. In particular, we aimed to cover these key areas:
With our design goals laid out, we then needed to make plans for how we would reach them and what tools we would use to implement the game with. This section will go over these topics.
The first thing we thought about was the hardware with which we were going to implement the game. Our plan was to use the following hardware:
So that we could better understand the game and isolate the game logic before having to worry about resource constraints, one of the first things we planned to do was write a version of the game that could be played from within Terminal on a laptop.
With our goals in mind, we then started to implement the plan. This section will describe what we did for that purpose.
The first step was to simulate the game on a laptop to learn how the game works and realize what challenges we would face in implementing a game like Beat Saber. The game was written in around 700 lines of C. Below is a demo of what the gameplay looks like:
We designed our two-layer PCB using the aforementioned parts. Below is our final design:
The system is powered through a 5V barrel jack (the barrel jack port is at the bottom left), which feeds into a 5V-3.3V DC-DC converter at the top left. The 5V rail delivers power to the power-hungry LED array as well as our speaker amplification circuit. The 3.3V rail can be accessed via the left side pins and is responsible for powering our sound board, our accelerometers, and our MSPM0+ microprocessor. Since all devices sit on the same ground, we can simply use the MSPM0+ pins directly for interfacing with all of our devices, for which purpose we have all the header pins at the top right.
To make the joysticks for the game, we 3D-printed enclosures for our accelerometers. Below is the
design for our joysticks:
Once our PCB arrived and all of our parts were in hand, the next step was to assemble everything. Below is what the final setup looks like:
We had to figure out how to communicate with the LED array and accelerometer peripherals. The LED array uses a protocol called WS2812b, which isn't natively supported by MSPM0 microcontrollers. The protocol involves sampling data signals within a certain period, and determining 1 or 0 based on whether the data was held high or held low for longer. Below is a relevant visual for the protocol:
We were pleased to find that this protocol can be mimicked with SPI, by sending 110 to indicate a 1 bit and 100 to indicate a zero bit. In this way we were able to interface with our LED array.
As for our accelerometers, we used I2C for communications. We were unsuccessful in giving each accelerometer its own I2C channel on the MSPM0, which would have been the preferred way to get both accelerometers working. A workaround we tried was to put the data and clock pins from both accelerometers in parallel on the same I2C channel, and use GPIO to alternate which accelerometer is powered on. This experiment was somewhat successful in that we were able to get readings from both accelerometers using only one channel, but was often laggy and inconsistent, so was dropped from the final game. We ultimately ended up using one accelerometer to play the game, tilting left to hit notes in the left channel and tilting right to hit notes in the right channel.
After we assembled and tested everything, we were ready to play the game. Here is what our game looks like:
Overall, our project was fun and educational. We learned a huge amount about PCB design, microcontroller programming, C, various communication protocols, and how to implement custom hardware solutions to real world problems.