Close

The few more steps and the end result

A project log for The analog joystick adventure

Taking the analog joystick into the digital world

talofer99talofer99 05/25/2021 at 20:450 Comments

At the end of the previse part, I told you I got some crazy idea of using esp. and html for a game – so apparently It was not that crazy – and it works.

using the VR valentine game by the IOT Makers Israel team I made adjustments to use the joystick https://dev.to/azure/how-to-build-a-w...

The game is based on a-frame which is a JavaScript framework for VR and 3D powered by the three.js library.
The game is served from an ESP8266 and there is a web socket open between the 2, and each change in the joystick is sent as a web socket message to the game.

off course it all just didn’t happen in one go, there were steps.

My first step was to set a web server sketch on the esp, that included events, which are a bit similar to socket, but short messages and only from the server to the page.
The next step was to connect the joystick buttons, if you want to know how to buttons work, you can watch it all in the first episode

once the buttons where connected I added the small joystick to control the direction of the camera. The next big thing, which took me the longest, was to figure out how to imitate the click of the mouse which in the original game is how you collect the hearts - so I can use the front trigger joy stick button instead.
I had to dig into the library itself and look how it was done in the courser section, and it’s all down to the canvas object with in the scene object.

As all of you probably know, the esp8266 has only one analog and this is why only the joystick Y-axis is working. On top of that, it seems that reading the analog slowed down the web service of the esp dramatically.
After I was done getting everything to work, the event service was not working well, and kept on disconnecting, and was replace with a web sockets. I still get some errors, but its way more stable this way.

My next big task will be to find the right analog multiplexer, I did ordered a few that were recommended to me. Hoping to get better results than when the esp is doing the analog read.
And I can always go with the known mcp3008.



And the progress on this stage is on this video 

At the end of the previse part, I mentioned adding an analog multiplexer, so we can read more than one analog input from the joystick. I choose 3 options, when ended up using the CD4051, which is an eight channel analog multiplexer.
In the video I cove the data sheet of the IC.
Starting with its functional Diagrams, showing the truth table used to set the input channel.
Through the IC pinout and pin uses.
I first run a test on Arduino uno, to make it easier.
Then move the setup to the esp and in the end adjust the code of the game, so I can use the joystick to move in space both x & y.
I defiantly need to solder the setup, it’s a wire madness.

And I want a better game that fit the joystick.
The demo was a great start But it’s time to create something new

Here is the video of this 



In this video – the analog joystick gets upgraded to BLE using esp32.




I wanted the esp to host the game using a web server but couldn’t find the time to make the game more interesting and playable. Some comments on the previous video suggested an interface for a computer, either USB or BLE. And I decided I will try the BLE first – this way I can play on any device. 

You can see me in the background trying a nice web flight simulator that support joystick. The esp32 is powered by a battery that is inside the 3d printed box.
https://www.geo-fs.com/geofs.php

I take you through the process I made to move to esp32, added some features and printed a 3d case for it.
I show the assembly process, and go over the code used for it.
The libraries I used for the BLE game pad is https://github.com/lemmingDev/ESP32-B...

And the MCP is https://github.com/adafruit/Adafruit_...

Discussions