Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Newb needs some help

  1. #1
    Junior Member
    Join Date
    Jul 2018
    Posts
    6

    Newb needs some help

    As said in title I am new to using a teensy. To get to my point, I want to use my teensy lc as a gamepad and I have no idea where to start and how to do that. YES I did look at the examples given but it did not work the way I wanted to. I am trying to have a 14 button and 2 joystick type gamepad, when I used example code provided on raspberry pi 3 it was all wonky and buggy. did I do something wrong when soldering or do I have to edit the example code?

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,787
    The normal starting point is the one I think you are already using
    https://www.pjrc.com/teensy/td_joystick.html
    Which example code are you using, and can you describe or post a picture of your hardware wiring?
    Anther step to finding out where in the hardware/firmware/USB/driver/OS chain things are going wrong is to use the digital IO examples to verify your hardware is actually all wired up right without the joystick elements.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,767
    Would be amazing if there was an example that had those exact details in mind - in any case seeing a reference the example used would allow for detailed review.

    That is a great deal of soldering to do all at once. Better to tackle it in steps seeing and keeping it working ... a button or two ... then the next logical small step to minimize rework or hidden errors.

    "did not work the way I wanted to." - doesn't help a reader understand if it worked at all - or not at all so that could use more detail as well.

    The soldering could be checked for bridges and tested for expected continuity to the right pin. When the soldering is right the software ideally can make it work as expected.

  4. #4
    Junior Member
    Join Date
    Jul 2018
    Posts
    6
    Ok realizing it now I guess it's hard to understand sorry but the way I describe things is the way I understand not others again sorry. Ok what in trying to say is that I have all BUTTONS wired good as in they work fine, my 2 JOYSTICKS are the ones that are having trouble, they are both 3ds joysticks. I am using and edited version of the basic joystick example provided by arduino examples, by edited I mean I just added the other 12 buttons since the basic starts off with 2. The problem with my joysticks Left and down is not being detected, but up and right are being detected. And it's happening on both joysticks. And by being detected I mean in retropie Up on joystick is detected as 0+, right is 1+, going left does nothing and going down does nothing as well, and again it's happening on both joystick both with the same problem

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,767
    Are all inputs on both joysticks detectable as expected to the right inputs? Any chance you could go back to the base 2 button example and see the joysticks work?

  6. #6
    Junior Member
    Join Date
    Jul 2018
    Posts
    6
    The joysticks are detected but just not down or left, and yes I have tried the 2 button example and the results is the same, the buttons work but the down left of the joysticks do not work,

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,767
    Does that confirm they are properly wired and yet not working? A sample sketch running showing state changes on the inputs works as expected? was either joystick tested to work at any point?

  8. #8
    Junior Member
    Join Date
    Jul 2018
    Posts
    6
    Sorry but I'm confused by your question, so Ima answer it the way that I understand. I wired the joysticks and uploaded the code and test it by going to the joystick calibrator thing on windows and it detects that the joysticks are moving the direction that I go to. So I know that they are wired correctly or else they wouldn't show that it was moving. My only problem is when I go to retropie only up and right is detected by 0+ and 1+
    0 being x axis and 1 being y axis, but 0- and 1- do not show when I go either left or down. I am using fresh install of retropie so I'm pretty sure that retropie is the problem. Also my teensy is being detected as 2 game pads so I'm not sure if that also a factor of the problem

  9. #9
    Junior Member
    Join Date
    Jul 2018
    Posts
    6
    Here is my code if this helps figure out the problem as well


    Code:
    /* Basic USB Joystick Example
       Teensy becomes a USB joystick
    
       You must select Joystick from the "Tools > USB Type" menu
    
       Pushbuttons should be connected to digital pins 0 and 1.
       Wire each button between the digital pin and ground.
       Potentiometers should be connected to analog inputs 0 to 1.
    
       This example code is in the public domain.
    */
    
    void setup() {
      pinMode(0, INPUT_PULLUP); //A
      pinMode(1, INPUT_PULLUP); //B
      pinMode(2, INPUT_PULLUP); //X
      pinMode(3, INPUT_PULLUP); //Y
      
      pinMode(4, INPUT_PULLUP); //DUP
      pinMode(5, INPUT_PULLUP); //DDOWN
      pinMode(6, INPUT_PULLUP); //DLEFT
      pinMode(7, INPUT_PULLUP); //DRIGHT
      
      pinMode(8, INPUT_PULLUP); //START
      pinMode(9, INPUT_PULLUP); //SELECT
      
      pinMode(10, INPUT_PULLUP); //L1
      pinMode(11, INPUT_PULLUP); //L2
      pinMode(12, INPUT_PULLUP); //R1
      pinMode(13, INPUT_PULLUP); //R2
    
      pinMode(14,INPUT_PULLUP); //x axis 1
      pinMode(15,INPUT_PULLUP); //y axis 1
    
      pinMode(16,INPUT_PULLUP); // x axis 2
      pinMode(17,INPUT_PULLUP);// y axis 2
    }
    
    void loop() {
      // read analog inputs and set X-Y position
      Joystick.X(analogRead(0));
      Joystick.Y(analogRead(1));
      Joystick.sliderLeft(analogRead(2));
      Joystick.sliderRight(analogRead(3));
      
    
      // read the digital inputs and set the buttons
      Joystick.button(1, digitalRead(0));
      Joystick.button(2, digitalRead(1));
      Joystick.button(3, digitalRead(2));
      Joystick.button(4, digitalRead(3));
      Joystick.button(5, digitalRead(4));
      Joystick.button(6, digitalRead(5));
      Joystick.button(7, digitalRead(6));
      Joystick.button(8, digitalRead(7));
      Joystick.button(9, digitalRead(8));
      Joystick.button(10, digitalRead(9));
      Joystick.button(11, digitalRead(10));
      Joystick.button(12, digitalRead(11));
      Joystick.button(13, digitalRead(12));
      Joystick.button(14, digitalRead(13));
      
    
      // a brief delay, so this runs 20 times per second
      delay(5);
    }
    Last edited by defragster; 07-11-2018 at 07:56 AM. Reason: Added # CODE blocking

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,767
    There was a lot of confusion before - looking for specific details as provided post #8 - the fact that it works normally at all eliminates a whole series of questions ...

    The fact that it works with Windows test app shows wiring and hardware including Teensy and code working as expected.

    Indeed it seems the part that is failing is 'retropie'. The message formatting or the device information is not not as it expects it perhaps.

    Posting the code is essential when looking for more answers than questions as it make clear many things. ... per the forum rule at the top of each page.

    Perhaps it is getting too many updates and updates should only be sent when there is a change in status for each element - at least for the 14 buttons? The Teensy is very fast and those operations will complete and send in very rapid succession.

    That may apply to the X,Y analogs as well. Even without movement they will likely change +/- 1 or 2 or more between readings and could result in a bouncing or jittering cross hair depending on how they are handled/mapped to usable numbers.

    Also note that the "brief delay" is 10 times shorter than noted. There are 1,000 milliseconds in one second - so a delay of 5 ms each loop is allowing up to 200 times per second, not 20 as commented.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    Try running this program on your Teensy and then open the Arduino Serial Monitor to watch the numbers it prints.

    Code:
    void setup() {
    }
    
    void loop() {
      Serial.print("A0=");
      Serial.print(analogRead(A0));
      Serial.print(", A1=");
      Serial.print(analogRead(A1));
      Serial.print(", A2=");
      Serial.print(analogRead(A2));
      Serial.print(", A3=");
      Serial.print(analogRead(A3));
      Serial.println();
      delay(100);
    }
    Do all 4 of the numbers properly respond to movement of the joystick hardware?

  12. #12
    Junior Member
    Join Date
    Jul 2018
    Posts
    6
    Ok so I figured out the problem it's was the power being supplied to the joystick normally 5v is the normal amount for the 3ds joysticks according to the pinout, so I changed it to 3.3v on the teensy and now the joysticks can show the negative values. Now my only problem is the delay on the buttons, when I try to configure them buttons on retropie, I would press a button and then like 3 seconds later it would register, and then it would act like I'm holding down the button (I'm not) and skip configuration for other buttons

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •