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

Thread: Which Teensy to use for a 14 buttons + 2 joysticks USB game controller ?

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    5

    Which Teensy to use for a 14 buttons + 2 joysticks USB game controller ?

    Hello,

    I would like to build a USB Game Controller using a Teensy, to use it with a Raspberry Pi on a handheld retro console.

    The controller will have 14 buttons, using momentary push buttons :
    • A, B, X, Y
    • START, SELECT
    • LT, RT, LB, RB
    • DPAD UP, DOWN, LEFT, RIGHT


    And 2 joysticks, from what I understood each has 2 analog pins (X and Y axis).

    That makes a total of 14 push buttons, and 4 analog. From what I've read, the push buttons can be used with either digital or analog inputs, but the joysticks obviously need analog inputs.

    I would like to fit everything on a single Teensy to make a "standalone" controller (self-powered via USB, so I'll be using the 3.3v pins of the board), working on Windows for testing and eventually the Raspberry Pi (and maybe other devices too). The code will be a simple loop where I check for each pin and send them as joystick buttons / axis via USB.

    Now here is my question : which Teensy should I buy ? Will a Teensy 3.2 be enough for that ? Will it have enough pins, and of the right type ? I also want to add VOL-, VOL+ and MENU buttons but I need to emulate a keyboard for them, so I'll wire them directly to the Raspberry Pi (unless the Teensy has enough pins AND the capability to emulate both a USB keyboard and joystick).

    Thanks for the input

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,359

    Cool

    You could do it with any of the ARM based Teensys (LC, 3.2, 3.5, or 3.6). On the Teensy LC/3.2, you have the following pins that can be used on the outer rows of pins that are easily used in a breadboard or soldered to a pcb:
    • 13 digital input/output pins;
    • 1 pin that can only do digital output (13), and is hooked up to the on board LED;
    • 10 pins that can be either digital or analog;

    In addition, there are 2 analog input pins and 1 analog input/output pin that can be used for sound output with easily accessible soldering holes inside of the Teensy.

    On the Teensy 3.5/3.6, you have 7 more digital only pins along the main breadboard row and 9 more digital/analog pins.

    In addition, on the Teensy 3.2/3.5/3.6, there are more pins available if you solder wires to the solder pads underneath the Teensy.

    If I may make a suggestion on which pins to use, you might want to not use pins 18/19 (A4/A5). These pins are the I2C pins. With two 2.2k resistors soldered between each of the pins and 3.3v, you can add various simple devices to the Teensy, such as extenders for reading additional digital pins, simple displays, etc. If you want to add more digital inputs or outputs, the MCP23017 (https://www.adafruit.com/product/732) can be added to the i2c bus to support 16 digital input/output pins (and you can hook up to 8 MCP23017's on a single i2c bus). You might not need this now, but it is useful to plan for growth.
    Last edited by MichaelMeissner; 10-09-2017 at 01:12 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,769
    Teensy LC should be able to do all this. Yes, it can even do the USB keyboard emulation for those media control buttons, while doing the USB joystick stuff.

    After you install Arduino+Teensyduino, in Arduino select Teensy LC from Tools > Boards. Then use File > Examples > Teensy > USB_Joystick to get started. There's also an example for the media buttons in File > Examples > Teensy > USB_Keyboard. Those should give you most of the code you need.

  4. #4
    Junior Member
    Join Date
    Oct 2017
    Posts
    5
    Thanks for all your answers !

    I might go with the Teensy LC because, well, it's low cost compared to the 3.2. I'll use the 13 digital pins for the 13 first buttons, 4 digital/analog pin in D mode for the remaining buttons and 4 digital/analog pins in A mode for the joysticks.

    I just installed the Arduino IDE and Teensyduino, and I saw the Keyboard + Mouse + Joystick USB type... I think that'll do !

  5. #5
    Junior Member
    Join Date
    Jan 2019
    Posts
    2
    Quote Originally Posted by natinusala View Post
    Thanks for all your answers !

    I might go with the Teensy LC because, well, it's low cost compared to the 3.2. I'll use the 13 digital pins for the 13 first buttons, 4 digital/analog pin in D mode for the remaining buttons and 4 digital/analog pins in A mode for the joysticks.

    I just installed the Arduino IDE and Teensyduino, and I saw the Keyboard + Mouse + Joystick USB type... I think that'll do !
    Were you able to get this working? I am working on a very similar project. I would be interested in your code if you are willing to share it.

    Using a Teensy 3.2 I am able to get 1 Joystick and some buttons work very easily. I am stuck on adding the second Joystick.

    I was looking at the properties of an Xbox controller and it appears the right joystick controlls X and Y rotation. I am not sure how to write code for that though (arduino noob).

    Any help would be appreciated!

  6. #6
    Junior Member
    Join Date
    Oct 2017
    Posts
    5
    Sure, here is my code : https://github.com/natinusala/RetroM...tromachine.ino

    edit: and here is the button & pinout mapping : https://puu.sh/Cz96h/ec62d7557a.png

    DX is digital pin X, ADX is analog or digital pin X, (D) being in digital mode and (A) in analog mode

  7. #7
    Junior Member
    Join Date
    Jan 2019
    Posts
    2
    <strike>Thanks for sharing!

    In your pinout mapping I see that the right joystick is pinned to A6 and A7.

    I don't see any mention of those in your code though, and after uploading to my teensy it doesnt appear that manipulating the right joystick does anything. </strike>

    Nevermind! I figured it out!

    I added..

    Code:
    void joystick_z(unsigned int value)
    {
      Joystick.Z(value);
    }
    
    void joystick_zr(unsigned int value)
    {
      Joystick.Zrotate(value);
    }
    And

    Code:
    {A6, A7, joystick_z, joystick_zr} //Right analog
    It works! Thanks again for sharing.

  8. #8
    Junior Member
    Join Date
    Nov 2019
    Posts
    1

    Joystick only registering two directions

    Quote Originally Posted by natinusala View Post
    Sure, here is my code : https://github.com/natinusala/RetroM...tromachine.ino

    edit: and here is the button & pinout mapping : https://puu.sh/Cz96h/ec62d7557a.png

    DX is digital pin X, ADX is analog or digital pin X, (D) being in digital mode and (A) in analog mode
    Hello I tried using your code but my joystick is only registering two directions, ie. Left and down the way I have it oriented in the case. When trying to configured in emulation station it reads 0+ and 1+ for those two directions. Any thoughts? Is it a faulty psp1000 joystick?

Posting Permissions

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