Beat Saber Project

We aimed to recreate the game Beat Saber for our ELEC 327 final project. This website showcases the work we did.

Overview

So, what exactly were we doing?

Context

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.

Beat Saber Gameplay Gif

Goals

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:

Welcome Screen:
The player sees a welcome message, and can give any input to proceed
Song Select:
The player is greeted with a catalog of playable songs which they can scroll through and hear.
In Game:
A song plays, and notes approach the player in sync with the song. The player must move their controller at the time the notes enter the strike zone to score points and accumulate combo.
Report Screen:
The player sees their accuracy, maximum combo, and overall performance. The player can go back to song select or leave the game.
Exit Screen:
The player leaves the game, seeing a warm exit message on their way out.

Planning

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.

Parts Needed

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:

  1. MSPM0G3507xDGS28 (x1): This 28-pin microcontroller was selected to be the core of the project.
  2. HJHX 2220 32x8 WS2812B LED Array (x1): This LED strip was selected to be the display for our game, showing notes coming down while a song plays.
  3. Adafruit 2220 FX Sound Board (x1): This IC was selected to store and play the songs of the game.
  4. LSM303AGR (x2): These accelerometers were selected to measure user motion. We put these in 3D-printed joysticks to make controllers for the game.
  5. Traco Power TES 1-0510 (x1): We selected this 1-Watt DC-DC converter to convert 5V to 3.3V, as most of our components use 3.3V.
  6. Speakers (x2): We needed speakers so that the player could hear songs.
  7. Buttons (x6): We wanted several buttons for our PCB as well.

Simulation Design

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.

Implementation

With our goals in mind, we then started to implement the plan. This section will describe what we did for that purpose.

Laptop Simulation

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:

PCB Design

We designed our two-layer PCB using the aforementioned parts. Below is our final design:

PCB Render

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.

3D Printing

To make the joysticks for the game, we 3D-printed enclosures for our accelerometers. Below is the design for our joysticks: Schematic

Assembly

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:

Everything Assembled

Communication Protocols

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:

Visual of WS2812b 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.

Demo

After we assembled and tested everything, we were ready to play the game. Here is what our game looks like:

Conclusion

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.