Making a Rock Paper Scissors game with an Arduino compatible device

This summer, I have been working as an intern at a company called Switch Science in Tokyo, Japan. I am writing about my experience here in the form of blog posts, and you can find my first post here.

On Thursday last week, I was given a thermal camera to work with along with my M5Stack. My goal was to connect them together and display the thermal data in the form of a picture on the M5Stack's screen. The thermal camera was called the MLX90640 by Melexis. After briefly reading about it, I was confident that I knew where to connect the wires and which I2C address to use, but I quickly realized that the size of the pins on the thermal camera were too small to connect to the wires' pins. Although I could plug them into each other, the connection would only work properly half of the time. So my coworker Kazunori helped me by cutting the end of the wires and soldering them straight to the camera's pins. It seemed to connect well, and I continued trying to figure out how to display the data from it.

Then, Monday morning, the camera suddenly stopped connecting. I spent a few hours trying to figure this out on my own before I asked Kazu for help. He suggested we try to connect a different camera, but no cigar. We also tried a different Arduino sketch made by a different person, but it also didn't work. Eventually, we tried using a different, brand new M5Stack, and it connected!

But then a few minutes later it stopped connecting again.

Due to this issue having already taken a full work day and being pretty inconsistent, I decided to quit the project and start something new.

On Tuesday, I got to the office wondering what to work on. I opened my backpack to grab my stuff, and saw both my old M5Stack and my new one from Monday. This gave me the idea to make a game involving both M5Stacks. I decided to create a simple Rock Paper Scissors game where players would each select their option on their M5Stack and then the screen would display who won. Truth be told, I was a bit cocky and thought I could finish this project in just one work day, but this was not the case.

I worked with my M5Stack and my computer's serial port in order to simulate the other player's M5Stack because it was easier than continuously uploading new code, unplugging the M5Stack, uploading it to the second M5Stack, unplugging that one, and then plugging them to each other. I'd rather just run it while it was still connected to my computer and then simulate the other M5Stack manually on Arduino's serial port. Therefore, at the end of the day, when I thought my game was working great, I was a bit surprised to see that when I uploaded the code to both devices and played them against each other, it was an absolute mess.

I honestly cannot describe what the error was that prevented my game from working, as I think there were many. I was overwhelmed to say the least, and the next day I was not very motivated to figure this out. I got a bit of work done, but I was tired and it went slowly. At least I got it from looking like a meme of sorts to being coherent, although still not what I wanted. Some values would persist even after the round ended and all variables were supposed to be reset, but nothing was consistent. For example, sometimes you could choose rock, paper, or scissors, and it would tell you if you won or lost without the opponent even picking their choice yet. Other times, the opponent's status would read as "READY" from the beginning of the round (it should only turn to "READY" after the opponent makes their choice), and then when you picked your choice it would just continue saying "READY" instead of revealing the opponent's choice.

Then, this morning, I decided I was going to finish making this game before lunchtime. I did quite a bit of stuff, but by the end, the trick was to make a "value monitor" and add it to my reset function that ran before / after each round.

I was finally able to see that the "oppChoice" integer (if the other player chose rock, paper, or scissors) would continue switching values between your choice and the other players choice after the first round, even when the reset function played. This was because the serial input ("mailbox[0]") kept on reading these values off when it should not have. I was finally able to acknowledge and fix this issue (it would take another few paragraphs to explain, and I'll save you that catastrophe) and the game finally WORKED! (See photo at top of this post.)

I am not saying it is perfect, as the player must hold down their choice for a second for it to register and the results are not well centered, but I will continue to fix these issues and get my project to the best state that it can be in, even if it is just Rock Paper Scissors.

I will continue to post about my internship in the near future! Thanks for sticking around.