This week I created a physical joystick for Ball Drop Game , originated by Tom Igeo, using Arduino Nano IOT33. In this assignment, I tried to understand how the server works with clients using WIFI connection. The main library I used is WiFi Nina. During writing the sketch, I found a lot of difficulty and challenging. Here are several sketches I made before the final version.
In this sketch, I try to follow and adapt the code from Tom's example(BallDropWifiJoystickClient). I can connect to the server but there were a lot of delays when I push any button. Sometimes, It seems like nothing happens in the server at all, but the result always show in the console of Arduino. And the main problem I found is I cannot reconnect to the server or sign out from the server in a consistent way.
This time I found my friends Tito posed his finished assignment on Instagram. I followed into his blog and tried to learn from his code. It was very useful. From his sketch, I got two logic that very essential. The first one is setting the Wifi status as a state using String. From this logic, I can check and change the wifi and server status as I want and it can solve the problem that I can not reconnect the server from the last sketch. The second logic is setting state for button by comparing the new and old status of the button. This somehow speeds up the connection between device and server.
In this final sketch, I adjusted the code from the sketch I mostly borrowed the code from Tito. First, I reduce some steps to help me understand the code easier. The main thing I adjust is changing from using String to define button status, represented the status with boolean instead. I'm not sure whether it helps speed up the connection. At least it's helping me to understand the code in my own way.
Here the video for and interaction
For the Devices, I decided to use a basic push button as an input because it's not complicated to code and easy to find. For the enclosure, I use basic foam board to make the breadboard can be held easily.
After finishing this first assignment, I feel very proud of myself for being able to finish this by myself and trying to understand the logic behind the coding and networking.