An esp32 pong multiplayer game using the ESP-NOW protocol
I used AI to translate the code from python to java script, because I donāt know java script, and also to help me make the CSS.
An esp32 pong multiplayer game using the ESP-NOW protocol
I used AI to translate the code from python to java script, because I donāt know java script, and also to help me make the CSS.
Iāve created a wireless Pong game that works without Wi-Fi by connecting two ESP32s using the ESP-NOW protocol.
The biggest challenge was overcoming input lag. I fixed it by making one ESP32 the āMasterā that processes all the logic, while the other acts as a āSlaveā that just receives data.
This was my first time using MicroPython and my first hardware project based on Python. Iām really proud of how it turned out because ESP-NOW isnāt commonly used, but itās a super efficient way to communicate between devices. I definitely plan to use it again soon!
Iāve finished the website where you can see how it works. I didnāt know I needed to make a website to show how it works, this discourages me from making more hardware projects. My next project will be an app. The hardest thing about this project was the CSS because I have almost never used it. Luckily, I just had to make squares and text. At first, I wanted to draw the cables, but I gave up because I couldnāt figure out how to do it, so I added a button where you can see the schematics. This project helped me learn the ESP-NOW protocol, which I plan to use in future projects. All the documentation is on GitHub, so anyone can replicate it or improve it. It also helped me learn MicroPython, which was much easier for me than C++ in Arduino IDE.
Log in to leave a comment
I realized that I need to create a way for people to experience it, so Iām building a website that simulates the project. I donāt know anything about CSS or HTML, so Iām sure this will take a long time since Iām starting from scratch. Iāve been trying to make a website where you can interact with it and see how it works.
THE PROJECT IS FINISHED!
Today at school I tested the game by asking a friend to go as far as he could to see the maximum distance. It worked, but sometimes it lagged when there was a lot of distance and walls in between.
Iāve completed the README so now anyone can follow the project. Itās my first time writing a README, so if something isnāt clear, let me know. Iāll publish the project and, in the future, Iāll probably improve some things, like making the game more complex or building a case for it. For now itās functional.
This project made me realize the potential the ESP-NOW protocol has, and I already have ideas for what to build next.
Check out the video to see how it works.
The problem was easier than I initially thought. I simply had to add the function that draws the players directly into the actual library, SSD1306 (as shown in the first picture). Once I added this function, the game improved significantly, but it still didnāt work perfectly it had a small amount of lag.
The solution was to increase the I2C speed to 1 MHz; before, it was running at 400 kHz. After this change, the game now works perfectly without any noticeable lag, and it can be played anywhere.
Next, I will focus on writing the README and creating the actual circuit schematics, a step I probably should have done earlier.
Log in to leave a comment
I have finished the logic, i had already the game done i just had to implement the button logic. The problem I have had is that this code is funcional but having to iterate to draw the character uses a lot of resources so on one screee it works well and on the other it lags, I iterate because I know I canāt use the drawing functions of the library because for some reason in python they do not work and only work in c++ I could take my code and tell an ai to translate it from python to c++ but that is not the goal because I would not understand anything since I do not know c++, I will try to fix it but if it does not work I will have no choice but to pass the code to c++ for now micropython is not working properly for me.
Log in to leave a comment
Before starting the game logic, I wanted the esp32 to run without being connected to the computer, the code was not running as it should. What I did to fix it was just rename the files to main, the problem was that the esp32 was not executing the code because it was not named main.py. Now the code runs perfectly, so now you can play without being in the same room, once was done with that I could start with the actual game
Log in to leave a comment
During these first 25 minutes, I was trying to communicate the two ESP32s. On both screens, I put a text that says āReleasedā or āPressedā, if a button is pressed, it should be shown on both screens. I decided that one ESP32 will run the game logic and send the data to the other to avoid lag and prevent desync issues.
The first problem I had to fix was that the main ESP32 was sending its button info and the other was receiving it, but not the other way around. I read the code and found that the problem was a logic error, the screen was being cleared just a millisecond after receiving the input, so the text didnāt show even if the button was pressed. Once I fixed the logic, it still didnāt work because the buttons werenāt connected to the pins I intended to use, so that was probably the main problem at the beginning. Now I just have to implement the button logic the the game logic. The most difficult part will be sending the thata, I hope itās easier than I think.
Log in to leave a comment