Intangible Interactions Week 8
Using Arduino to access APIs (or not)

I was originally excited to use the Arduino as Wi-Fi and HTTP client, connecting to the internet just like any other computing device and interacting with some cool APIs. However, the sample code never was able to connect to the Wi-Fi router!

It turns out that the router in my apartment is only supplying a 5GHz network, and the Arduino's Wi-Fi module only works with 2.4GHz networks. The router is not mine, so I didn't want to reconfigure it. Time for another plan…

Using Arduino as a Wi-Fi AP
Idea and demo

Instead I used the Arduino as a Wi-Fi access point and HTTP server, and used it to serve a small game:

To play, the player first taps a hole for the rabbit to hide the carrots in. Then, the player must tape the same hole to retrieve the carrots. This is a trivial task and obviously should be expanded on to make an interesting game. However, even it its current state:

  • It could be a fun game for small children to teach them object permanence.
  • It could be a fun game for inebriated people to teach them object permanence.
  • Multiple people can connect to the server at the same time to cause a lot of chaos.
  • It can be used as a memory game, or a habit-forming aid, if the player allows for a long time between placing the carrot and retrieving the carrot.

The game is simple, but I made sure it was complex enough to require the server to store game state ✨ to prevent cheating ✨ since the stakes in this game are very high.

Process

To create the game, I mentally mapped out the game's possible states. Some of the states would be only directly accessible to the server, and some were ok to show the client. I had the server store whether the carrot was stored in a hole, and, if so, which hole. All the remaining aspects of the state were fairly transient, and could be stored in the URL or in a meta refresh tag to indicate the state to advance to after a 2-second delay.

This is a simplified state diagram, not showing the states corresponding to which hole the carrot was stored in, and the hole the player decided to look at.

To prototype the code, I made a client-only version that uses only JS and doesn't interact with a server. (The Arduino version of the game also doesn't use JavaScript at all!) Both versions of the game look exactly the same.

Play the JS version of the game here.

Arduino code — run on your own Arduino!