Close
0%
0%

The analog joystick adventure

Taking the analog joystick into the digital world

Similar projects worth following
118 views
0 followers
Back in the early 90’s if you had one of this bad boys, you were envied by your friends .
I love retro stuff, and this was given to me by a friend (thanks Tamir) few weeks back.
I was busy with the rotary phone project and I finally got some time to handle this in the last 2 days.
I took it a part and found how all works.
I did struggle with the analog and there is going to be some learning and hacking here – but it’s going to be fun and tons of learning.

I really like retro things, and this joystick brings back memories.
I do love to learn how things work, so taking it apart was the first step. 

The buttons are considerably easy to handle and they are using the 4 output of the buttons with sets of binary representation. you can see the LED in the youtube thumb.

The analog are a different story and I will need to imitate the old mono stable mechanism with a 555 - so that will be fun and a great video.

I do no have an end result yet, got few Ideas, will post updates. 

  • 1 × arduino mega
  • 1 × Flight stick - analog joystick
  • 1 × GLCD Switches and Relays / Switches

  • The analog joystick adventure – part III – let’s play a game

    talofer9903/22/2020 at 00:53 0 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-webvr-game-with-a-frame-4ifg

    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.




    I need to work out a game worthy of the joystick. So if you got ideas, or want to help out, please feel free to drop me a line in the comments and if you haven’t done it by now, please subscribe or give a thumbs up and see you next time.


  • I got it centered

    talofer9902/25/2020 at 08:56 0 comments

    After many adventures I finally manged to get a proper readings from the analog. 

    at first I tried to work it out using a 555 IC in monostable configuration and to read the result using the pulsein command.

    My first big task was to find the right circuit, I had one major hardware limitation, and that is the 100K vcc connected potentiometer.

    The second most important limitation I had was that I wanted the total of both the High and Low period to be as short and possible, yet leaving me enough scale on the High part.

    After searching and few trials and errors, I ended up with this circuit.

    Down there between the wires there is a 555 IC, one of the oldest most used IC till today. The setup is monostable, and the output is red by the Arduino using the pulsein command.

    What you are seeing in the serial monitor is the pulsein result of both the High and Low square wave length of time in microseconds. The potentiometer, valued at 100K ohm, will control the length of the HIGH period. As you can see when I move it, the High period changes. Running from 6 to about 50, which gives more than enough scale to work with. 

    After running the test with a potentiometer it was time to connect the joy stick and see if I get proper results.

    Now at this stage I was getting unstable reads, mainly from the scroller on the side.

    After a conversation with my friend Ofer, that pointed out that the 555 and analog are both using a voltage divider and why won’t I go back to analog. I did. I first took an 100K ohm resistor and working with voltage dividing formula to calculate the value of the variant resistor I was able to get some reasonable values. Link for this post in the description. Out of this value I could see the possibility of calculate, at some accuracy, what is the position of the x & y of the joystick. Now that worked well with the x & y, but when tested on the side scroller, I find it to get thrown out of balance at the edge of the scroller

    My first guess was that unlike the x&y this one seem to have to full range of the potentiometer and its due to the none linear change in resistance.

    I added another 100K ohm resistor, so the diving id done between 100K to 100K + potentiometer resistance value. It gave much better result across the board. The last step was to decide what will be the edges of all the x& y in value, I add to trim thing up a bit, 


    I still have to deiced what to do with it now, I originally thought of moving some thing physically,  but in the last few days I'm thinking of maybe using esp and serve a html game out of it, using the joystick as the game controller. 

    This is how the setting file in the video looks like 

    #define BUT_TRIGGER 14 //1110
    #define BUT_TRIG_R  11 //1011
    #define BUT_TRIG_C  7  //0111
    #define BUT_TRIG_L  13 //1101
    #define BUT_UP      0  //0000
    #define BUT_DOWN    8  //1000
    #define BUT_LEFT    12 //1100
    #define BUT_RIGHT   4  //0100
    
    #define MAX_X1 190
    #define MIN_X1 110
    
    #define MAX_Y1 185 
    #define MIN_Y1 105
    
    #define MAX_Y2 184 
    #define MIN_Y2 104

    and this is the main code 




    #include "joyStickSettings.h"
    
    #define BUT_A1_PIN 4
    #define BUT_A2_PIN 5
    #define BUT_B1_PIN 6
    #define BUT_B2_PIN 7
    
    #define JOY1_X A8
    #define JOY1_Y A9
    #define JOY2_Y A10
    
    int joy1_x,joy1_y,joy2_y;
    
    // include the library header
    #include <openGLCD.h>
    
    
    int getAnalogPosition(byte analogChannel) {
      int analogValue = analogRead(analogChannel);
      return (102300) / analogValue - 100;
    }
    
    
    void setup()
    {
      Serial.begin(115200);
      Serial.println("System started");
      pinMode(BUT_A1_PIN, INPUT);
      pinMode(BUT_A2_PIN, INPUT);
      pinMode(BUT_B1_PIN, INPUT);
      pinMode(BUT_B2_PIN, INPUT);
    
      // Initialize the GLCD
      GLCD.Init();
      // Select the font for the default text area
      GLCD.SelectFont(Callibri10);
      GLCD.print("-JOYSTICK TEST-");
    
    
    }
    
    void loop()
    {
      //read buttons
      byte butState = 128;
      butState |= digitalRead(BUT_A1_PIN);
      butState |= digitalRead(BUT_A2_PIN) << 1;
      butState |= digitalRead(BUT_B1_PIN) << 2;
    ...
    Read more »

View all 2 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates