Forum Rule: Always post complete source code & details to reproduce any issue!
Page 6 of 6 FirstFirst ... 4 5 6
Results 126 to 144 of 144

Thread: Many axis joystick

  1. #126
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    Quote Originally Posted by konfu View Post
    What about the 128 buttons from the original version?
    Did you actually try using this yet?

    All 128 button still exist. This JOYSTICK_SIZE define is the number of bytes for the entire HID report, not the number of any particular type of field within the report.

    The 128 buttons use 1 bit each, so they consume only the first 16 of these 64 bytes. The many axes account for most of the report size.

  2. #127
    Junior Member
    Join Date
    Mar 2017
    Posts
    1
    Hi Paul, i was searching a lot for the best setup for a 16bit flight controller, i was wondering does Extreme Joystick works with rotary encoders and rotary switches ??
    I want to buy the Teensy 3.1 for the project, but i found mmjoy too that uses teensy 2++, so im a bit confused what is the best.
    Since this thread is from a very long time, does extreme joystick have had any update ??
    and... if i would like to use a bigger resolution like 20bit, can it be done on teensy 3.1 ?

    thanks very much

  3. #128
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    Quote Originally Posted by kbral View Post
    i was wondering does Extreme Joystick works with rotary encoders and rotary switches ??
    Teensy is about DIY electronics. The USB Joystick function (either standard or extreme) is meant to allow you to create such things.

    You write relatively simple code in Arduino which reads whatever encoders or switches you like. When then change, you use the joystick functions to transmit joystick events. You could use pots instead of encoders. Or you could connect a ethernet module and allow network communication to send joystick events.

    If you haven't already installed the software, get Arduino & Teensyduino. Select Teensy in the Tools > Boards menu (the other menus update based on the board). Then look at some of the examples, in File > Examples > Teensy > USB_Joystick and File > Examples > Encoder. To accomplish a project like this, you'll be copying bits of code from these examples. You can download the software and look at this code before buying anything, and doing so can give you a much better idea of how this all works. It's not a finished, fixed-function product. It's a system that allows you to create things.

  4. #129
    Junior Member
    Join Date
    Mar 2017
    Posts
    2
    Hi Paul,

    I am using the USB Joystick Complete example (that comes with Teensyduino) for a custom joystick. The axes are X, Y, Z, Zrotate, sliderLeft, sliderRight. The joystick shows up like the attached pict under Windows 10. The second slider axis won't work in a game (Overload) and I suspect it is because they are both named slider. I have tried renaming sliderLeft and sliderRight to Xrotate and Yrotate in the .ino sketch, usb_joystick.h, and usb_api.h. I also changed joystick_report_desc in usb_desc.c and usb.c as follows:

    Changed:
    0x09, 0x36, // Usage (Slider)
    0x09, 0x36, // Usage (Slider)

    To:
    0x09, 0x33, // Usage (Rx)
    0x09, 0x34, // Usage (Ry)

    After uninstalling the joystick under Device Manager and reinstalling it, it still comes up the same way with two sliders. Am I missing something?

    Thanks in advance.

    Click image for larger version. 

