Forum Rule: Always post complete source code & details to reproduce any issue!
Page 7 of 7 FirstFirst ... 5 6 7
Results 151 to 158 of 158

Thread: Many axis joystick

  1. #151
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Quote Originally Posted by obzai View Post
    Can anyone see any problems with trying to use a rotary encoder to act as a Mouse.scroll() wheel in a Teensy build of a hybrid mouse-keyboard-gamepad-mega-joystick with more than 8 axes?
    This should be possible. Certainly Teensy gives you the way to implement these HID interfaces and precisely control what actually gets sent to your PC.

    To specifically answer your question, here are some challenges you might face.

    If using Microsoft Windows, the default joystick driver might not recognize more than 8 axes, even though it's properly implemented on the Teensy side (assuming you've edited the code to enable the bigger HID joystick report - or otherwise edited the USB code).

    In designing your code on the Teensy side, you'll want to avoid delays, so you're always being responsive to all the input signals. Simple as this sounds, real-world signals often aren't as nice as you might like and require "debouncing" or other techniques. Many people have gone down a path of adding delays in their code, which tends to work for only 1 signal, but then becomes really difficult when the delays to clean up 1 signal cause everything to be unresponsive to all the others. Teensyduino has features like elapsedMillis to make this easier, so if you need to do this sort of work I recommend using those and avoid delay().

    HID provides fixed bandwidth. At best you can send 1000 events per second. That's usually plenty, but it can quickly become a limitation if you do things inefficiently. The joystick functions have a way to freeze, so you can change multiple settings and have it all go out the USB cable to your PC as a single packet.

    If you do approach the bandwidth limits, those functions to send will end up waiting. If using the Encoder library, you may see the result of several changes at once. Likewise for other inputs, if those functions have to wait, your code may be "blind" to changes. Teensy's USB stack does buffer several outgoing packets, which gives you some flexibility. But as a general rule, if you try to sustain close to or more than 1000 updates per second, you will run into HID bandwidth limits and ultimately your code will suffer waits in the transmit functions.

  2. #152
    Junior Member
    Join Date
    Aug 2018
    Fantastic, thanks for the detailed reply Paul.

    Sounds like I could reasonably expect to build something that will work using this approach. I'll see how I go.
    Thanks for your work on the Teensy boards Paul, they're my favourite "do anything" solution. I always keep a couple on hand.

  3. #153
    Junior Member
    Join Date
    Sep 2018
    I tried to code a 8 axis joystick. I took the many axis joystick disabling all sliders beyond 2. Only data from the 6 axis are transmitted, sliders remain at zero
    Click image for larger version. 

Name:	Joystick.JPG 
Views:	59 
Size:	49.9 KB 
ID:	14715

  4. #154
    Junior Member
    Join Date
    Jul 2019
    Hello Paul, i replaced the files and now i'm getting a serial error, like it was not recognized:
    "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=144 -DARDUINO=10807 -DF_CPU=96000000 -DUSB_EVERYTHING -DLAYOUT_US_ENGLISH "-IC:\\Users\\NICOLA~1\\AppData\\Local\\Temp\\arduin o_build_113933/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teen sy3" "C:\\Users\\NICOLA~1\\AppData\\Local\\Temp\\arduin o_build_113933\\sketch\\sbus2joystick.ino.cpp" -o "C:\\Users\\NICOLA~1\\AppData\\Local\\Temp\\arduin o_build_113933\\sketch\\sbus2joystick.ino.cpp.o"
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_serial.h:34:0,

    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:54,

    from C:\Users\NICOLA~1\AppData\Local\Temp\arduino_build _113933/pch/Arduino.h:6,

    from C:\Users\NICOLA~1\AppData\Local\Temp\arduino_build _113933\sketch\sbus2joystick.ino.cpp:1:

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_desc.h:297:48: error: 'NUM_ENDPOINTS' was not declared in this scope

    extern const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS];

    Any idea?

  5. #155
    I have a question.. I sort of asked this in another thread where I was pointed to here, so this will probably be a better place to ask this..

    I have read through the thread and think I understand a bit about what is going on here but then again maybe not because I have never messed with this stuff..

    Anyway, what I would like to do is Expand the USB HID Joystick interface to access at least 64 buttons, Maybe 128. Unlike most of the examples on here I am not really in need of extending the Axis Count, However I also need to retain serial functions for the device for other things I plan on doing.

    I would LIKE TO do this to the Teensy LC as that is the primary device I am using, though I have noticed that most of this work has been done on the 3's so I am not sure of the possibility. I have located the USB headers information based on an earlier post but don't see anything specifically for the LC in there so any info on where to do adjustments would be helpful if it is even possible to do..

    Because I am not familiar with HID headers pointers in where to research this or guidance on the changes would be greatly appreciated.

    Thank you

  6. #156
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    I am no expert on this end of it. I have done more on the side of usbhost_t36 to try to handle different USB devices... I don't think there is much difference here between T3.x and TLC for this, they both use the teensy3 directory under cores.

    But if I were doing it, I think some of the areas I would look to change include:

    usb_desc.c - need to change the number of buttons... For example if you look for the JOYSTICK_SIZE==12 portion, you will see:
            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)
    So would try changing those 0x20 (32) to the size you need. Note: That will change the JOYSTICK_SIZE. Each 8 bits will add 1 byte to the size...
    So you may want to either modify these tables and/or make another copy #elif JOYSTICK_SIZE == <YOUR SIZE>

    You will need to update usb_desc.h to have the new size for your joyststick data...

    You will probably need to update usb_joystick.h to handle the additional buttons, that is the code again has specific code for size ==12 and == 64 again not knowing enough of which way you wish to start from (like how many axis) not sure which one is easiest for you to start from.

    My guess is probably the 64 one as the ==12 assumes all of the buttons fit into one uint32_t value and all of the axis are aligned to the 32 bit starting memory locations... Actually both assume a certain alignment in memory for where the axis values are stored...

    Again there are probably other things I am missing, but that is where I would start

  7. #157
    Yea that is my concern as in some ways it seems so simple , but is it really just a matter of changing the size of those parameters.. Thank you though on the information about the LC using the T3 core code as that one makes it seem feasible and two points me in the direction of the files to mess with..

    I think I may be able to figure it out from there but if anyone else or you have any further information it is always appreciated.

  8. #158
    Oh Hmm.. It looks like Paul has included the code for the extreme Joystick IN the core data as I was just looking at the usb_desc.c in the teensy3/Core/avr and noted this:

    #elif JOYSTICK_SIZE == 64
    // extreme joystick (to use this, edit JOYSTICK_SIZE to 64 in usb_desc.h)
    // 128 buttons 16
    // 6 axes 12
    // 17 sliders 34
    // 4 pov 2

    This will be beyond of course what I generally would need but hey seems much easier now

Posting Permissions

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