Weekly Updates

Week 1 (2/15/2020-2/21/2020)

This week, the parts we ordered have arrived. These peripherals are:

  • Adafruit Neopixel NeoMatrix 8x8 - 64 RGB LED pixel matrix

  • MAX72199CNG LED Matrix/Digit Display Driver

  • Nunchucky (Wii nunchuk breakout adapter)

  • Wii nunchuck

We have collected and read through the data sheets for the respective peripherals, and have figured out how we plan on proceeding with our setup and code. The MAX driver will need 3 GPIO pins, and will be using SPI control to send and receive data. With the driver properly wired to the 8x8 matrix, it will possible to access individual LEDs on the matrix. We have also read tutorials for hooking up the nunchuk, and with the adapter it will just need a VCC connection, GND connection, and a clock and data pin. For the nunchuck controller, one can implement a program that registers when buttons are pressed and, when the joystick is pushed, this program should determine which direction it is pressed.

Our goal for next week is to begin the initialization process for the SPI connection, as well as the UART connection to display messages on the termite window. Given enough time, we may begin to implement the initialization and input detection of the nunchuck controller.

Week 2 (2/22/2020-2/28/2020)

This week, we completed a large portion of the code to initialize the project design, namely for the UART and the Wii nunchuck. We managed to initialize the UART interface to output messages upon the detection of user input. We also initialized the Wii nunchuck in I2C such that it can detect the direction in which the joystick is pushed. Finally, we initialized the two nunchuck buttons, Z and C, such that the STM32 detects when either button is pressed. The UART was used as a display to show which button is pressed and in which direction the joystick is pushed, with four directions detected: up, down, left, and right.

For next week, we plan to initialize the SPI connection to the LED matrix and write the code to light up the LEDs and randomize the values of each index of the matrix. If time provides we will also begin the design of the minesweeper initial game state. We have also realized that the MAX7219 driver is used for a different type of LED matrix than the one we have, specifically matrixes with 8 data lines. Ours has just one data line, so it will not require the use of the MAX7219.



Week 3 (2/29/2020-3/06/2020)

This week, we created the function that generates an 8x8 matrix representing the game state. The function creates a matrix where each index contains a number from 0-8 or 10. A value of 10 represents that the spot contains a bomb. A value of 0 represents that it does not contain a bomb and is more than one index in any direction away from the nearest bomb. Any number from 1-8 represents the number of bombs that the index borders within a 3x3 square surrounding it. To generate the matrix, we used the built in RNG registers on the stm32 to generate random values, and if a certain number was generated a bomb would be placed at that location. This was continued in a while loop until all the bombs were assigned. When all the bombs are assigned, the function calculates the number of neighboring bombs for every other index and assigns that value to the index.

In the game, all values in the matrix are "hidden" in the beginning unless the player selects them or they are revealed by another index. We created the function that, when an index of the matrix is selected, reveals the value of the index. If it reveals a 10 (a bomb), every other index containing a bomb is also revealed in an "explosion". If it reveals a 0 (a blank spot), and if there are other 0's bordering it, they are all revealed, as are all bordering indices of revealed blank spots. If there is a single index with value 0, and no surrounding ones are 0's, then selecting it reveals a 3x3 square with a center of 0 surrounded by values of 1-8. Likewise, if there is a cluster of 0's, then selecting one will reveal all of them as well as the values of surrounding indices. Otherwise, if a value of 1-8 is selected, then only it is revealed. This was implemented using a recursive function which checks an index then recursively calls the function on the corresponding neighboring indexes following these guidelines.

We also created a cursor structure, which consists of a location (x,y) on the matrix. The wii nunchuk can move this cursor using its joystick. This allows the player to move the cursor and select a spot on the "minefield" (the matrix), reveal whether it contains a bomb (a value of 10) or is clear (contains any other value), and determine how many bombs are nearby to continue clearing the field.

Finally, we wrote code to allow the player to flag suspected bomb spots. When a spot is known or suspected to be a bomb, a flag can be placed on it that marks it as safe and prevents the player from revealing it unless they remove the flag. This feature, alongside the reveal feature, is coded into the two buttons of the Wii nunchuck C and Z respectively. When C is selected, a flag is toggled onto the spot the cursor is currently on. When Z is selected, the value of the spot is revealed, unless there is a flag on it.

For next week, we plan to create the code that applies the matrix to the actual LED matrix, including defining the colors that represent different numbers or hidden spots. We also plan to implement the code that displays the results of the game on the UART display.

Week 4 (3/07/2020-3/13/2020)

This week, we modified the project significantly. It became clear that the Neopixel LED matrix could not be used as originally intended using an STM32 device, as it is designed for Arduino and is intended to be used with its own Adafruit C++ library, not using STM32 C code. This library is incompatible with the STM32, and we were unable to get the game matrix to load onto the LED matrix manually. We extensively read through the Arduino code but it was written in assembly code and not able to be translated to C code for the STM32. Therefore, we have modified the project to not use the LED matrix as the game board itself. The LED matrix has instead been made into a "progress bar" in which the LED's are progressively lit up as spots not containing bombs are uncovered. This allows us to still use the LED matrix as a productive tool even if not as the game board.

The game board itself printed onto the Termite terminal using UART instead as an 8x8 matrix. Default unrevealed spots are represented as "_", flags are represented as "F", and the cursor is represented as "X". Numbered and blank spots are still simply represented by their respective numbers. When the player moves the joystick on the Wii nunchuck, the matrix is updated to represent where the cursor has moved to. If they press a button, the matrix is updated to represent all of the spots that have been revealed, including previously revealed ones. In order to keep the UART display clean, each time there is an update to the game state, a series of newlines are printed to remove the previous iterations and display only the current one. Prior iterations can still be accessed by scrolling up. The game is fully playable and the nunchuk works very effectively. We have completed the game and just need to tidy up the code and make some UI changes for the player. The project uses UART and I2C for the game interface and nunchuk respectively.

Project Development Photos

Week 2: Nunchuk inputs displayed on the termite terminal via UART

Week 3: Sample matrix of two games of Minesweeper where 10 represents a bomb and 0-8 represents the number of bombs bordering that spot