Name:	Windows_control_panel.JPG 
Views:	38 
Size:	43.7 KB 
ID:	9988

  5. #130
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    It can be tough to get Windows to "forget" the prior info it stores about a USB device.

    Usually the best thing is to increment the BCD version number in the USB device descriptor. Windows will see it's a newer version and re-read everything.

  6. #131
    Junior Member
    Join Date
    Mar 2017
    Posts
    2
    I did try incrementing the bcdDevice number (usb_desc.c, line 90), as well as the vendor ID and product ID and then flashed the firmware to the Teensy. Nothing made it reinstall the device short of going to device manager and right clicking on the correct USB composite device and uninstalling. In that case, after unplugging and plugging it in again, windows installed it fresh (however sliders still show as in the pict). Are there any other places other than the files I mentioned that need to be changed for the sliders to change to Rx and Ry? Thanks for your help!
    Last edited by Natefp; 03-18-2017 at 05:48 AM. Reason: clarification

  7. #132
    Junior Member
    Join Date
    Mar 2017
    Posts
    4
    Quote Originally Posted by PaulStoffregen View Post
    Ok, I've updated this code and merged it into the official core library.

    https://github.com/PaulStoffregen/co...e4114bf6e767fa

    If you want to play with it now, you can get the updated files from github and put them into your copy of Arduino. Starting with 1.36-beta2 they will always be there by the installer.

    To actually use this (after you have the new files installed), edit usb_desc.h. Change JOYSTICK_SIZE from 12 to 64. Remember, there's 4 copies for the different USB Types which use joystick. Edit the one you need, or all of them if unsure. I've set everything else to automatically adapt.

    As always, on Windows your old USB device detection might be cached in the Windows Registry. You might need to increase the BCD version number or change the product ID or do other stuff to get Windows to re-detect the device.
    Hello Paul, thank you for your work on this project, I am kind of new using the teensy boards since I just got my first one a week ago(teensy ++ 2.0) for a project and was afraid i will not have enough axis for it. Looking this project was from 2014 I was losing hope that i will be able to use it now.

    This might be a dumb question but will this work with the teensy ++ 2.0? (I ask since the project was for the teensy 3.1 originally)

  8. #133
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    Quote Originally Posted by zombierevel View Post
    but will this work with the teensy ++ 2.0?
    No, sorry, it's written for the new USB stack in Teensy LC & 3.x.

    In theory, with enough work someone skilled with the USB code could rewrite it all for the older Teensy 2.x USB code. But in practice, that's very unlikely to ever happen...

  9. #134
    Junior Member
    Join Date
    Mar 2017
    Posts
    4
    Well that's unfortunate, but thank you for your honest reply. Since Teensy boards arent sold here its kind of difficult to get one, and was only able to get a ++ 2.0. The cheapest Teensy 3.x seems to be at least close to 50$ so I think i will need to stay with the ++2.0 for some time, if the project goes well maybe i will be able to get another teensy and try this. If you dont mind me asking for future reference, if I would like to modify the files, what will be the hardest part? Modifying the HID descriptor?

  10. #135
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    Where is "here"? None of these distributors are close?

    https://forum.pjrc.com/threads/23601...l-Distributors

    On porting, modifying the code is fairly easy. Getting it to actually work is the hard part! It'd be particularly difficult without a known-good board for comparison and a USB protocol analyzer so you can see what's actually communicated over the USB lines.

  11. #136
    Junior Member
    Join Date
    Mar 2017
    Posts
    4
    Quote Originally Posted by PaulStoffregen View Post
    Where is "here"? None of these distributors are close?

    https://forum.pjrc.com/threads/23601...l-Distributors

    On porting, modifying the code is fairly easy. Getting it to actually work is the hard part! It'd be particularly difficult without a known-good board for comparison and a USB protocol analyzer so you can see what's actually communicated over the USB lines.
    Thank you for the reply. Seems like its not an easy job for a noob like me, but fortunately i think i can get enough axis and buttons with the teensy ++ 2.0 for my project.
    I am from Peru (South America). Doesnt seems like my region is supported, so best case I need to import from USA. But i think one of my friends is going to travel to USA so maybe I will be able to get a Teensy 3.2 from him.

  12. #137
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,573
    If your friend is going to a city with a Microcenter (http://www.microcenter.com/), they often times have various Teensys for sale in a retail setting.

  13. #138
    Junior Member
    Join Date
    Mar 2017
    Posts
    4
    Quote Originally Posted by MichaelMeissner View Post
    If your friend is going to a city with a Microcenter (http://www.microcenter.com/), they often times have various Teensys for sale in a retail setting.
    Great man, thank you for the information. Will tell him.

  14. #139
    Junior Member
    Join Date
    Nov 2017
    Posts
    3
    I have a similar question that I posted in a different thread: < https://forum.pjrc.com/threads/24433...l=1#post160215 >. Instead of more axis and buttons, I am trying to understand how to make the device show up with less axis and fewer buttons. Does anyone have recommendations on how to do that?

  15. #140
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,233
    I have not worked much with T2s, mostly know trying to add T3.6 host support... Including plugging in another Teensy... Including Joystick support.

    But For the 3.x I would look in the file: D:\arduino-1.8.5\hardware\teensy\avr\cores\teensy3\usb_desc.c
    Most likely your path will be different...
    For this section:
    Code:
    #ifdef JOYSTICK_INTERFACE
    #if JOYSTICK_SIZE == 12
    static uint8_t joystick_report_desc[] = {
            0x05, 0x01,                     // Usage Page (Generic Desktop)
            0x09, 0x04,                     // Usage (Joystick)
            0xA1, 0x01,                     // Collection (Application)
            0x15, 0x00,                     //   Logical Minimum (0)
            0x25, 0x01,                     //   Logical Maximum (1)
            0x75, 0x01,                     //   Report Size (1)
            0x95, 0x20,                     //   Report Count (32)
            0x05, 0x09,                     //   Usage Page (Button)
            0x19, 0x01,                     //   Usage Minimum (Button #1)
            0x29, 0x20,                     //   Usage Maximum (Button #32)
            0x81, 0x02,                     //   Input (variable,absolute)
            0x15, 0x00,                     //   Logical Minimum (0)
            0x25, 0x07,                     //   Logical Maximum (7)
            0x35, 0x00,                     //   Physical Minimum (0)
            0x46, 0x3B, 0x01,               //   Physical Maximum (315)
            0x75, 0x04,                     //   Report Size (4)
            0x95, 0x01,                     //   Report Count (1)
            0x65, 0x14,                     //   Unit (20)
            0x05, 0x01,                     //   Usage Page (Generic Desktop)
            0x09, 0x39,                     //   Usage (Hat switch)
            0x81, 0x42,                     //   Input (variable,absolute,null_state)
            0x05, 0x01,                     //   Usage Page (Generic Desktop)
            0x09, 0x01,                     //   Usage (Pointer)
            0xA1, 0x00,                     //   Collection ()
            0x15, 0x00,                     //     Logical Minimum (0)
            0x26, 0xFF, 0x03,               //     Logical Maximum (1023)
            0x75, 0x0A,                     //     Report Size (10)
            0x95, 0x04,                     //     Report Count (4)
            0x09, 0x30,                     //     Usage (X)
            0x09, 0x31,                     //     Usage (Y)
            0x09, 0x32,                     //     Usage (Z)
            0x09, 0x35,                     //     Usage (Rz)
            0x81, 0x02,                     //     Input (variable,absolute)
            0xC0,                           //   End Collection
            0x15, 0x00,                     //   Logical Minimum (0)
            0x26, 0xFF, 0x03,               //   Logical Maximum (1023)
            0x75, 0x0A,                     //   Report Size (10)
            0x95, 0x02,                     //   Report Count (2)
            0x09, 0x36,                     //   Usage (Slider)
            0x09, 0x36,                     //   Usage (Slider)
            0x81, 0x02,                     //   Input (variable,absolute)
            0xC0                            // End Collection
    };
    I believe the line I put in RED above controls the number of buttons: in particular the 0x20 (which is 32)

    The Number of Axis is a little more complicated, Some of the lines associated with it are in Green
    That is for example you have the section, that defines X, Y, Z, Rz which there are 4 of them. (report count).

    Likewise with sliders. Note: The HAT fields earlier in the report also probably show up as axis.

    Again I have not looked at where it is defined for Teensy 2.0, but I would suspect it would be something similar.
    On my system I believe it is in the file: D:\arduino-1.8.5\hardware\teensy\avr\cores\usb_hid\usb.c
    Last edited by KurtE; 11-21-2017 at 05:20 AM.

  16. #141
    Junior Member
    Join Date
    Nov 2017
    Posts
    3
    Thanks,

    The path on my machine is: '/usr/share/arduino/hardware/teensy/avr/cores/teensy3/'.
    That file exists in the teensy3 directory, however there is no teensy2 directory.
    Perhaps it defaults to the teensy directory, but the file is not in that directory.
    Is it possible that the file in teeny3 is being used?
    I'll make changes to the file, then flash a teensy 2 and see if it makes a difference.

    Edit:

    Okay, so I tried that, but I think I messed something up.
    I think what I really want to do now, is peal back this obtuse layer of arduino abstraction and get a real sense of what is actually going on.
    What is the bare minimum that I would need to compile and flash the teensy2 from a terminal?
    What compiler do I need, what library files do I need?
    What utility do I need to flash the compiled hex?
    Again the goal is still to make a joystick, but I just want to understand what is going on and what files are absolutely necessary.
    Last edited by Technicus; 11-21-2017 at 05:45 AM.

  17. #142
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,233
    On my linux box: My arduino Installation is similar: kurt@kurt-UP-CHT01:~/Desktop/arduino-1.8.5/hardware/teensy/avr/cores$
    Under that directory is teensy3 for the stuff I mentioned.

    For a Teensy2, the sources are in the directory: teensy
    As I mentioned in the first post, some of the USB code (usb.c) includes code from other directories for the different USB configurations. The code I mentioned associated with the joystick is in the directory: kurt@kurt-UP-CHT01:~/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/usb_hid$
    If you look in usb.c you will find the joystick HID descriptor.

    However just changing the descriptors will not be sufficient. This tells the other side how the data is packed on the messages that follow from the logical joystick.
    You then also need to update the usb_joystick_class which is in the usb_api.h and usb_api.cpp files in that directory to make the data match the format that you describe in the descriptor.

    So again currently in the usb.c you have:
    Code:
    static const uint8_t PROGMEM joystick_hid_report_desc[] = {
            0x05, 0x01,                     // Usage Page (Generic Desktop)
            0x09, 0x04,                     // Usage (Joystick)
            0xA1, 0x01,                     // Collection (Application)
    	0x15, 0x00,			// Logical Minimum (0)
    	0x25, 0x01,			// Logical Maximum (1)
    	0x75, 0x01,			// Report Size (1)
    	0x95, 0x20,			// Report Count (32)
    	0x05, 0x09,			// Usage Page (Button)
    	0x19, 0x01,			// Usage Minimum (Button #1)
    	0x29, 0x20,			// Usage Maximum (Button #32)
    	0x81, 0x02,			// Input (variable,absolute)
    	0x15, 0x00,			// Logical Minimum (0)
    	0x25, 0x07,			// Logical Maximum (7)
    	0x35, 0x00,			// Physical Minimum (0)
    	0x46, 0x3B, 0x01,		// Physical Maximum (315)
    	0x75, 0x04,			// Report Size (4)
    	0x95, 0x01,			// Report Count (1)
    	0x65, 0x14,			// Unit (20)
            0x05, 0x01,                     // Usage Page (Generic Desktop)
    	0x09, 0x39,			// Usage (Hat switch)
    	0x81, 0x42,			// Input (variable,absolute,null_state)
            0x05, 0x01,                     // Usage Page (Generic Desktop)
    	0x09, 0x01,			// Usage (Pointer)
            0xA1, 0x00,                     // Collection ()
    	0x15, 0x00,			//   Logical Minimum (0)
    	0x26, 0xFF, 0x03,		//   Logical Maximum (1023)
    	0x75, 0x0A,			//   Report Size (10)
    	0x95, 0x04,			//   Report Count (4)
    	0x09, 0x30,			//   Usage (X)
    	0x09, 0x31,			//   Usage (Y)
    	0x09, 0x32,			//   Usage (Z)
    	0x09, 0x35,			//   Usage (Rz)
    	0x81, 0x02,			//   Input (variable,absolute)
            0xC0,                           // End Collection
    	0x15, 0x00,			// Logical Minimum (0)
    	0x26, 0xFF, 0x03,		// Logical Maximum (1023)
    	0x75, 0x0A,			// Report Size (10)
    	0x95, 0x02,			// Report Count (2)
    	0x09, 0x36,			// Usage (Slider)
    	0x09, 0x36,			// Usage (Slider)
    	0x81, 0x02,			// Input (variable,absolute)
            0xC0                            // End Collection
    };
    This translates into:
    32 bits - Buttons
    4 bits - Hat switch
    10 bits for X (axis)
    10 bits for y (axis)
    10 bits for Z (axis)
    10 bits for RZ (axis)
    10 bits for Slider
    10 bits for Slider
    = 96 bits of data or 12 bytes.

    So if you look at the usb_joystick_class you will see how it is packing all of the data into the appropriate areas of the report on a bit boundary. So if you change the report descriptor, you will need to pack the data in your new format...

    Now as to the minimal stuff needed to build and program. There are several threads on forum on how to program using bare metal. You might do a search. I typically just install Arduino and Teensyduino and use it that way

  18. #143
    Junior Member TG626's Avatar
    Join Date
    Dec 2017
    Posts
    3
    Quote Originally Posted by KurtE View Post
    ...snip...

    However just changing the descriptors will not be sufficient. This tells the other side how the data is packed on the messages that follow from the logical joystick.
    You then also need to update the usb_joystick_class which is in the usb_api.h and usb_api.cpp files in that directory to make the data match the format that you describe in the descriptor.
    ...snip...
    I'm using a Teensy 2.0 and would dearly love 37 buttons. Could I add a byte to the buttons by:

    • Editing the descriptor
    • Editing usb_api.h by changing
      Code:
      extern uint8_t joystick_report_data[12];
      to
      Code:
      extern uint8_t joystick_report_data[13];
      and adding conditional code in the usb_joystick_class
      Code:
      else if (button < 40) joystick_report_data[4] |= mask;
    • Editing usb_api.cpp
      Code:
      UEDATX = joystick_report_data[12];
      after line 662



    Is that really all there is to it?

  19. #144
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,275
    That's most of it. But you'll also need to alter all the writes to joystick_report_data[4] to joystick_report_data[11] to one index farther in the array, since you'll now be using joystick_report_data[4] for something else. Of course, if you add fewer than 8 buttons, you'll need to add a const field to the descriptor to fill up the rest of joystick_report_data[4] with bits the HID parser will ignore. Adding exactly 8 more is easiest.

    If using Windows, don't forget to increment the BCD version. Windows loves to cache USB info in the Windows Registry, even when it's silly to do so because it has to read all that stuff anyway as it detects the device. If you don't increment the BCD version or change the VID or PID, Windows may happily ignore your changes and use the stale info from its registry.

Posting Permissions

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